Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gl.c @ 5141:da10636e5eca
Making the API simpler, scaling is always defined as linear interpolation and should be supported as much as possible on all renderers.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 31 Jan 2011 22:44:43 -0800 |
parents | c2539ff054c8 |
children | e743b9c3f6d6 |
comparison
equal
deleted
inserted
replaced
5140:e594f07297a9 | 5141:da10636e5eca |
---|---|
82 static int GL_SetTextureColorMod(SDL_Renderer * renderer, | 82 static int GL_SetTextureColorMod(SDL_Renderer * renderer, |
83 SDL_Texture * texture); | 83 SDL_Texture * texture); |
84 static int GL_SetTextureAlphaMod(SDL_Renderer * renderer, | 84 static int GL_SetTextureAlphaMod(SDL_Renderer * renderer, |
85 SDL_Texture * texture); | 85 SDL_Texture * texture); |
86 static int GL_SetTextureBlendMode(SDL_Renderer * renderer, | 86 static int GL_SetTextureBlendMode(SDL_Renderer * renderer, |
87 SDL_Texture * texture); | |
88 static int GL_SetTextureScaleMode(SDL_Renderer * renderer, | |
89 SDL_Texture * texture); | 87 SDL_Texture * texture); |
90 static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 88 static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
91 const SDL_Rect * rect, const void *pixels, | 89 const SDL_Rect * rect, const void *pixels, |
92 int pitch); | 90 int pitch); |
93 static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 91 static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
124 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), | 122 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
125 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | | 123 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | |
126 SDL_TEXTUREMODULATE_ALPHA), | 124 SDL_TEXTUREMODULATE_ALPHA), |
127 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | | 125 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | |
128 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), | 126 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), |
129 (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST | SDL_SCALEMODE_SLOW), | |
130 15, | 127 15, |
131 { | 128 { |
132 SDL_PIXELFORMAT_INDEX1LSB, | 129 SDL_PIXELFORMAT_INDEX1LSB, |
133 SDL_PIXELFORMAT_INDEX1MSB, | 130 SDL_PIXELFORMAT_INDEX1MSB, |
134 SDL_PIXELFORMAT_INDEX8, | 131 SDL_PIXELFORMAT_INDEX8, |
157 SDL_bool GL_EXT_paletted_texture_supported; | 154 SDL_bool GL_EXT_paletted_texture_supported; |
158 SDL_bool GL_APPLE_ycbcr_422_supported; | 155 SDL_bool GL_APPLE_ycbcr_422_supported; |
159 SDL_bool GL_MESA_ycbcr_texture_supported; | 156 SDL_bool GL_MESA_ycbcr_texture_supported; |
160 SDL_bool GL_ARB_fragment_program_supported; | 157 SDL_bool GL_ARB_fragment_program_supported; |
161 int blendMode; | 158 int blendMode; |
162 int scaleMode; | |
163 | 159 |
164 /* OpenGL functions */ | 160 /* OpenGL functions */ |
165 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; | 161 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; |
166 #include "SDL_glfuncs.h" | 162 #include "SDL_glfuncs.h" |
167 #undef SDL_PROC | 163 #undef SDL_PROC |
301 renderer->SetTexturePalette = GL_SetTexturePalette; | 297 renderer->SetTexturePalette = GL_SetTexturePalette; |
302 renderer->GetTexturePalette = GL_GetTexturePalette; | 298 renderer->GetTexturePalette = GL_GetTexturePalette; |
303 renderer->SetTextureColorMod = GL_SetTextureColorMod; | 299 renderer->SetTextureColorMod = GL_SetTextureColorMod; |
304 renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod; | 300 renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod; |
305 renderer->SetTextureBlendMode = GL_SetTextureBlendMode; | 301 renderer->SetTextureBlendMode = GL_SetTextureBlendMode; |
306 renderer->SetTextureScaleMode = GL_SetTextureScaleMode; | |
307 renderer->UpdateTexture = GL_UpdateTexture; | 302 renderer->UpdateTexture = GL_UpdateTexture; |
308 renderer->LockTexture = GL_LockTexture; | 303 renderer->LockTexture = GL_LockTexture; |
309 renderer->UnlockTexture = GL_UnlockTexture; | 304 renderer->UnlockTexture = GL_UnlockTexture; |
310 renderer->DirtyTexture = GL_DirtyTexture; | 305 renderer->DirtyTexture = GL_DirtyTexture; |
311 renderer->RenderClear = GL_RenderClear; | 306 renderer->RenderClear = GL_RenderClear; |
420 data->GL_ARB_fragment_program_supported = SDL_TRUE; | 415 data->GL_ARB_fragment_program_supported = SDL_TRUE; |
421 } | 416 } |
422 | 417 |
423 /* Set up parameters for rendering */ | 418 /* Set up parameters for rendering */ |
424 data->blendMode = -1; | 419 data->blendMode = -1; |
425 data->scaleMode = -1; | |
426 data->glDisable(GL_DEPTH_TEST); | 420 data->glDisable(GL_DEPTH_TEST); |
427 data->glDisable(GL_CULL_FACE); | 421 data->glDisable(GL_CULL_FACE); |
428 /* This ended up causing video discrepancies between OpenGL and Direct3D */ | 422 /* This ended up causing video discrepancies between OpenGL and Direct3D */ |
429 /*data->glEnable(GL_LINE_SMOOTH);*/ | 423 /*data->glEnable(GL_LINE_SMOOTH);*/ |
430 if (data->GL_ARB_texture_rectangle_supported) { | 424 if (data->GL_ARB_texture_rectangle_supported) { |
840 data->format = format; | 834 data->format = format; |
841 data->formattype = type; | 835 data->formattype = type; |
842 renderdata->glEnable(data->type); | 836 renderdata->glEnable(data->type); |
843 renderdata->glBindTexture(data->type, data->texture); | 837 renderdata->glBindTexture(data->type, data->texture); |
844 renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, | 838 renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, |
845 GL_NEAREST); | 839 GL_LINEAR); |
846 renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, | 840 renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, |
847 GL_NEAREST); | 841 GL_LINEAR); |
848 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, | 842 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, |
849 GL_CLAMP_TO_EDGE); | 843 GL_CLAMP_TO_EDGE); |
850 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, | 844 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, |
851 GL_CLAMP_TO_EDGE); | 845 GL_CLAMP_TO_EDGE); |
852 #ifdef __MACOSX__ | 846 #ifdef __MACOSX__ |
994 case SDL_BLENDMODE_MOD: | 988 case SDL_BLENDMODE_MOD: |
995 return 0; | 989 return 0; |
996 default: | 990 default: |
997 SDL_Unsupported(); | 991 SDL_Unsupported(); |
998 texture->blendMode = SDL_BLENDMODE_NONE; | 992 texture->blendMode = SDL_BLENDMODE_NONE; |
999 return -1; | |
1000 } | |
1001 } | |
1002 | |
1003 static int | |
1004 GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
1005 { | |
1006 switch (texture->scaleMode) { | |
1007 case SDL_SCALEMODE_NONE: | |
1008 case SDL_SCALEMODE_FAST: | |
1009 case SDL_SCALEMODE_SLOW: | |
1010 return 0; | |
1011 case SDL_SCALEMODE_BEST: | |
1012 SDL_Unsupported(); | |
1013 texture->scaleMode = SDL_SCALEMODE_SLOW; | |
1014 return -1; | |
1015 default: | |
1016 SDL_Unsupported(); | |
1017 texture->scaleMode = SDL_SCALEMODE_NONE; | |
1018 return -1; | 993 return -1; |
1019 } | 994 } |
1020 } | 995 } |
1021 | 996 |
1022 static int | 997 static int |
1361 if (data->fragment_program_mask != ~0) { | 1336 if (data->fragment_program_mask != ~0) { |
1362 shader = data->fragment_program_mask; | 1337 shader = data->fragment_program_mask; |
1363 } | 1338 } |
1364 } | 1339 } |
1365 | 1340 |
1366 if (texture->scaleMode != data->scaleMode) { | |
1367 switch (texture->scaleMode) { | |
1368 case SDL_SCALEMODE_NONE: | |
1369 case SDL_SCALEMODE_FAST: | |
1370 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, | |
1371 GL_NEAREST); | |
1372 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, | |
1373 GL_NEAREST); | |
1374 break; | |
1375 case SDL_SCALEMODE_SLOW: | |
1376 case SDL_SCALEMODE_BEST: | |
1377 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, | |
1378 GL_LINEAR); | |
1379 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, | |
1380 GL_LINEAR); | |
1381 break; | |
1382 } | |
1383 data->scaleMode = texture->scaleMode; | |
1384 } | |
1385 | |
1386 if (shader) { | 1341 if (shader) { |
1387 data->glEnable(GL_FRAGMENT_PROGRAM_ARB); | 1342 data->glEnable(GL_FRAGMENT_PROGRAM_ARB); |
1388 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader); | 1343 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader); |
1389 } | 1344 } |
1390 | 1345 |