diff options
author | Dan Gudmundsson <[email protected]> | 2010-10-06 14:05:36 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2010-11-15 10:13:05 +0100 |
commit | a9f305c51ebccefc3ce6725b4f90700a7d250287 (patch) | |
tree | 64f522982e763eb5eda411196413a15704db36c4 /lib/wx/api_gen | |
parent | b48be79573171e530d97cdf078488eb66fc23f30 (diff) | |
download | otp-a9f305c51ebccefc3ce6725b4f90700a7d250287.tar.gz otp-a9f305c51ebccefc3ce6725b4f90700a7d250287.tar.bz2 otp-a9f305c51ebccefc3ce6725b4f90700a7d250287.zip |
Split opengl functionality into separate dynamic library
The idea is to build a separate opengl library which can be reused
by other erlang applications.
Diffstat (limited to 'lib/wx/api_gen')
-rw-r--r-- | lib/wx/api_gen/gl_gen_c.erl | 28 | ||||
-rw-r--r-- | lib/wx/api_gen/gl_gen_erl.erl | 61 | ||||
-rw-r--r-- | lib/wx/api_gen/wx_gen_cpp.erl | 12 | ||||
-rw-r--r-- | lib/wx/api_gen/wx_gen_erl.erl | 17 | ||||
-rw-r--r-- | lib/wx/api_gen/wxapi.conf | 49 |
5 files changed, 102 insertions, 65 deletions
diff --git a/lib/wx/api_gen/gl_gen_c.erl b/lib/wx/api_gen/gl_gen_c.erl index 3293050ab9..99dd2e58ea 100644 --- a/lib/wx/api_gen/gl_gen_c.erl +++ b/lib/wx/api_gen/gl_gen_c.erl @@ -47,30 +47,16 @@ gen(GLFuncs, GLUFuncs) -> w("/***** This file is generated do not edit ****/~n~n", []), w("#include <stdio.h>~n", []), w("#include <string.h>~n", []), - w("#include \"../wxe_impl.h\"~n", []), - w("#include \"../wxe_gl.h\"~n", []), + w("#include \"../egl_impl.h\"~n", []), w("#include \"gl_fdefs.h\"~n", []), w("~nint gl_error_op;~n", []), - w("void gl_dispatch(int op, char *bp,ErlDrvTermData caller,WXEBinRef *bins[]){~n", + w("void egl_dispatch(int op, char *bp, ErlDrvPort port, ErlDrvTermData caller, char *bins[]){~n", []), w(" gl_error_op = op;~n", []), - w(" if(caller != gl_active) {~n", []), - w(" wxGLCanvas * current = glc[caller];~n", []), - w(" if(current) { gl_active = caller; current->SetCurrent();}~n", []), - w(" else {~n " - " ErlDrvTermData rt[] = // Error msg~n" - " {ERL_DRV_ATOM, driver_mk_atom((char *) \"_wxe_error_\"),~n" - " ERL_DRV_INT, op,~n" - " ERL_DRV_ATOM, driver_mk_atom((char *) \"no_gl_context\"),~n" - " ERL_DRV_TUPLE,3};~n" - " driver_send_term(WXE_DRV_PORT,caller,rt,8);~n" - " return ;~n }~n };~n~n", []), w(" switch(op)~n{~n",[]), - w(" case 5000:~n wxe_tess_impl(bp, caller);~n break;~n", []), - w(" case WXE_BIN_INCR:~n driver_binary_inc_refc(bins[0]->bin);~n break;~n",[]), - w(" case WXE_BIN_DECR:~n driver_binary_dec_refc(bins[0]->bin);~n break;~n",[]), + w(" case 5000:~n erl_tess_impl(bp, port, caller);~n break;~n", []), [funcs(F) || F <- GLUFuncs], [funcs(F) || F <- GLFuncs], @@ -171,10 +157,10 @@ decode_arg(P=#arg{where=c},A) -> {P,A}; decode_arg(P=#arg{in=false},A) -> {P,A}; decode_arg(P=#arg{name=Name,type=#type{name=Type,base=binary}},A0) -> - w(" ~s *~s = (~s *) bins[~p]->base;~n", [Type,Name,Type,next_id(bin_count)]), + w(" ~s *~s = (~s *) bins[~p];~n", [Type,Name,Type,next_id(bin_count)]), {P, A0}; decode_arg(P=#arg{name=Name,type=#type{name=Type,base=memory}},A0) -> - w(" ~s *~s = (~s *) bins[~p]->base;~n", [Type,Name,Type,next_id(bin_count)]), + w(" ~s *~s = (~s *) bins[~p];~n", [Type,Name,Type,next_id(bin_count)]), {P, A0}; decode_arg(P=#arg{name=Name,type=#type{name=T,base=string,single=list}},A0) -> A = align(4,A0), @@ -322,7 +308,7 @@ build_return_vals(Type,As) -> w(" rt[AP++]=ERL_DRV_ATOM;" " rt[AP++]=driver_mk_atom((char *) \"ok\");~n",[]), w(" rt[AP++] = ERL_DRV_TUPLE; rt[AP++] = 2;~n",[]), - w(" driver_send_term(WXE_DRV_PORT,caller,rt,AP);~n",[]), + w(" driver_send_term(port,caller,rt,AP);~n",[]), ok end; {Val,Vars,Cnt} -> @@ -348,7 +334,7 @@ build_return_vals(Type,As) -> w(" rt[AP++] = ERL_DRV_TUPLE; rt[AP++] = 2;~n",[]), w(" if (AP != ~s ) fprintf(stderr, \"%d: ERROR AP mismatch %d %d\\r\\n\",__LINE__,AP,~s);~n", [CSize,CSize]), - w(" driver_send_term(WXE_DRV_PORT,caller,rt,AP);~n",[]), + w(" driver_send_term(port,caller,rt,AP);~n",[]), case Vars of none -> ignore; _ -> diff --git a/lib/wx/api_gen/gl_gen_erl.erl b/lib/wx/api_gen/gl_gen_erl.erl index ce35484561..36a6ea2373 100644 --- a/lib/wx/api_gen/gl_gen_erl.erl +++ b/lib/wx/api_gen/gl_gen_erl.erl @@ -49,7 +49,7 @@ glu_defines(Defs) -> w("~n%% GLU DEFINITIONS~n~n", []), w("%% This file is generated DO NOT EDIT~n~n", []), [gen_define(Def) || Def=#def{} <- Defs], - close(), + close(), ok. gen_define(#def{name=N, val=Val, type=int}) -> @@ -90,22 +90,51 @@ gl_api(Fs) -> w("%% See <a href=\"http://www.opengl.org/sdk/docs/man/\">www.opengl.org</a>~n",[]), w("%%~n", []), w("%% Booleans are represented by integers 0 and 1.~n~n", []), - w("%% @type wx_mem(). see wx.erl on memory allocation functions~n", []), + w("%% @type mem(). memory block~n", []), w("%% @type enum(). An integer defined in gl.hrl~n", []), w("%% @type offset(). An integer which is an offset in an array~n", []), w("%% @type clamp(). A float clamped between 0.0 - 1.0~n", []), w("-module(gl).~n~n",[]), w("-compile(inline).~n", []), - %% w("-compile(export_all).~n~n", []), - %% w("-compile(binary_comprehension).~n~n", []), - w("-include(\"wxe.hrl\").~n", []), +%% w("-include(\"wxe.hrl\").~n", []), [w("-define(~s,~s).~n", [GL,Erl]) || {GL,Erl} <- types()], Exp = fun(F) -> gen_export(F) end, ExportList = lists:map(Exp,Fs), w("~n-export([~s]).~n~n", [args(fun(EF) -> EF end, ",", ExportList, 60)]), - + w("-export([call/2, cast/2, send_bin/1]).~n",[]), + w("%% @hidden~n", []), + w("call(Op, Args) ->~n", []), + w(" Port = get(opengl_port), ~n", []), + w(" _ = erlang:port_control(Port,Op,Args),~n", []), + w(" rec().~n", []), + w(" ~n", []), + w("%% @hidden~n", []), + w("cast(Op, Args) ->~n", []), + w(" Port = get(opengl_port), ~n", []), + w(" _ = erlang:port_control(Port,Op,Args),~n", []), + w(" ok.~n", []), + w(" ~n", []), + w("%% @hidden~n", []), + w("rec() ->~n", []), + w(" receive ~n", []), + w(" {'_egl_result_', Res} -> Res;~n", []), + w(" {'_egl_error_', Res} -> error({error,Res})~n", []), + w(" end.~n", []), + w("~n", []), + w("%% @hidden~n", []), + w("send_bin(Bin) when is_binary(Bin) ->~n", []), + w(" Port = get(opengl_port), ~n", []), + w(" erlang:port_command(Port,Bin);~n", []), + w("send_bin(Tuple) when is_tuple(Tuple) ->~n", []), + w(" Port = get(opengl_port), ~n", []), + w(" case element(2, Tuple) of~n", []), + w(" Bin when is_binary(Bin) ->~n", []), + w(" erlang:port_command(Port,Bin)~n", []), + w(" end.~n", []), + w("~n", []), + w("~n%% API~n~n", []), [gen_funcs(F) || F <- Fs], close(), @@ -120,20 +149,20 @@ glu_api(Fs) -> w("%% See <a href=\"http://www.opengl.org/sdk/docs/man/\">www.opengl.org</a>~n",[]), w("%%~n", []), w("%% Booleans are represented by integers 0 and 1.~n~n", []), - w("%% @type wx_mem(). see wx.erl on memory allocation functions~n", []), + w("%% @type mem(). memory block~n", []), w("%% @type enum(). An integer defined in gl.hrl~n", []), w("%% @type offset(). An integer which is an offset in an array~n", []), w("%% @type clamp(). A float clamped between 0.0 - 1.0~n~n", []), w("-module(glu).~n",[]), w("-compile(inline).~n", []), - w("-include(\"wxe.hrl\").~n", []), + %%w("-include(\"wxe.hrl\").~n", []), [w("-define(~s,~s).~n", [GL,Erl]) || {GL,Erl} <- types()], Exp = fun(F) -> gen_export(F) end, ExportList = ["tesselate/2" | lists:map(Exp,Fs)], w("~n-export([~s]).~n~n", [args(fun(EF) -> EF end, ",", ExportList, 60)]), - + w("-import(gl, [call/2,cast/2,send_bin/1]).", []), w("~n%% API~n~n", []), w("%% @spec (Vec3, [Vec3]) -> {Triangles, VertexPos}~n",[]), @@ -148,13 +177,13 @@ glu_api(Fs) -> "%% may contain newly created vertices in the end.~n", []), w("tesselate({Nx,Ny,Nz}, Vs) ->~n",[]), - w(" wxe_util:call(5000, <<(length(Vs)):32/native,0:32,~n" + w(" call(5000, <<(length(Vs)):32/native,0:32,~n" " Nx:?GLdouble,Ny:?GLdouble,Nz:?GLdouble,~n" " (<< <<Vx:?GLdouble,Vy:?GLdouble,Vz:?GLdouble >>~n" " || {Vx,Vy,Vz} <- Vs>>)/binary >>).~n~n", []), [gen_funcs(F) || F <- Fs], - close(), + close(), ok. gen_funcs([F]) when is_list(F) -> @@ -229,9 +258,9 @@ gen_func(_F=#func{name=Name,type=T,params=As,id=MId}) -> {StrArgs,_} = marshal_args(PreAs), case have_return_vals(T,As) of true -> - w(" wxe_util:call(~p, <<~s>>)", [MId, StrArgs]); + w(" call(~p, <<~s>>)", [MId, StrArgs]); false -> - w(" wxe_util:cast(~p, <<~s>>)", [MId, StrArgs]) + w(" cast(~p, <<~s>>)", [MId, StrArgs]) end. func_arg(#arg{in=In,where=W,name=Name,type=Type}) @@ -302,7 +331,7 @@ doc_arg_type3(#type{base=guard_int}) -> "offset()|binary()"; doc_arg_type3(#type{base=string}) -> "string()"; doc_arg_type3(#type{base=bool}) -> "0|1"; doc_arg_type3(#type{base=binary}) -> "binary()"; -doc_arg_type3(#type{base=memory}) -> "wx:wx_mem()". +doc_arg_type3(#type{base=memory}) -> "mem()". guard_test(As) -> Str = args(fun(#arg{name=N,type=#type{base=guard_int}}) -> @@ -316,10 +345,10 @@ guard_test(As) -> end. pre_marshal([#arg{name=N,in=true,type=#type{base=binary}}|R]) -> - w(" wxe_util:send_bin(~s),~n", [erl_arg_name(N)]), + w(" send_bin(~s),~n", [erl_arg_name(N)]), pre_marshal(R); pre_marshal([#arg{name=N,type=#type{base=memory}}|R]) -> - w(" wxe_util:send_bin(~s#wx_mem.bin),~n", [erl_arg_name(N)]), + w(" send_bin(~s),~n", [erl_arg_name(N)]), pre_marshal(R); pre_marshal([A=#arg{name=N,type=#type{base=string,single=list}}|R]) -> %% With null terminations diff --git a/lib/wx/api_gen/wx_gen_cpp.erl b/lib/wx/api_gen/wx_gen_cpp.erl index 846cec46c4..4bcdbe6a68 100644 --- a/lib/wx/api_gen/wx_gen_cpp.erl +++ b/lib/wx/api_gen/wx_gen_cpp.erl @@ -152,6 +152,7 @@ gen_funcs(Defs) -> w("#include \"../wxe_impl.h\"~n"), w("#include \"../wxe_events.h\"~n"), w("#include \"../wxe_return.h\"~n"), + w("#include \"../wxe_gl.h\"~n"), w("#include \"wxe_macros.h\"~n"), w("#include \"wxe_derived_dest.h\"~n~n"), @@ -176,6 +177,9 @@ gen_funcs(Defs) -> " rt.addAtom(\"ok\");~n" " break;~n" " }~n"), + w(" case WXE_BIN_INCR:~n driver_binary_inc_refc(Ecmd.bin[0]->bin);~n break;~n",[]), + w(" case WXE_BIN_DECR:~n driver_binary_dec_refc(Ecmd.bin[0]->bin);~n break;~n",[]), + w(" case WXE_INIT_OPENGL:~n wxe_initOpenGL(rt, bp);~n break;~n",[]), Res = [gen_class(Class) || Class <- Defs], @@ -266,13 +270,13 @@ gen_method(CName, M=#method{name=N,params=Ps0,type=T,method_type=MT,id=MethodId Def =/= none, In =/= false, Where =/= c], decode_options(Opts, Align), case M#method.pre_hook of - undefined -> skip; - Pre -> w(" ~s;~n", [Pre]) + {c,Pre} -> w(" ~s;~n", [Pre]); + _ -> skip end, Ps3 = call_wx(N,{MT,CName},T,Ps2), case M#method.post_hook of - undefined -> skip; - Post -> w(" ~s;~n", [Post]) + {c, Post} -> w(" ~s;~n", [Post]); + _ -> skip end, free_args(), build_return_vals(T,Ps3), diff --git a/lib/wx/api_gen/wx_gen_erl.erl b/lib/wx/api_gen/wx_gen_erl.erl index 7962dd9fbf..8648174b5b 100644 --- a/lib/wx/api_gen/wx_gen_erl.erl +++ b/lib/wx/api_gen/wx_gen_erl.erl @@ -270,6 +270,16 @@ gen_method2(M=#method{name=N,alias=A,params=Ps,type=T,method_type=MT,id=MethodId MId = arg_type_tests(Args, "?" ++ get_unique_name(MethodId)), {MArgs,Align} = marshal_args(Args), MOpts = marshal_opts(Optional, Align, Args), + case M#method.pre_hook of + {erl,Pre} -> w(" ~s~n", [Pre]); + _ -> skip + end, + + case M#method.post_hook of + {erl,_} -> w(" _Result = ~n", []); + _ -> skip + end, + case have_return_vals(T, Ps) of _ when MT =:= constructor -> w(" wxe_util:construct(~s,~n <<~s~s>>)", [MId, MArgs,MOpts]); @@ -278,6 +288,13 @@ gen_method2(M=#method{name=N,alias=A,params=Ps,type=T,method_type=MT,id=MethodId false -> w(" wxe_util:cast(~s,~n <<~s~s>>)", [MId, MArgs,MOpts]) end, + case M#method.post_hook of + {erl,Post} -> + w(" ~s~n", [Post]), + w(" _Result~n", []); + _ -> skip + end, + erase(current_func), M. diff --git a/lib/wx/api_gen/wxapi.conf b/lib/wx/api_gen/wxapi.conf index 6bafda5b9d..14f5f7e267 100644 --- a/lib/wx/api_gen/wxapi.conf +++ b/lib/wx/api_gen/wxapi.conf @@ -505,15 +505,15 @@ {"data",[in,{base,binary}]}, {"alpha",[in,{base,binary}]}, {{4,pre_hook}, - "if(!static_data) {" - "data = (unsigned char *) malloc(Ecmd.bin[0]->size);" - "memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"}, + {c, "if(!static_data) {" + "data = (unsigned char *) malloc(Ecmd.bin[0]->size);" + "memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"}}, {{5,pre_hook}, - "if(!static_data) {" - " data = (unsigned char *) malloc(Ecmd.bin[0]->size);" - " alpha = (unsigned char *) malloc(Ecmd.bin[1]->size);" - " memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);" - " memcpy(alpha,Ecmd.bin[1]->base,Ecmd.bin[1]->size);}"} + {c, "if(!static_data) {" + " data = (unsigned char *) malloc(Ecmd.bin[0]->size);" + " alpha = (unsigned char *) malloc(Ecmd.bin[1]->size);" + " memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);" + " memcpy(alpha,Ecmd.bin[1]->base,Ecmd.bin[1]->size);}"}} ]}, '~wxImage',%'AddHandler', 'Blur','BlurHorizontal','BlurVertical', @@ -524,15 +524,15 @@ {"data",[in,{base,binary}]}, {"alpha",[in,{base,binary}]}, {{4,pre_hook}, - "if(!static_data) {" - "data = (unsigned char *) malloc(Ecmd.bin[0]->size);" - "memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"}, + {c, "if(!static_data) {" + "data = (unsigned char *) malloc(Ecmd.bin[0]->size);" + "memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"}}, {{5,pre_hook}, - "if(!static_data) {" - " data = (unsigned char *) malloc(Ecmd.bin[0]->size);" - " alpha = (unsigned char *) malloc(Ecmd.bin[1]->size);" - " memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);" - " memcpy(alpha,Ecmd.bin[1]->base,Ecmd.bin[1]->size);}"} + {c, "if(!static_data) {" + " data = (unsigned char *) malloc(Ecmd.bin[0]->size);" + " alpha = (unsigned char *) malloc(Ecmd.bin[1]->size);" + " memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);" + " memcpy(alpha,Ecmd.bin[1]->base,Ecmd.bin[1]->size);}"}} ]}, 'Destroy','FindFirstUnusedColour', % 'FindHandler', 'GetImageExtWildcard', @@ -551,15 +551,15 @@ 'Rotate90','SaveFile','Scale','Size', {'SetAlpha', [{{2,"alpha"},[in,{base,binary}, {def, none}]}, {{2,pre_hook}, - "if(!static_data) {" - "alpha = (unsigned char *) malloc(Ecmd.bin[0]->size);" - "memcpy(alpha,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"} + {c, "if(!static_data) {" + "alpha = (unsigned char *) malloc(Ecmd.bin[0]->size);" + "memcpy(alpha,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"}} ]}, {'SetData', [{"data",[in,{base,binary}]}, {pre_hook, - "if(!static_data) {" - "data = (unsigned char *) malloc(Ecmd.bin[0]->size);" - "memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"} + {c, "if(!static_data) {" + "data = (unsigned char *) malloc(Ecmd.bin[0]->size);" + "memcpy(data,Ecmd.bin[0]->base,Ecmd.bin[0]->size);}"}} ]}, 'SetMask','SetMaskColour','SetMaskFromImage','SetOption', 'SetPalette', @@ -1146,9 +1146,10 @@ {class, wxGLCanvas, wxWindow, [{skip, [{'SetCurrent', 2}]}], %% NA MAC - [{'wxGLCanvas', [{"attribList", [in, {single,array}]}]}, + [{'wxGLCanvas', [{"attribList", [in, {single,array}]}, + {pre_hook, {erl, "wxe_master:init_opengl(),"}}]}, 'GetContext', - {'SetCurrent', [{post_hook,"if(This->GetContext()) setActiveGL(Ecmd.caller,This)"}]}, + {'SetCurrent', [{post_hook,{c, "if(This->GetContext()) setActiveGL(Ecmd.caller,This)"}}]}, %%{'SetColour', [{"colour", [in, {single,array}]}]}, 'SwapBuffers']}. |