@@ -62,124 +62,6 @@ struct renderer {
6262
6363static struct renderer renderer = {0 };
6464
65- static int getAndInitDisplay (TestPlatform * p , void * eglDisplay ) {
66- LOG (I , "Getting and initializing display" )
67- setenv (p -> ios_platform_env_key , p -> ios_platform_env_value , 1 );
68- if ((display = eglGetDisplay (eglDisplay )) == EGL_NO_DISPLAY ) {
69- logEGLError ( "eglGetDisplay" , eglGetError ());
70- return 0 ;
71- }
72- if (!eglInitialize (display , 0 , 0 )) {
73- logEGLError ( "eglInitialize" , eglGetError ());
74- return 0 ;
75- }
76- LOG (I , "Display got and initialized" )
77- return 1 ;
78- }
79-
80- static int chooseConfig (EGLint renderableType ) {
81- LOG (I , "Choosing config" )
82- EGLint attribs [] = {
83- EGL_SURFACE_TYPE , EGL_WINDOW_BIT ,
84- EGL_BLUE_SIZE , 8 ,
85- EGL_GREEN_SIZE , 8 ,
86- EGL_RED_SIZE , 8 ,
87- EGL_RENDERABLE_TYPE , renderableType ,
88- EGL_NONE
89- };
90-
91- if (!eglChooseConfig (display , attribs , & config , 1 , & numConfigs )) {
92- logEGLError ( "eglChooseConfig" , eglGetError ());
93- return 0 ;
94- }
95-
96- EGLint num_attrs = 0 ;
97- getEGLConfigAttributeForEGLAPIVersion (1 ,
98- 4 ,
99- NULL ,
100- & num_attrs );
101- EGLint * attrs = (EGLint * ) malloc (num_attrs * sizeof (EGLint ));
102- getEGLConfigAttributeForEGLAPIVersion (1 ,
103- 4 ,
104- attrs ,
105- & num_attrs );
106- displayEGLConfig (display , config , attrs , num_attrs );
107- LOG (I , "Config chosen" )
108- return 1 ;
109- }
110-
111- static int createSurface (void * nativeWinSurface ) {
112- LOG (I , "Creating surface" )
113- if (!(surface = eglCreateWindowSurface (display , config , nativeWinSurface , NULL ))) {
114- logEGLError ( "eglCreateWindowSurface" , eglGetError ());
115- return 0 ;
116- }
117-
118- if (!eglQuerySurface (display , surface , EGL_WIDTH , & width ) ||
119- !eglQuerySurface (display , surface , EGL_HEIGHT , & height )) {
120- logEGLError ( "eglQuerySurface" , eglGetError ());
121- return 0 ;
122- }
123- LOG (I , "Surface created" )
124- return 1 ;
125- }
126-
127- static int createContext (EGLint clientVersion ) {
128- LOG (I , "Initializing context" )
129- EGLint attribs [] = {
130- EGL_CONTEXT_CLIENT_VERSION , clientVersion /* 1 or 2 or 3 */ ,
131- EGL_NONE };
132- if (!(context = eglCreateContext (display , config , EGL_NO_CONTEXT , attribs ))) {
133- logEGLError ( "eglCreateContext" , eglGetError ());
134- return 0 ;
135- }
136-
137- LOG (I , "Context initialized" )
138- return 1 ;
139- }
140-
141- static int setAsCurrent (struct renderer * renderer ) {
142- LOG (I , "Setting current context" )
143- if (!eglMakeCurrent (display , surface , surface , context )) {
144- logEGLError ( "eglMakeCurrent" , eglGetError ());
145- return 0 ;
146- }
147-
148- LOG (I , "Set current context" )
149- return 1 ;
150- }
151-
152- static int destroyContext () {
153- if (!eglDestroyContext (display , context )) {
154- logEGLError ( "eglDestroyContext" , eglGetError ());
155- return 0 ;
156- };
157- context = EGL_NO_CONTEXT ;
158- return 1 ;
159- }
160-
161- static int destroySurface () {
162- if (!eglDestroySurface (display , surface )) {
163- logEGLError ( "eglDestroySurface" , eglGetError ());
164- return 0 ;
165- }
166- surface = EGL_NO_SURFACE ;
167- return 1 ;
168- }
169-
170- static int destroyDisplay () {
171- if (!eglTerminate (display )) {
172- logEGLError ( "eglTerminate" , eglGetError ());
173- return 0 ;
174- }
175- display = EGL_NO_DISPLAY ;
176- if (!eglReleaseThread ()) {
177- logEGLError ( "eglReleaseThread" , eglGetError ());
178- return 0 ;
179- }
180- return 1 ;
181- }
182-
18365/**************************************************************************
18466 OpenGL ES 1.x
18567 Inspired from: http://code.google.com/p/android-native-egl-example/source/browse/jni/renderer.cpp
@@ -698,24 +580,64 @@ static void sample(TestPlatform* p, void* eglDisplay, void* nativeWinSurface, in
698580 break ;
699581 }
700582
701- if (!getAndInitDisplay (p , eglDisplay )) {
583+ setenv (p -> ios_platform_env_key , p -> ios_platform_env_value , 1 );
584+ if ((display = eglGetDisplay (eglDisplay )) == EGL_NO_DISPLAY ) {
585+ logEGLError ( "eglGetDisplay" , eglGetError ());
586+ return ;
587+ }
588+ if (!eglInitialize (display , 0 , 0 )) {
589+ logEGLError ( "eglInitialize" , eglGetError ());
702590 return ;
703591 }
704592
705- if (!chooseConfig (renderer .renderableType )) {
593+ EGLint config_attribs [] = {
594+ EGL_SURFACE_TYPE , EGL_WINDOW_BIT ,
595+ EGL_BLUE_SIZE , 8 ,
596+ EGL_GREEN_SIZE , 8 ,
597+ EGL_RED_SIZE , 8 ,
598+ EGL_RENDERABLE_TYPE , renderer .renderableType ,
599+ EGL_NONE
600+ };
601+
602+ if (!eglChooseConfig (display , config_attribs , & config , 1 , & numConfigs )) {
603+ logEGLError ( "eglChooseConfig" , eglGetError ());
706604 return ;
707605 }
708606
607+ EGLint num_attrs = 0 ;
608+ getEGLConfigAttributeForEGLAPIVersion (1 ,
609+ 4 ,
610+ NULL ,
611+ & num_attrs );
612+ EGLint * attrs = (EGLint * ) malloc (num_attrs * sizeof (EGLint ));
613+ getEGLConfigAttributeForEGLAPIVersion (1 ,
614+ 4 ,
615+ attrs ,
616+ & num_attrs );
617+ displayEGLConfig (display , config , attrs , num_attrs );
618+
709619 init :
710- if (!createSurface (nativeWinSurface )) {
620+ if (!(surface = eglCreateWindowSurface (display , config , nativeWinSurface , NULL ))) {
621+ logEGLError ( "eglCreateWindowSurface" , eglGetError ());
711622 return ;
712623 }
713624
714- if (!createContext (renderer .clientVersion )) {
625+ if (!eglQuerySurface (display , surface , EGL_WIDTH , & width ) ||
626+ !eglQuerySurface (display , surface , EGL_HEIGHT , & height )) {
627+ logEGLError ( "eglQuerySurface" , eglGetError ());
628+ return ;
629+ }
630+
631+ EGLint context_attribs [] = {
632+ EGL_CONTEXT_CLIENT_VERSION , renderer .clientVersion /* 1 or 2 or 3 */ ,
633+ EGL_NONE };
634+ if (!(context = eglCreateContext (display , config , EGL_NO_CONTEXT , context_attribs ))) {
635+ logEGLError ( "eglCreateContext" , eglGetError ());
715636 return ;
716637 }
717638
718- if (!setAsCurrent (& renderer )) {
639+ if (!eglMakeCurrent (display , surface , surface , context )) {
640+ logEGLError ( "eglMakeCurrent" , eglGetError ());
719641 return ;
720642 }
721643
@@ -743,16 +665,21 @@ static void sample(TestPlatform* p, void* eglDisplay, void* nativeWinSurface, in
743665 if (error != EGL_CONTEXT_LOST ) {
744666 break ;
745667 }
746- if (!destroySurface ()) {
668+ if (!eglDestroySurface (display , surface )) {
669+ logEGLError ( "eglDestroySurface" , eglGetError ());
747670 break ;
748671 }
672+ surface = EGL_NO_SURFACE ;
749673
750- if (!destroyContext ()) {
674+ if (!eglDestroyContext (display , context )) {
675+ logEGLError ( "eglDestroyContext" , eglGetError ());
751676 break ;
752- }
677+ };
678+ context = EGL_NO_CONTEXT ;
753679
754- if (!setAsCurrent (& renderer )) {
755- break ;
680+ if (!eglMakeCurrent (display , surface , surface , context )) {
681+ logEGLError ( "eglMakeCurrent" , eglGetError ());
682+ return ;
756683 }
757684
758685 goto init ;
@@ -765,19 +692,30 @@ static void sample(TestPlatform* p, void* eglDisplay, void* nativeWinSurface, in
765692
766693 renderer .destroy ();
767694
768- if (!destroySurface ()) {
695+ if (!eglDestroySurface (display , surface )) {
696+ logEGLError ( "eglDestroySurface" , eglGetError ());
769697 return ;
770698 }
699+ surface = EGL_NO_SURFACE ;
771700
772- if (!destroyContext ()) {
701+ if (!eglDestroyContext (display , context )) {
702+ logEGLError ( "eglDestroyContext" , eglGetError ());
773703 return ;
774- }
704+ };
705+ context = EGL_NO_CONTEXT ;
775706
776- if (!setAsCurrent (& renderer )) {
707+ if (!eglMakeCurrent (display , surface , surface , context )) {
708+ logEGLError ( "eglMakeCurrent" , eglGetError ());
777709 return ;
778710 }
779711
780- if (!destroyDisplay ()) {
712+ if (!eglTerminate (display )) {
713+ logEGLError ( "eglTerminate" , eglGetError ());
714+ return ;
715+ }
716+ display = EGL_NO_DISPLAY ;
717+ if (!eglReleaseThread ()) {
718+ logEGLError ( "eglReleaseThread" , eglGetError ());
781719 return ;
782720 }
783721}
0 commit comments