comparison src/render/opengles2/SDL_render_gles2.c @ 5212:115fff0641ee

Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Feb 2011 10:22:25 -0800
parents 7d64745f1363
children 7b6101f3ea58
comparison
equal deleted inserted replaced
5211:78db79f5a4e2 5212:115fff0641ee
183 { 183 {
184 GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; 184 GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
185 GLES2_ProgramCacheEntry *entry; 185 GLES2_ProgramCacheEntry *entry;
186 GLES2_ProgramCacheEntry *next; 186 GLES2_ProgramCacheEntry *next;
187 187
188 GLES2_ActivateRenderer(renderer);
189
190 /* Deallocate everything */ 188 /* Deallocate everything */
191 entry = rdata->program_cache.head; 189 if (rdata) {
192 while (entry) 190 GLES2_ActivateRenderer(renderer);
193 { 191
194 glDeleteShader(entry->vertex_shader->id); 192 entry = rdata->program_cache.head;
195 glDeleteShader(entry->fragment_shader->id); 193 while (entry) {
196 SDL_free(entry->vertex_shader); 194 glDeleteShader(entry->vertex_shader->id);
197 SDL_free(entry->fragment_shader); 195 glDeleteShader(entry->fragment_shader->id);
198 glDeleteProgram(entry->id); 196 SDL_free(entry->vertex_shader);
199 next = entry->next; 197 SDL_free(entry->fragment_shader);
200 SDL_free(entry); 198 glDeleteProgram(entry->id);
201 entry = next; 199 next = entry->next;
202 } 200 SDL_free(entry);
203 SDL_GL_DeleteContext(rdata->context); 201 entry = next;
204 SDL_free(rdata->shader_formats); 202 }
205 SDL_free(renderer->driverdata); 203 if (rdata->context) {
204 SDL_GL_DeleteContext(rdata->context);
205 }
206 if (rdata->shader_formats) {
207 SDL_free(rdata->shader_formats);
208 }
209 SDL_free(rdata);
210 }
206 SDL_free(renderer); 211 SDL_free(renderer);
207 } 212 }
208 213
209 /************************************************************************************************* 214 /*************************************************************************************************
210 * Texture APIs * 215 * Texture APIs *
1079 GLboolean hasCompiler; 1084 GLboolean hasCompiler;
1080 #endif 1085 #endif
1081 1086
1082 /* Create the renderer struct */ 1087 /* Create the renderer struct */
1083 renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); 1088 renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
1089 if (!renderer) {
1090 SDL_OutOfMemory();
1091 return NULL;
1092 }
1093
1084 rdata = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext)); 1094 rdata = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext));
1085 if (!renderer) 1095 if (!rdata) {
1086 { 1096 GLES2_DestroyRenderer(renderer);
1087 SDL_OutOfMemory(); 1097 SDL_OutOfMemory();
1088 SDL_free(renderer);
1089 SDL_free(rdata);
1090 return NULL; 1098 return NULL;
1091 } 1099 }
1092 renderer->info = GLES2_RenderDriver.info; 1100 renderer->info = GLES2_RenderDriver.info;
1093 renderer->window = window; 1101 renderer->window = window;
1094 renderer->driverdata = rdata; 1102 renderer->driverdata = rdata;
1095 1103
1096 renderer->info.flags = SDL_RENDERER_ACCELERATED; 1104 renderer->info.flags = SDL_RENDERER_ACCELERATED;
1097 1105
1098 /* Create the GL context */ 1106 /* Create an OpenGL ES 2.0 context */
1107 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1108 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
1109
1099 rdata->context = SDL_GL_CreateContext(window); 1110 rdata->context = SDL_GL_CreateContext(window);
1100 if (!rdata->context) 1111 if (!rdata->context)
1101 { 1112 {
1102 SDL_free(renderer); 1113 GLES2_DestroyRenderer(renderer);
1103 SDL_free(rdata);
1104 return NULL; 1114 return NULL;
1105 } 1115 }
1106 if (SDL_GL_MakeCurrent(window, rdata->context) < 0) { 1116 if (SDL_GL_MakeCurrent(window, rdata->context) < 0) {
1107 SDL_free(renderer); 1117 GLES2_DestroyRenderer(renderer);
1108 SDL_free(rdata);
1109 return NULL; 1118 return NULL;
1110 } 1119 }
1111 1120
1112 if (flags & SDL_RENDERER_PRESENTVSYNC) { 1121 if (flags & SDL_RENDERER_PRESENTVSYNC) {
1113 SDL_GL_SetSwapInterval(1); 1122 SDL_GL_SetSwapInterval(1);
1130 ++nFormats; 1139 ++nFormats;
1131 #endif /* ZUNE_HD */ 1140 #endif /* ZUNE_HD */
1132 rdata->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum)); 1141 rdata->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum));
1133 if (!rdata->shader_formats) 1142 if (!rdata->shader_formats)
1134 { 1143 {
1144 GLES2_DestroyRenderer(renderer);
1135 SDL_OutOfMemory(); 1145 SDL_OutOfMemory();
1136 SDL_free(renderer);
1137 SDL_free(rdata);
1138 return NULL; 1146 return NULL;
1139 } 1147 }
1140 rdata->shader_format_count = nFormats; 1148 rdata->shader_format_count = nFormats;
1141 #ifdef ZUNE_HD 1149 #ifdef ZUNE_HD
1142 rdata->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV; 1150 rdata->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV;
1143 #else /* !ZUNE_HD */ 1151 #else /* !ZUNE_HD */
1144 glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats); 1152 glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats);
1145 if (glGetError() != GL_NO_ERROR) 1153 if (glGetError() != GL_NO_ERROR)
1146 { 1154 {
1155 GLES2_DestroyRenderer(renderer);
1147 SDL_SetError("Failed to query supported shader formats"); 1156 SDL_SetError("Failed to query supported shader formats");
1148 SDL_free(renderer);
1149 SDL_free(rdata->shader_formats);
1150 SDL_free(rdata);
1151 return NULL; 1157 return NULL;
1152 } 1158 }
1153 if (hasCompiler) 1159 if (hasCompiler)
1154 rdata->shader_formats[nFormats - 1] = (GLenum)-1; 1160 rdata->shader_formats[nFormats - 1] = (GLenum)-1;
1155 #endif /* ZUNE_HD */ 1161 #endif /* ZUNE_HD */