Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gles.c @ 3122:6c98826d88b0
OpenGL ES renderer state fixes. Now GL_TEXTURE_2D is not enabled by default.
author | Mike Gorchak <lestat@i.com.ua> |
---|---|
date | Thu, 14 May 2009 10:54:34 +0000 |
parents | 82e60908fab1 |
children | 7f684f249ec9 |
comparison
equal
deleted
inserted
replaced
3121:4a28c7c985b2 | 3122:6c98826d88b0 |
---|---|
101 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | | 101 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | |
102 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), | 102 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), |
103 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | | 103 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | |
104 SDL_TEXTURESCALEMODE_SLOW), 2, | 104 SDL_TEXTURESCALEMODE_SLOW), 2, |
105 { | 105 { |
106 SDL_PIXELFORMAT_RGB24, | 106 /* OpenGL ES 1.x supported formats list */ |
107 SDL_PIXELFORMAT_ABGR8888, | 107 SDL_PIXELFORMAT_BGR24, |
108 }, | 108 SDL_PIXELFORMAT_ABGR8888 |
109 }, | |
109 0, | 110 0, |
110 0} | 111 0} |
111 }; | 112 }; |
112 | 113 |
113 typedef struct | 114 typedef struct |
180 static int | 181 static int |
181 GLES_LoadFunctions(GLES_RenderData * data) | 182 GLES_LoadFunctions(GLES_RenderData * data) |
182 { | 183 { |
183 | 184 |
184 #define SDL_PROC(ret,func,params) \ | 185 #define SDL_PROC(ret,func,params) \ |
185 data->func = func; | 186 data->func = func; |
186 #include "SDL_glesfuncs.h" | 187 #include "SDL_glesfuncs.h" |
187 #undef SDL_PROC | 188 #undef SDL_PROC |
188 | 189 |
189 return 0; | 190 return 0; |
190 } | 191 } |
299 | 300 |
300 /* Set up parameters for rendering */ | 301 /* Set up parameters for rendering */ |
301 data->blendMode = -1; | 302 data->blendMode = -1; |
302 data->glDisable(GL_DEPTH_TEST); | 303 data->glDisable(GL_DEPTH_TEST); |
303 data->glDisable(GL_CULL_FACE); | 304 data->glDisable(GL_CULL_FACE); |
304 data->glEnable(GL_TEXTURE_2D); | |
305 data->updateSize = SDL_TRUE; | 305 data->updateSize = SDL_TRUE; |
306 | 306 |
307 return renderer; | 307 return renderer; |
308 } | 308 } |
309 | 309 |
349 } | 349 } |
350 return value; | 350 return value; |
351 } | 351 } |
352 | 352 |
353 static int | 353 static int |
354 GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 354 GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) |
355 { | 355 { |
356 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; | 356 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; |
357 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 357 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
358 GLES_TextureData *data; | 358 GLES_TextureData *data; |
359 GLint internalFormat; | 359 GLint internalFormat; |
360 GLenum format, type; | 360 GLenum format, type; |
361 int texture_w, texture_h; | 361 int texture_w, texture_h; |
362 GLenum result; | 362 GLenum result; |
363 | 363 |
364 switch (texture->format) { | 364 switch (texture->format) { |
365 case SDL_PIXELFORMAT_INDEX1LSB: | |
366 case SDL_PIXELFORMAT_INDEX1MSB: | |
367 case SDL_PIXELFORMAT_INDEX8: | |
368 case SDL_PIXELFORMAT_RGB332: | |
369 case SDL_PIXELFORMAT_RGB444: | |
370 case SDL_PIXELFORMAT_RGB555: | |
371 case SDL_PIXELFORMAT_ARGB4444: | |
372 case SDL_PIXELFORMAT_ARGB1555: | |
373 case SDL_PIXELFORMAT_BGR24: | 365 case SDL_PIXELFORMAT_BGR24: |
374 case SDL_PIXELFORMAT_BGR888: | 366 internalFormat = GL_RGB; |
375 case SDL_PIXELFORMAT_RGB888: | 367 format = GL_RGB; |
376 case SDL_PIXELFORMAT_RGBA8888: | 368 type = GL_UNSIGNED_BYTE; |
377 case SDL_PIXELFORMAT_ARGB2101010: | 369 break; |
378 case SDL_PIXELFORMAT_ARGB8888: | |
379 case SDL_PIXELFORMAT_RGB24: | |
380 internalFormat = GL_RGB; | |
381 format = GL_RGB; | |
382 type = GL_UNSIGNED_BYTE; | |
383 break; | |
384 case SDL_PIXELFORMAT_ABGR8888: | 370 case SDL_PIXELFORMAT_ABGR8888: |
385 internalFormat = GL_RGBA; | 371 internalFormat = GL_RGBA; |
386 format = GL_RGBA; | 372 format = GL_RGBA; |
387 type = GL_UNSIGNED_BYTE; | 373 type = GL_UNSIGNED_BYTE; |
388 break; | 374 break; |
389 /* | 375 /* |
390 These formats would be supported if SDL had the necessary pixel formats | 376 These formats would be supported if SDL had the necessary pixel formats |
391 case SDL_PIXELFORMAT_BGR565: | 377 case SDL_PIXELFORMAT_BGR565: |
392 internalFormat = GL_RGB; | 378 internalFormat = GL_RGB; |
393 format = GL_RGB; | 379 format = GL_RGB; |
401 case SDL_PIXELFORMAT_ABGR4444: | 387 case SDL_PIXELFORMAT_ABGR4444: |
402 internalFormat = GL_RGBA; | 388 internalFormat = GL_RGBA; |
403 format = GL_RGBA; | 389 format = GL_RGBA; |
404 type = GL_UNSIGNED_SHORT_4_4_4_4; | 390 type = GL_UNSIGNED_SHORT_4_4_4_4; |
405 break; | 391 break; |
406 */ | 392 */ |
407 default: | 393 default: |
408 SDL_SetError("Unsupported texture format"); | 394 SDL_SetError("Unsupported texture format"); |
409 return -1; | 395 return -1; |
410 } | 396 } |
411 | 397 |
426 } | 412 } |
427 | 413 |
428 texture->driverdata = data; | 414 texture->driverdata = data; |
429 | 415 |
430 renderdata->glGetError(); | 416 renderdata->glGetError(); |
417 renderdata->glEnable(GL_TEXTURE_2D); | |
431 renderdata->glGenTextures(1, &data->texture); | 418 renderdata->glGenTextures(1, &data->texture); |
432 | 419 |
433 data->type = GL_TEXTURE_2D; | 420 data->type = GL_TEXTURE_2D; |
434 /* no NPOV textures allowed in OpenGL ES (yet) */ | 421 /* no NPOV textures allowed in OpenGL ES (yet) */ |
435 texture_w = power_of_2(texture->w); | 422 texture_w = power_of_2(texture->w); |
449 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, | 436 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, |
450 GL_CLAMP_TO_EDGE); | 437 GL_CLAMP_TO_EDGE); |
451 | 438 |
452 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, | 439 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, |
453 texture_h, 0, format, type, NULL); | 440 texture_h, 0, format, type, NULL); |
441 renderdata->glDisable(GL_TEXTURE_2D); | |
454 | 442 |
455 result = renderdata->glGetError(); | 443 result = renderdata->glGetError(); |
456 if (result != GL_NO_ERROR) { | 444 if (result != GL_NO_ERROR) { |
457 GLES_SetError("glTexImage2D()", result); | 445 GLES_SetError("glTexImage2D()", result); |
458 return -1; | 446 return -1; |
543 return -1; | 531 return -1; |
544 } | 532 } |
545 } | 533 } |
546 | 534 |
547 static int | 535 static int |
548 GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 536 GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, |
549 const SDL_Rect * rect, const void *pixels, int pitch) | 537 const SDL_Rect *rect, const void *pixels, int pitch) |
550 { | 538 { |
551 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; | 539 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; |
552 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; | 540 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
553 GLenum result; | 541 GLenum result; |
554 | 542 |
543 renderdata->glGetError(); | |
544 renderdata->glEnable(data->type); | |
555 SetupTextureUpdate(renderdata, texture, pitch); | 545 SetupTextureUpdate(renderdata, texture, pitch); |
556 renderdata->glGetError(); | |
557 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, | 546 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, |
558 rect->h, data->format, data->formattype, | 547 rect->h, data->format, data->formattype, |
559 pixels); | 548 pixels); |
549 renderdata->glDisable(data->type); | |
560 result = renderdata->glGetError(); | 550 result = renderdata->glGetError(); |
561 if (result != GL_NO_ERROR) { | 551 if (result != GL_NO_ERROR) { |
562 GLES_SetError("glTexSubImage2D()", result); | 552 GLES_SetError("glTexSubImage2D()", result); |
563 return -1; | 553 return -1; |
564 } | 554 } |
649 data->glVertexPointer(2, GL_SHORT, 0, vertices); | 639 data->glVertexPointer(2, GL_SHORT, 0, vertices); |
650 data->glEnableClientState(GL_VERTEX_ARRAY); | 640 data->glEnableClientState(GL_VERTEX_ARRAY); |
651 data->glDrawArrays(GL_POINTS, 0, 1); | 641 data->glDrawArrays(GL_POINTS, 0, 1); |
652 data->glDisableClientState(GL_VERTEX_ARRAY); | 642 data->glDisableClientState(GL_VERTEX_ARRAY); |
653 | 643 |
644 data->glDisable(GL_BLEND); | |
645 | |
654 return 0; | 646 return 0; |
655 } | 647 } |
656 | 648 |
657 static int | 649 static int |
658 GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | 650 GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) |
674 | 666 |
675 data->glVertexPointer(2, GL_SHORT, 0, vertices); | 667 data->glVertexPointer(2, GL_SHORT, 0, vertices); |
676 data->glEnableClientState(GL_VERTEX_ARRAY); | 668 data->glEnableClientState(GL_VERTEX_ARRAY); |
677 data->glDrawArrays(GL_LINES, 0, 2); | 669 data->glDrawArrays(GL_LINES, 0, 2); |
678 data->glDisableClientState(GL_VERTEX_ARRAY); | 670 data->glDisableClientState(GL_VERTEX_ARRAY); |
671 | |
672 data->glDisable(GL_BLEND); | |
679 | 673 |
680 return 0; | 674 return 0; |
681 } | 675 } |
682 | 676 |
683 static int | 677 static int |
710 data->glVertexPointer(2, GL_SHORT, 0, vertices); | 704 data->glVertexPointer(2, GL_SHORT, 0, vertices); |
711 data->glEnableClientState(GL_VERTEX_ARRAY); | 705 data->glEnableClientState(GL_VERTEX_ARRAY); |
712 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 706 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
713 data->glDisableClientState(GL_VERTEX_ARRAY); | 707 data->glDisableClientState(GL_VERTEX_ARRAY); |
714 | 708 |
709 data->glDisable(GL_BLEND); | |
710 | |
715 return 0; | 711 return 0; |
716 } | 712 } |
717 | 713 |
718 static int | 714 static int |
719 GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 715 GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
725 int minx, miny, maxx, maxy; | 721 int minx, miny, maxx, maxy; |
726 GLfloat minu, maxu, minv, maxv; | 722 GLfloat minu, maxu, minv, maxv; |
727 int i; | 723 int i; |
728 void *temp_buffer; /* used for reformatting dirty rect pixels */ | 724 void *temp_buffer; /* used for reformatting dirty rect pixels */ |
729 void *temp_ptr; | 725 void *temp_ptr; |
726 | |
727 data->glEnable(GL_TEXTURE_2D); | |
730 | 728 |
731 if (texturedata->dirty.list) { | 729 if (texturedata->dirty.list) { |
732 SDL_DirtyRect *dirty; | 730 SDL_DirtyRect *dirty; |
733 void *pixels; | 731 void *pixels; |
734 int bpp = SDL_BYTESPERPIXEL(texture->format); | 732 int bpp = SDL_BYTESPERPIXEL(texture->format); |
765 } | 763 } |
766 SDL_ClearDirtyRects(&texturedata->dirty); | 764 SDL_ClearDirtyRects(&texturedata->dirty); |
767 } | 765 } |
768 | 766 |
769 data->glBindTexture(texturedata->type, texturedata->texture); | 767 data->glBindTexture(texturedata->type, texturedata->texture); |
770 data->glEnable(GL_TEXTURE_2D); | |
771 | 768 |
772 if (texture->modMode) { | 769 if (texture->modMode) { |
773 data->glColor4f((GLfloat) texture->r * inv255f, | 770 data->glColor4f((GLfloat) texture->r * inv255f, |
774 (GLfloat) texture->g * inv255f, | 771 (GLfloat) texture->g * inv255f, |
775 (GLfloat) texture->b * inv255f, | 772 (GLfloat) texture->b * inv255f, |
849 data->glVertexPointer(2, GL_SHORT, 0, vertices); | 846 data->glVertexPointer(2, GL_SHORT, 0, vertices); |
850 data->glEnableClientState(GL_VERTEX_ARRAY); | 847 data->glEnableClientState(GL_VERTEX_ARRAY); |
851 data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); | 848 data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
852 data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 849 data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
853 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 850 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
854 | 851 data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
855 } | 852 data->glDisableClientState(GL_VERTEX_ARRAY); |
853 } | |
854 | |
855 data->glDisable(GL_TEXTURE_2D); | |
856 | 856 |
857 return 0; | 857 return 0; |
858 } | 858 } |
859 | 859 |
860 static void | 860 static void |
861 GLES_RenderPresent(SDL_Renderer * renderer) | 861 GLES_RenderPresent(SDL_Renderer *renderer) |
862 { | 862 { |
863 SDL_GL_SwapWindow(renderer->window); | 863 SDL_GL_SwapWindow(renderer->window); |
864 } | 864 } |
865 | 865 |
866 static void | 866 static void |
888 { | 888 { |
889 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 889 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
890 | 890 |
891 if (data) { | 891 if (data) { |
892 if (data->context) { | 892 if (data->context) { |
893 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ | |
894 SDL_GL_DeleteContext(data->context); | 893 SDL_GL_DeleteContext(data->context); |
895 } | 894 } |
896 SDL_free(data); | 895 SDL_free(data); |
897 } | 896 } |
898 SDL_free(renderer); | 897 SDL_free(renderer); |