Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gl.c @ 2230:9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
The SDL 1.2 API version of testsprite went from 120 FPS to 320 FPS. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 12 Aug 2007 07:02:28 +0000 |
parents | 926294b2bb4e |
children | fb01ee9716bc |
comparison
equal
deleted
inserted
replaced
2229:22342048bcb8 | 2230:9b7d29d2432b |
---|---|
29 #include "SDL_pixels_c.h" | 29 #include "SDL_pixels_c.h" |
30 #include "SDL_rect_c.h" | 30 #include "SDL_rect_c.h" |
31 #include "SDL_yuv_sw_c.h" | 31 #include "SDL_yuv_sw_c.h" |
32 | 32 |
33 /* OpenGL renderer implementation */ | 33 /* OpenGL renderer implementation */ |
34 | |
35 /* Details on optimizing the texture path on Mac OS X: | |
36 http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html | |
37 */ | |
34 | 38 |
35 static const float inv255f = 1.0f / 255.0f; | 39 static const float inv255f = 1.0f / 255.0f; |
36 | 40 |
37 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); | 41 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); |
38 static int GL_ActivateRenderer(SDL_Renderer * renderer); | 42 static int GL_ActivateRenderer(SDL_Renderer * renderer); |
459 internalFormat = GL_RGB8; | 463 internalFormat = GL_RGB8; |
460 format = GL_RGBA; | 464 format = GL_RGBA; |
461 type = GL_UNSIGNED_BYTE; | 465 type = GL_UNSIGNED_BYTE; |
462 break; | 466 break; |
463 case SDL_PIXELFORMAT_ARGB8888: | 467 case SDL_PIXELFORMAT_ARGB8888: |
468 #ifdef __MACOSX__ | |
469 internalFormat = GL_RGBA; | |
470 format = GL_BGRA; | |
471 type = GL_UNSIGNED_INT_8_8_8_8_REV; | |
472 #else | |
464 internalFormat = GL_RGBA8; | 473 internalFormat = GL_RGBA8; |
465 format = GL_BGRA; | 474 format = GL_BGRA; |
466 type = GL_UNSIGNED_BYTE; | 475 type = GL_UNSIGNED_BYTE; |
476 #endif | |
467 break; | 477 break; |
468 case SDL_PIXELFORMAT_ABGR8888: | 478 case SDL_PIXELFORMAT_ABGR8888: |
469 internalFormat = GL_RGBA8; | 479 internalFormat = GL_RGBA8; |
470 format = GL_RGBA; | 480 format = GL_RGBA; |
471 type = GL_UNSIGNED_BYTE; | 481 type = GL_UNSIGNED_BYTE; |
524 data->texh = (GLfloat) texture->h / texture_h; | 534 data->texh = (GLfloat) texture->h / texture_h; |
525 } | 535 } |
526 data->format = format; | 536 data->format = format; |
527 data->formattype = type; | 537 data->formattype = type; |
528 renderdata->glBindTexture(data->type, data->texture); | 538 renderdata->glBindTexture(data->type, data->texture); |
529 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, | 539 renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, |
530 texture_h, 0, format, type, NULL); | 540 GL_NEAREST); |
541 renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, | |
542 GL_NEAREST); | |
543 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, | |
544 GL_CLAMP_TO_EDGE); | |
545 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, | |
546 GL_CLAMP_TO_EDGE); | |
547 #ifdef __MACOSX__ | |
548 #ifndef GL_TEXTURE_STORAGE_HINT_APPLE | |
549 #define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC | |
550 #endif | |
551 #ifndef STORAGE_CACHED_APPLE | |
552 #define STORAGE_CACHED_APPLE 0x85BE | |
553 #endif | |
554 #ifndef STORAGE_SHARED_APPLE | |
555 #define STORAGE_SHARED_APPLE 0x85BF | |
556 #endif | |
557 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { | |
558 renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, | |
559 GL_STORAGE_SHARED_APPLE); | |
560 } else { | |
561 renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, | |
562 GL_STORAGE_CACHED_APPLE); | |
563 } | |
564 if (data->pixels && internalFormat == GL_RGBA && format == GL_BGRA | |
565 && type == GL_UNSIGNED_INT_8_8_8_8_REV && data->pixels) { | |
566 renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); | |
567 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, | |
568 texture_h, 0, format, type, data->pixels); | |
569 } else | |
570 #endif | |
571 { | |
572 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, | |
573 texture_h, 0, format, type, NULL); | |
574 } | |
531 result = renderdata->glGetError(); | 575 result = renderdata->glGetError(); |
532 if (result != GL_NO_ERROR) { | 576 if (result != GL_NO_ERROR) { |
533 GL_SetError("glTexImage2D()", result); | 577 GL_SetError("glTexImage2D()", result); |
534 return -1; | 578 return -1; |
535 } | 579 } |