Mercurial > sdl-ios-xcode
annotate src/video/SDL_renderer_gl.c @ 2843:e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
texture. This is a total hack though. Maybe we should be using a different
texture format?
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 06 Dec 2008 18:22:28 +0000 |
parents | 53ca0d758b0a |
children | 70b63882d2ef |
rev | line source |
---|---|
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
24 #if SDL_VIDEO_RENDER_OGL |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
25 |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
26 #include "SDL_video.h" |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
27 #include "SDL_opengl.h" |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
28 #include "SDL_sysvideo.h" |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
29 #include "SDL_pixels_c.h" |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
30 #include "SDL_rect_c.h" |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
31 #include "SDL_yuv_sw_c.h" |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
2246
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
33 #ifdef __MACOSX__ |
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
34 #include <OpenGL/OpenGL.h> |
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
35 #endif |
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
36 |
2778
38dfc890ee6b
Preliminary support for YUV textures
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
37 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 /* OpenGL renderer implementation */ |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
40 /* Details on optimizing the texture path on Mac OS X: |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
41 http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
42 */ |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
43 |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
44 /* !!! FIXME: this should go in a higher level than the GL renderer. */ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
45 static __inline__ int |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
46 bytes_per_pixel(const Uint32 format) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
47 { |
2839 | 48 if (!SDL_ISPIXELFORMAT_FOURCC(format)) { |
49 return SDL_BYTESPERPIXEL(format); | |
50 } | |
51 | |
52 /* FOURCC format */ | |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
53 switch (format) { |
2839 | 54 case SDL_PIXELFORMAT_YV12: |
55 case SDL_PIXELFORMAT_IYUV: | |
56 case SDL_PIXELFORMAT_YUY2: | |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
57 case SDL_PIXELFORMAT_UYVY: |
2839 | 58 case SDL_PIXELFORMAT_YVYU: |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
59 return 2; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
60 default: |
2839 | 61 return 1; /* shouldn't ever hit this. */ |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
62 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
63 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
64 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
65 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
66 static const float inv255f = 1.0f / 255.0f; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
67 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
69 static int GL_ActivateRenderer(SDL_Renderer * renderer); |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
70 static int GL_DisplayModeChanged(SDL_Renderer * renderer); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
72 static int GL_QueryTexturePixels(SDL_Renderer * renderer, |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
73 SDL_Texture * texture, void **pixels, |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
74 int *pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 static int GL_SetTexturePalette(SDL_Renderer * renderer, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 const SDL_Color * colors, int firstcolor, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 int ncolors); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 static int GL_GetTexturePalette(SDL_Renderer * renderer, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 SDL_Texture * texture, SDL_Color * colors, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 int firstcolor, int ncolors); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
82 static int GL_SetTextureColorMod(SDL_Renderer * renderer, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
83 SDL_Texture * texture); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
84 static int GL_SetTextureAlphaMod(SDL_Renderer * renderer, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
85 SDL_Texture * texture); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
86 static int GL_SetTextureBlendMode(SDL_Renderer * renderer, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
87 SDL_Texture * texture); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
88 static int GL_SetTextureScaleMode(SDL_Renderer * renderer, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
89 SDL_Texture * texture); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 const SDL_Rect * rect, const void *pixels, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 int pitch); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
94 const SDL_Rect * rect, int markDirty, void **pixels, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
95 int *pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 int numrects, const SDL_Rect * rects); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
99 static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
100 Uint8 a, const SDL_Rect * rect); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
102 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 static void GL_RenderPresent(SDL_Renderer * renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 static void GL_DestroyRenderer(SDL_Renderer * renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 SDL_RenderDriver GL_RenderDriver = { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 GL_CreateRenderer, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 "opengl", |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
112 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD | |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
113 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
114 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
115 SDL_TEXTUREMODULATE_ALPHA), |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
116 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
117 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
118 SDL_TEXTUREBLENDMODE_MOD), |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
119 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
120 SDL_TEXTURESCALEMODE_SLOW), |
2813
49243a6e9ff1
Removed the hacky stuff for YUV OpenGL textures, since Ryan's pixel shader code
Sam Lantinga <slouken@libsdl.org>
parents:
2812
diff
changeset
|
121 15, |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
123 SDL_PIXELFORMAT_INDEX1LSB, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
124 SDL_PIXELFORMAT_INDEX1MSB, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
125 SDL_PIXELFORMAT_INDEX8, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
126 SDL_PIXELFORMAT_RGB332, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
127 SDL_PIXELFORMAT_RGB444, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
128 SDL_PIXELFORMAT_RGB555, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
129 SDL_PIXELFORMAT_ARGB4444, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
130 SDL_PIXELFORMAT_ARGB1555, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
131 SDL_PIXELFORMAT_RGB565, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
132 SDL_PIXELFORMAT_RGB24, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
133 SDL_PIXELFORMAT_BGR24, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
134 SDL_PIXELFORMAT_RGB888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
135 SDL_PIXELFORMAT_BGR888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
136 SDL_PIXELFORMAT_ARGB8888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
137 SDL_PIXELFORMAT_ABGR8888, |
2813
49243a6e9ff1
Removed the hacky stuff for YUV OpenGL textures, since Ryan's pixel shader code
Sam Lantinga <slouken@libsdl.org>
parents:
2812
diff
changeset
|
138 SDL_PIXELFORMAT_ARGB2101010}, |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 0, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 0} |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 }; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 typedef struct |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 SDL_GLContext context; |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
146 SDL_bool updateSize; |
2233
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
147 SDL_bool GL_ARB_texture_rectangle_supported; |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
148 SDL_bool GL_EXT_paletted_texture_supported; |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
149 SDL_bool GL_ARB_fragment_program_supported; |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
150 int blendMode; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
151 int scaleMode; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
152 |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
153 /* OpenGL functions */ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
154 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
155 #include "SDL_glfuncs.h" |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
156 #undef SDL_PROC |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
157 |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
158 PFNGLCOLORTABLEEXTPROC glColorTableEXT; |
2233
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
159 void (*glTextureRangeAPPLE) (GLenum target, GLsizei length, |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
160 const GLvoid * pointer); |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
161 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
162 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
163 PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
164 PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
165 PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
166 PFNGLGENPROGRAMSARBPROC glGenProgramsARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
167 PFNGLBINDPROGRAMARBPROC glBindProgramARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
168 PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
169 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
170 /* (optional) fragment programs */ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
171 GLuint fragment_program_UYVY; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 } GL_RenderData; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 typedef struct |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 GLuint texture; |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
177 GLuint shader; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
178 GLenum type; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 GLfloat texw; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 GLfloat texh; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
181 GLenum format; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
182 GLenum formattype; |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
183 Uint8 *palette; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 void *pixels; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 int pitch; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
186 SDL_DirtyRectList dirty; |
2843
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
187 int HACK_RYAN_FIXME; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 } GL_TextureData; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
191 static void |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
192 GL_SetError(const char *prefix, GLenum result) |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
193 { |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
194 const char *error; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
195 |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
196 switch (result) { |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
197 case GL_NO_ERROR: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
198 error = "GL_NO_ERROR"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
199 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
200 case GL_INVALID_ENUM: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
201 error = "GL_INVALID_ENUM"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
202 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
203 case GL_INVALID_VALUE: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
204 error = "GL_INVALID_VALUE"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
205 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
206 case GL_INVALID_OPERATION: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
207 error = "GL_INVALID_OPERATION"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
208 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
209 case GL_STACK_OVERFLOW: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
210 error = "GL_STACK_OVERFLOW"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
211 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
212 case GL_STACK_UNDERFLOW: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
213 error = "GL_STACK_UNDERFLOW"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
214 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
215 case GL_OUT_OF_MEMORY: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
216 error = "GL_OUT_OF_MEMORY"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
217 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
218 case GL_TABLE_TOO_LARGE: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
219 error = "GL_TABLE_TOO_LARGE"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
220 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
221 default: |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
222 error = "UNKNOWN"; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
223 break; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
224 } |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
225 SDL_SetError("%s: %s", prefix, error); |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
226 } |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
227 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
228 static int |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
229 GL_LoadFunctions(GL_RenderData * data) |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
230 { |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
231 #if defined(__QNXNTO__) && (_NTO_VERSION < 630) |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
232 #define __SDL_NOGETPROCADDR__ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
233 #elif defined(__MINT__) |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
234 #define __SDL_NOGETPROCADDR__ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
235 #endif |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
236 #ifdef __SDL_NOGETPROCADDR__ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
237 #define SDL_PROC(ret,func,params) data->func=func; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
238 #else |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
239 #define SDL_PROC(ret,func,params) \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
240 do { \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
241 data->func = SDL_GL_GetProcAddress(#func); \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
242 if ( ! data->func ) { \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
243 SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
244 return -1; \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
245 } \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
246 } while ( 0 ); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
247 #endif /* __SDL_NOGETPROCADDR__ */ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
248 |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
249 #include "SDL_glfuncs.h" |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
250 #undef SDL_PROC |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
251 return 0; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
252 } |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
253 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 GL_AddRenderDriver(_THIS) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 { |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
257 if (_this->GL_CreateContext) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 SDL_AddRenderDriver(0, &GL_RenderDriver); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 SDL_Renderer * |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 GL_CreateRenderer(SDL_Window * window, Uint32 flags) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 SDL_Renderer *renderer; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 GL_RenderData *data; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
267 GLint value; |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
268 int doublebuffer; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
270 /* Render directly to the window, unless we're compositing */ |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
271 #ifndef __MACOSX__ |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
272 if (flags & SDL_RENDERER_SINGLEBUFFER) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
273 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
274 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
275 #endif |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
1928
861bc36f0ab3
Fixed crash with multiple windows
Sam Lantinga <slouken@libsdl.org>
parents:
1927
diff
changeset
|
277 if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) { |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
278 return NULL; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
279 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
282 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 if (!renderer) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 SDL_OutOfMemory(); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
288 data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 if (!data) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 GL_DestroyRenderer(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 SDL_OutOfMemory(); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
295 renderer->ActivateRenderer = GL_ActivateRenderer; |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
296 renderer->DisplayModeChanged = GL_DisplayModeChanged; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 renderer->CreateTexture = GL_CreateTexture; |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
298 renderer->QueryTexturePixels = GL_QueryTexturePixels; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 renderer->SetTexturePalette = GL_SetTexturePalette; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 renderer->GetTexturePalette = GL_GetTexturePalette; |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
301 renderer->SetTextureColorMod = GL_SetTextureColorMod; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
302 renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
303 renderer->SetTextureBlendMode = GL_SetTextureBlendMode; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
304 renderer->SetTextureScaleMode = GL_SetTextureScaleMode; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 renderer->UpdateTexture = GL_UpdateTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 renderer->LockTexture = GL_LockTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 renderer->UnlockTexture = GL_UnlockTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 renderer->DirtyTexture = GL_DirtyTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 renderer->RenderFill = GL_RenderFill; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 renderer->RenderCopy = GL_RenderCopy; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 renderer->RenderPresent = GL_RenderPresent; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 renderer->DestroyTexture = GL_DestroyTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 renderer->DestroyRenderer = GL_DestroyRenderer; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 renderer->info = GL_RenderDriver.info; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 renderer->window = window->id; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 renderer->driverdata = data; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 renderer->info.flags = |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
319 (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
321 if (GL_LoadFunctions(data) < 0) { |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
322 GL_DestroyRenderer(renderer); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
323 return NULL; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
324 } |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
325 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 data->context = SDL_GL_CreateContext(window->id); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 if (!data->context) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 GL_DestroyRenderer(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 GL_DestroyRenderer(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 } |
2246
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
335 #ifdef __MACOSX__ |
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
336 /* Enable multi-threaded rendering */ |
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
337 /* Disabled until Ryan finishes his VBO/PBO code... |
2295
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
338 CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine); |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
339 */ |
2246
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
340 #endif |
75daa0792bd1
Added code to enable multi-threaded OpenGL on Mac OS X, pending Ryan's PBO/VBO
Sam Lantinga <slouken@libsdl.org>
parents:
2237
diff
changeset
|
341 |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
342 if (flags & SDL_RENDERER_PRESENTVSYNC) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 SDL_GL_SetSwapInterval(1); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 } else { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 SDL_GL_SetSwapInterval(0); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 if (SDL_GL_GetSwapInterval() > 0) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
348 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
351 if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
352 if (!doublebuffer) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
353 renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
354 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
355 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
356 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
357 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
358 renderer->info.max_texture_width = value; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
359 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
360 renderer->info.max_texture_height = value; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
361 |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
362 if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
363 || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
364 data->GL_ARB_texture_rectangle_supported = SDL_TRUE; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
365 } |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
366 if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
367 data->GL_EXT_paletted_texture_supported = SDL_TRUE; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
368 data->glColorTableEXT = |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
369 (PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT"); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
370 } else { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
371 /* Don't advertise support for 8-bit indexed texture format */ |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
372 Uint32 i, j; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
373 SDL_RendererInfo *info = &renderer->info; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
374 for (i = 0, j = 0; i < info->num_texture_formats; ++i) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
375 if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
376 info->texture_formats[j++] = info->texture_formats[i]; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
377 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
378 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
379 --info->num_texture_formats; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
380 } |
2233
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
381 if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) { |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
382 data->glTextureRangeAPPLE = |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
383 (void (*)(GLenum, GLsizei, const GLvoid *)) |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
384 SDL_GL_GetProcAddress("glTextureRangeAPPLE"); |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
385 } |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
386 |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
387 /* we might use fragment programs for YUV data, etc. */ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
388 if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
389 /* !!! FIXME: this doesn't check for errors. */ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
390 /* !!! FIXME: this should really reuse the glfuncs.h stuff. */ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
391 data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
392 SDL_GL_GetProcAddress("glGetProgramivARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
393 data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
394 SDL_GL_GetProcAddress("glGetProgramStringARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
395 data->glProgramLocalParameter4fvARB = |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
396 (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
397 SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
398 data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
399 SDL_GL_GetProcAddress("glDeleteProgramsARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
400 data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
401 SDL_GL_GetProcAddress("glGenProgramsARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
402 data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
403 SDL_GL_GetProcAddress("glBindProgramARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
404 data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
405 SDL_GL_GetProcAddress("glProgramStringARB"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
406 data->GL_ARB_fragment_program_supported = SDL_TRUE; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
407 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
408 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 /* Set up parameters for rendering */ |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
410 data->blendMode = -1; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
411 data->scaleMode = -1; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
412 data->glDisable(GL_DEPTH_TEST); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
413 data->glDisable(GL_CULL_FACE); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
414 if (data->GL_ARB_texture_rectangle_supported) { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
415 data->glEnable(GL_TEXTURE_RECTANGLE_ARB); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
416 } else { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
417 data->glEnable(GL_TEXTURE_2D); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
418 } |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
419 data->updateSize = SDL_TRUE; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 return renderer; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
424 static int |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
425 GL_ActivateRenderer(SDL_Renderer * renderer) |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
426 { |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
427 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
428 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
429 |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
430 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
431 return -1; |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
432 } |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
433 if (data->updateSize) { |
2836
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
434 data->glMatrixMode(GL_PROJECTION); |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
435 data->glLoadIdentity(); |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
436 data->glMatrixMode(GL_MODELVIEW); |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
437 data->glLoadIdentity(); |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
438 data->glViewport(0, 0, window->w, window->h); |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
439 data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
440 0.0, 1.0); |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
441 data->updateSize = SDL_FALSE; |
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
442 } |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
443 return 0; |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
444 } |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
445 |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
446 static int |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
447 GL_DisplayModeChanged(SDL_Renderer * renderer) |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
448 { |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
449 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
450 |
2836
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
451 /* Rebind the context to the window area and update matrices */ |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
452 data->updateSize = SDL_TRUE; |
b128b94ed31e
Rebind the context to the window area and update matrices when the window size changes
Sam Lantinga <slouken@libsdl.org>
parents:
2835
diff
changeset
|
453 return GL_ActivateRenderer(renderer); |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
454 } |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
455 |
1922
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
456 static __inline__ int |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
457 power_of_2(int input) |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
458 { |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
459 int value = 1; |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
460 |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
461 while (value < input) { |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
462 value <<= 1; |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
463 } |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
464 return value; |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
465 } |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
466 |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
467 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
468 #define DEBUG_PROGRAM_COMPILE 1 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
469 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
470 static GLuint |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
471 compile_shader(GL_RenderData *data, GLenum shader_type, const char *source) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
472 { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
473 #if DEBUG_PROGRAM_COMPILE |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
474 printf("compiling shader:\n%s\n\n", source); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
475 #endif |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
476 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
477 GLuint program = 0; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
478 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
479 data->glGetError(); /* flush any existing error state. */ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
480 data->glGenProgramsARB(1, &program); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
481 data->glBindProgramARB(shader_type, program); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
482 data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB, |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
483 SDL_strlen(source), source); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
484 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
485 if (data->glGetError() == GL_INVALID_OPERATION) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
486 { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
487 #if DEBUG_PROGRAM_COMPILE |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
488 GLint pos = 0; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
489 const GLubyte *errstr; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
490 data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
491 errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
492 printf("program compile error at position %d: %s\n\n", |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
493 (int) pos, (const char *) errstr); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
494 #endif |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
495 data->glBindProgramARB(shader_type, 0); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
496 data->glDeleteProgramsARB(1, &program); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
497 return 0; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
498 } // if |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
499 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
500 return program; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
501 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
502 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
503 // UYVY to RGB equasion... |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
504 // R = 1.164(Y-16) + 1.596(Cr-128) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
505 // G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
506 // B = 1.164(Y-16) + 2.018(Cb-128) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
507 // Byte layout is Cb, Y1, Cr, Y2. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
508 // 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
509 // !!! FIXME: this ignores blendmodes, etc. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
510 // !!! FIXME: this could be more efficient...use a dot product for green, not convert to 255.0 range, etc. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
511 static const char *fragment_program_UYVY_source_code = |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
512 "!!ARBfp1.0\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
513 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
514 // outputs... |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
515 "OUTPUT outcolor = result.color;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
516 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
517 // scratch registers... |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
518 "TEMP uyvy;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
519 "TEMP luminance;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
520 "TEMP work;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
521 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
522 // We need 32 bits to store the data, but each pixel is 16 bits in itself. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
523 // halve the coordinates to grab the correct 32 bits for the fragment. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
524 "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
525 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
526 // Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in r,g,b,a. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
527 // !!! FIXME: "RECT" needs to be "2D" if we're not using texture_rectangle extension. :/ |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
528 "TEX uyvy, work, texture[0], RECT;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
529 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
530 // Scale from 0.0/1.0 to 0.0/255.0 and do subtractions. (!!! FIXME: optimize!) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
531 "MUL uyvy, uyvy, { 255.0, 255.0, 255.0, 255.0 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
532 "SUB uyvy, uyvy, { 128.0, 16.0, 128.0, 16.0 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
533 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
534 // Choose the luminance component by texcoord. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
535 // !!! FIXME: laziness wins out for now... just average Y1 and Y2. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
536 "ADD luminance, uyvy.yyyy, uyvy.wwww;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
537 "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
538 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
539 // Multiply luminance by its magic value. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
540 "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
541 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
542 // uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
543 "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
544 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
545 // Add luminance Cr and Cb, store to RGB channels. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
546 "ADD work.rgb, luminance, uyvy;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
547 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
548 // Do final addition for Green channel. (!!! FIXME: this should be a DPH?) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
549 "ADD work.g, work.g, uyvy.w;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
550 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
551 // Scale back to 0.0/1.0. (this number is 1.0/255.0). |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
552 "MUL work, work, { 0.0039215686274509803, 0.0039215686274509803, 0.0039215686274509803, 0.0039215686274509803 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
553 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
554 // Make sure alpha channel is fully opaque. (!!! FIXME: blend modes!) |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
555 "MOV work.a, { 1.0 };\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
556 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
557 // Store out the final fragment color. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
558 "MOV outcolor, work;\n" |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
559 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
560 // ...and we're done. |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
561 "END\n"; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
562 |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
563 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
565 GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
568 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 GL_TextureData *data; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
570 GLint internalFormat; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
571 GLenum format, type; |
1922
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
572 int texture_w, texture_h; |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
573 GLuint shader = 0; |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
574 GLenum result; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
576 switch (texture->format) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
577 case SDL_PIXELFORMAT_INDEX1LSB: |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
578 case SDL_PIXELFORMAT_INDEX1MSB: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
579 internalFormat = GL_RGB; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
580 format = GL_COLOR_INDEX; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
581 type = GL_BITMAP; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
582 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
583 case SDL_PIXELFORMAT_INDEX8: |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
584 if (!renderdata->GL_EXT_paletted_texture_supported) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
585 SDL_SetError("Unsupported texture format"); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
586 return -1; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
587 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
588 internalFormat = GL_COLOR_INDEX8_EXT; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
589 format = GL_COLOR_INDEX; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
590 type = GL_UNSIGNED_BYTE; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
591 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
592 case SDL_PIXELFORMAT_RGB332: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
593 internalFormat = GL_R3_G3_B2; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
594 format = GL_RGB; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
595 type = GL_UNSIGNED_BYTE_3_3_2; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
596 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
597 case SDL_PIXELFORMAT_RGB444: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
598 internalFormat = GL_RGB4; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
599 format = GL_RGB; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
600 type = GL_UNSIGNED_SHORT_4_4_4_4; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
601 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
602 case SDL_PIXELFORMAT_RGB555: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
603 internalFormat = GL_RGB5; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
604 format = GL_RGB; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
605 type = GL_UNSIGNED_SHORT_5_5_5_1; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
606 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
607 case SDL_PIXELFORMAT_ARGB4444: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
608 internalFormat = GL_RGBA4; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
609 format = GL_BGRA; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
610 type = GL_UNSIGNED_SHORT_4_4_4_4_REV; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
611 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
612 case SDL_PIXELFORMAT_ARGB1555: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
613 internalFormat = GL_RGB5_A1; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
614 format = GL_BGRA; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
615 type = GL_UNSIGNED_SHORT_1_5_5_5_REV; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
616 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
617 case SDL_PIXELFORMAT_RGB565: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
618 internalFormat = GL_RGB8; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
619 format = GL_RGB; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
620 type = GL_UNSIGNED_SHORT_5_6_5; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
621 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
622 case SDL_PIXELFORMAT_RGB24: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
623 internalFormat = GL_RGB8; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
624 format = GL_RGB; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
625 type = GL_UNSIGNED_BYTE; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
626 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
627 case SDL_PIXELFORMAT_RGB888: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
628 internalFormat = GL_RGB8; |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
629 format = GL_BGRA; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
630 type = GL_UNSIGNED_BYTE; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
631 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
632 case SDL_PIXELFORMAT_BGR24: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
633 internalFormat = GL_RGB8; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
634 format = GL_BGR; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
635 type = GL_UNSIGNED_BYTE; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
636 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
637 case SDL_PIXELFORMAT_BGR888: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
638 internalFormat = GL_RGB8; |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
639 format = GL_RGBA; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
640 type = GL_UNSIGNED_BYTE; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
641 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
642 case SDL_PIXELFORMAT_ARGB8888: |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
643 #ifdef __MACOSX__ |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
644 internalFormat = GL_RGBA; |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
645 format = GL_BGRA; |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
646 type = GL_UNSIGNED_INT_8_8_8_8_REV; |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
647 #else |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
648 internalFormat = GL_RGBA8; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
649 format = GL_BGRA; |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
650 type = GL_UNSIGNED_BYTE; |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
651 #endif |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
652 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
653 case SDL_PIXELFORMAT_ABGR8888: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
654 internalFormat = GL_RGBA8; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
655 format = GL_RGBA; |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
656 type = GL_UNSIGNED_BYTE; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
657 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
658 case SDL_PIXELFORMAT_ARGB2101010: |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
659 internalFormat = GL_RGB10_A2; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
660 format = GL_BGRA; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
661 type = GL_UNSIGNED_INT_2_10_10_10_REV; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
662 break; |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
663 case SDL_PIXELFORMAT_UYVY: |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
664 if (renderdata->GL_ARB_fragment_program_supported) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
665 if (renderdata->fragment_program_UYVY == 0) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
666 renderdata->fragment_program_UYVY = |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
667 compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB, |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
668 fragment_program_UYVY_source_code); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
669 if (renderdata->fragment_program_UYVY == 0) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
670 SDL_SetError("Fragment program compile error"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
671 return -1; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
672 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
673 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
674 shader = renderdata->fragment_program_UYVY; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
675 internalFormat = GL_RGBA; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
676 format = GL_RGBA; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
677 type = GL_UNSIGNED_BYTE; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
678 } else { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
679 SDL_SetError("Unsupported texture format"); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
680 return -1; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
681 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
682 break; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
683 default: |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
684 SDL_SetError("Unsupported texture format"); |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
685 return -1; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
686 } |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
687 |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
688 data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
689 if (!data) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
690 SDL_OutOfMemory(); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 return -1; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
693 |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
694 data->shader = shader; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
695 |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
696 if (texture->format == SDL_PIXELFORMAT_INDEX8) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
697 data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8)); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
698 if (!data->palette) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
699 SDL_OutOfMemory(); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
700 SDL_free(data); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
701 return -1; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
702 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
703 SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8)); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
704 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
705 |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
706 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
707 data->pitch = texture->w * bytes_per_pixel(texture->format); |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
708 data->pixels = SDL_malloc(texture->h * data->pitch); |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
709 if (!data->pixels) { |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
710 SDL_OutOfMemory(); |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
711 SDL_free(data); |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
712 return -1; |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
713 } |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
714 } |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
715 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
716 texture->driverdata = data; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
717 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
718 renderdata->glGetError(); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
719 renderdata->glGenTextures(1, &data->texture); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
720 if (renderdata->GL_ARB_texture_rectangle_supported) { |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
721 data->type = GL_TEXTURE_RECTANGLE_ARB; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
722 texture_w = texture->w; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
723 texture_h = texture->h; |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
724 data->texw = (GLfloat) texture_w; |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
725 data->texh = (GLfloat) texture_h; |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
726 } else { |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
727 data->type = GL_TEXTURE_2D; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
728 texture_w = power_of_2(texture->w); |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
729 texture_h = power_of_2(texture->h); |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
730 data->texw = (GLfloat) (texture->w) / texture_w; |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
731 data->texh = (GLfloat) texture->h / texture_h; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
732 } |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
733 |
2839 | 734 /* YUV formats use RGBA but are really two bytes per pixel */ |
735 if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) { | |
2843
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
736 data->HACK_RYAN_FIXME = 2; |
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
737 } else { |
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
738 data->HACK_RYAN_FIXME = 1; |
2839 | 739 } |
2843
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
740 texture_w /= data->HACK_RYAN_FIXME; |
2839 | 741 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
742 data->format = format; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
743 data->formattype = type; |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
744 renderdata->glBindTexture(data->type, data->texture); |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
745 renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
746 GL_NEAREST); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
747 renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
748 GL_NEAREST); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
749 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
750 GL_CLAMP_TO_EDGE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
751 renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
752 GL_CLAMP_TO_EDGE); |
2840
53ca0d758b0a
The previous checkin fixes the crash, so at least we're not overrunning
Sam Lantinga <slouken@libsdl.org>
parents:
2839
diff
changeset
|
753 #ifdef __MACOSX__ |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
754 #ifndef GL_TEXTURE_STORAGE_HINT_APPLE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
755 #define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
756 #endif |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
757 #ifndef STORAGE_CACHED_APPLE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
758 #define STORAGE_CACHED_APPLE 0x85BE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
759 #endif |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
760 #ifndef STORAGE_SHARED_APPLE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
761 #define STORAGE_SHARED_APPLE 0x85BF |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
762 #endif |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
763 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
764 renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
765 GL_STORAGE_SHARED_APPLE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
766 } else { |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
767 renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
768 GL_STORAGE_CACHED_APPLE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
769 } |
2809
7e257c3a3bf0
Temporary fix for Mac OS X crash in textoverlay
Sam Lantinga <slouken@libsdl.org>
parents:
2808
diff
changeset
|
770 /* This causes a crash in testoverlay for some reason. Apple bug? */ |
7e257c3a3bf0
Temporary fix for Mac OS X crash in textoverlay
Sam Lantinga <slouken@libsdl.org>
parents:
2808
diff
changeset
|
771 #if 0 |
2295
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
772 if (texture->access == SDL_TEXTUREACCESS_STREAMING |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
773 && texture->format == SDL_PIXELFORMAT_ARGB8888) { |
2237
e57a883ffa86
Advertise the most efficient format for the screen. Of course SDL code needs
Sam Lantinga <slouken@libsdl.org>
parents:
2236
diff
changeset
|
774 /* |
2295
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
775 if (renderdata->glTextureRangeAPPLE) { |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
776 renderdata->glTextureRangeAPPLE(data->type, |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
777 texture->h * data->pitch, |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
778 data->pixels); |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
779 } |
dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents:
2275
diff
changeset
|
780 */ |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
781 renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
782 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
783 texture_h, 0, format, type, data->pixels); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
784 } else |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
785 #endif |
2809
7e257c3a3bf0
Temporary fix for Mac OS X crash in textoverlay
Sam Lantinga <slouken@libsdl.org>
parents:
2808
diff
changeset
|
786 #endif |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
787 { |
2840
53ca0d758b0a
The previous checkin fixes the crash, so at least we're not overrunning
Sam Lantinga <slouken@libsdl.org>
parents:
2839
diff
changeset
|
788 printf("teximage2d(%d,%d)\n", (int) texture_w, (int) texture_h); |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
789 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
790 texture_h, 0, format, type, NULL); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
791 } |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
792 result = renderdata->glGetError(); |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
793 if (result != GL_NO_ERROR) { |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
794 GL_SetError("glTexImage2D()", result); |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
795 return -1; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
796 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
797 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
798 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
799 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
800 static int |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
801 GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
802 void **pixels, int *pitch) |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
803 { |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
804 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
805 |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
806 *pixels = data->pixels; |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
807 *pitch = data->pitch; |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
808 return 0; |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
809 } |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
810 |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
811 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
812 GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
813 const SDL_Color * colors, int firstcolor, int ncolors) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
814 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
815 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
816 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
817 Uint8 *palette; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
818 |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
819 if (!data->palette) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
820 SDL_SetError("Texture doesn't have a palette"); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
821 return -1; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
822 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
823 palette = data->palette + firstcolor * 3; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
824 while (ncolors--) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
825 *palette++ = colors->r; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
826 *palette++ = colors->g; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
827 *palette++ = colors->b; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
828 ++colors; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
829 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
830 renderdata->glBindTexture(data->type, data->texture); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
831 renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB, |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
832 GL_UNSIGNED_BYTE, data->palette); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
833 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
834 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
835 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
836 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
837 GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
838 SDL_Color * colors, int firstcolor, int ncolors) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
839 { |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
840 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
841 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
842 Uint8 *palette; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
843 |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
844 if (!data->palette) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
845 SDL_SetError("Texture doesn't have a palette"); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
846 return -1; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
847 } |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
848 palette = data->palette + firstcolor * 3; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
849 while (ncolors--) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
850 colors->r = *palette++; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
851 colors->g = *palette++; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
852 colors->b = *palette++; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
853 colors->unused = SDL_ALPHA_OPAQUE; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
854 ++colors; |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
855 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
856 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
857 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
858 |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
859 static void |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
860 SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
861 int pitch) |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
862 { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
863 if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
864 renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1); |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
865 } else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
866 renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0); |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
867 } |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
868 renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
2808
368410632f2d
Whoops, we need this for subrect updates (testsprite)
Sam Lantinga <slouken@libsdl.org>
parents:
2804
diff
changeset
|
869 renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, |
2843
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
870 (pitch / bytes_per_pixel(texture->format) / ((GL_TextureData *)texture->driverdata)->HACK_RYAN_FIXME)); |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
871 } |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
872 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
873 static int |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
874 GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
875 { |
1986
f4c65e3bfaed
Cleanup for the last checkin
Sam Lantinga <slouken@libsdl.org>
parents:
1985
diff
changeset
|
876 return 0; |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
877 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
878 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
879 static int |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
880 GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
881 { |
1986
f4c65e3bfaed
Cleanup for the last checkin
Sam Lantinga <slouken@libsdl.org>
parents:
1985
diff
changeset
|
882 return 0; |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
883 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
884 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
885 static int |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
886 GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
887 { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
888 switch (texture->blendMode) { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
889 case SDL_TEXTUREBLENDMODE_NONE: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
890 case SDL_TEXTUREBLENDMODE_MASK: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
891 case SDL_TEXTUREBLENDMODE_BLEND: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
892 case SDL_TEXTUREBLENDMODE_ADD: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
893 case SDL_TEXTUREBLENDMODE_MOD: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
894 return 0; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
895 default: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
896 SDL_Unsupported(); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
897 texture->blendMode = SDL_TEXTUREBLENDMODE_NONE; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
898 return -1; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
899 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
900 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
901 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
902 static int |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
903 GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
904 { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
905 switch (texture->scaleMode) { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
906 case SDL_TEXTURESCALEMODE_NONE: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
907 case SDL_TEXTURESCALEMODE_FAST: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
908 case SDL_TEXTURESCALEMODE_SLOW: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
909 return 0; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
910 case SDL_TEXTURESCALEMODE_BEST: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
911 SDL_Unsupported(); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
912 texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
913 return -1; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
914 default: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
915 SDL_Unsupported(); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
916 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
917 return -1; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
918 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
919 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
920 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
921 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
922 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
923 const SDL_Rect * rect, const void *pixels, int pitch) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
924 { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
925 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
926 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
927 GLenum result; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
928 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
929 renderdata->glGetError(); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
930 SetupTextureUpdate(renderdata, texture, pitch); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
931 renderdata->glBindTexture(data->type, data->texture); |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
932 printf("texsubimage2d(%d,%d,%d,%d)\n", (int) rect->x, (int) rect->y, (int) rect->w, (int) rect->h); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
933 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
934 rect->h, data->format, data->formattype, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
935 pixels); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
936 result = renderdata->glGetError(); |
1924
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
937 if (result != GL_NO_ERROR) { |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
938 GL_SetError("glTexSubImage2D()", result); |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
939 return -1; |
69217fdd2c0a
If the OpenGL renderer is selected for a non-OpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset
|
940 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
941 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
942 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
943 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
944 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
945 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
946 const SDL_Rect * rect, int markDirty, void **pixels, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
947 int *pitch) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
948 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
949 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
950 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
951 if (markDirty) { |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
952 SDL_AddDirtyRect(&data->dirty, rect); |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
953 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
954 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
955 *pixels = |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
956 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
957 rect->x * bytes_per_pixel(texture->format)); |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
958 *pitch = data->pitch; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
959 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
960 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
961 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
962 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
963 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
964 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
965 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
966 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
967 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
968 GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
969 const SDL_Rect * rects) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
970 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
971 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
972 int i; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
973 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
974 for (i = 0; i < numrects; ++i) { |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
975 SDL_AddDirtyRect(&data->dirty, &rects[i]); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
976 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
977 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
978 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
979 static int |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
980 GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
981 const SDL_Rect * rect) |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
982 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
983 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
984 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
985 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
986 data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
987 (GLclampf) b * inv255f, (GLclampf) a * inv255f); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
988 data->glViewport(rect->x, window->h - rect->y, rect->w, rect->h); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
989 data->glClear(GL_COLOR_BUFFER_BIT); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
990 data->glViewport(0, 0, window->w, window->h); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
991 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
992 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
993 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
994 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
995 GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
996 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
997 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
998 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
999 GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1000 int minx, miny, maxx, maxy; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1001 GLfloat minu, maxu, minv, maxv; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1002 |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2246
diff
changeset
|
1003 if (texturedata->dirty.list) { |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1004 SDL_DirtyRect *dirty; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1005 void *pixels; |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1006 int bpp = bytes_per_pixel(texture->format); |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1007 int pitch = texturedata->pitch; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1008 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1009 SetupTextureUpdate(data, texture, pitch); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1010 data->glBindTexture(texturedata->type, texturedata->texture); |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1011 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1012 SDL_Rect *rect = &dirty->rect; |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1013 pixels = |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1014 (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch + |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1015 rect->x * bpp); |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1016 printf("texsubimage2d(%d,%d,%d,%d)\n", (int) rect->x, (int) rect->y, (int) rect->w, (int) rect->h); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1017 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y, |
2843
e919f2e3700d
Fixed the shader fragment problems using 2 byte YUV data in a 4 byte RGB
Sam Lantinga <slouken@libsdl.org>
parents:
2840
diff
changeset
|
1018 rect->w / texturedata->HACK_RYAN_FIXME, rect->h, texturedata->format, |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1019 texturedata->formattype, pixels); |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1020 } |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1021 SDL_ClearDirtyRects(&texturedata->dirty); |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1022 } |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1023 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1024 minx = dstrect->x; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1025 miny = dstrect->y; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1026 maxx = dstrect->x + dstrect->w; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1027 maxy = dstrect->y + dstrect->h; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1028 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1029 minu = (GLfloat) srcrect->x / texture->w; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1030 minu *= texturedata->texw; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1031 maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1032 maxu *= texturedata->texw; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1033 minv = (GLfloat) srcrect->y / texture->h; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1034 minv *= texturedata->texh; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1035 maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1036 maxv *= texturedata->texh; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1037 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1038 data->glBindTexture(texturedata->type, texturedata->texture); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1039 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1040 if (texture->modMode) { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1041 data->glColor4f((GLfloat) texture->r * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1042 (GLfloat) texture->g * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1043 (GLfloat) texture->b * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1044 (GLfloat) texture->a * inv255f); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1045 } else { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1046 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1047 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1048 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1049 if (texture->blendMode != data->blendMode) { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1050 switch (texture->blendMode) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1051 case SDL_TEXTUREBLENDMODE_NONE: |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1052 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1053 data->glDisable(GL_BLEND); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1054 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1055 case SDL_TEXTUREBLENDMODE_MASK: |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1056 case SDL_TEXTUREBLENDMODE_BLEND: |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1057 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1058 data->glEnable(GL_BLEND); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1059 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1060 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1061 case SDL_TEXTUREBLENDMODE_ADD: |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1062 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1063 data->glEnable(GL_BLEND); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1064 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1065 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1066 case SDL_TEXTUREBLENDMODE_MOD: |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1067 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1068 data->glEnable(GL_BLEND); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1069 data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1070 break; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1071 } |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1072 data->blendMode = texture->blendMode; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1073 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1074 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1075 if (texture->scaleMode != data->scaleMode) { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1076 switch (texture->scaleMode) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1077 case SDL_TEXTURESCALEMODE_NONE: |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1078 case SDL_TEXTURESCALEMODE_FAST: |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1079 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1080 GL_NEAREST); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1081 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1082 GL_NEAREST); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1083 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1084 case SDL_TEXTURESCALEMODE_SLOW: |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
1085 case SDL_TEXTURESCALEMODE_BEST: |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1086 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1087 GL_LINEAR); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1088 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1089 GL_LINEAR); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1090 break; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1091 } |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
1092 data->scaleMode = texture->scaleMode; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1093 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1094 |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1095 if (texturedata->shader != 0) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1096 data->glEnable(GL_FRAGMENT_PROGRAM_ARB); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1097 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, texturedata->shader); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1098 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1099 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1100 data->glBegin(GL_TRIANGLE_STRIP); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1101 data->glTexCoord2f(minu, minv); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1102 data->glVertex2i(minx, miny); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1103 data->glTexCoord2f(maxu, minv); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1104 data->glVertex2i(maxx, miny); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1105 data->glTexCoord2f(minu, maxv); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1106 data->glVertex2i(minx, maxy); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1107 data->glTexCoord2f(maxu, maxv); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1108 data->glVertex2i(maxx, maxy); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1109 data->glEnd(); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1110 |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1111 if (texturedata->shader != 0) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1112 data->glDisable(GL_FRAGMENT_PROGRAM_ARB); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1113 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1114 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1115 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1116 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1117 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1118 GL_RenderPresent(SDL_Renderer * renderer) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1119 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1120 SDL_GL_SwapWindow(renderer->window); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1121 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1122 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1123 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1124 GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1125 { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1126 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1127 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1128 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1129 if (!data) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1130 return; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1131 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1132 if (data->texture) { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
1133 renderdata->glDeleteTextures(1, &data->texture); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1134 } |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
1135 if (data->palette) { |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
1136 SDL_free(data->palette); |
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
1137 } |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1138 if (data->pixels) { |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1139 SDL_free(data->pixels); |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1140 } |
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1141 SDL_FreeDirtyRects(&data->dirty); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1142 SDL_free(data); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1143 texture->driverdata = NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1144 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1145 |
1975
ccef0d0c40c6
Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents:
1974
diff
changeset
|
1146 static void |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1147 GL_DestroyRenderer(SDL_Renderer * renderer) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1148 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1149 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1150 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1151 if (data) { |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1152 if (data->context) { |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1153 if (data->GL_ARB_fragment_program_supported) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1154 data->glDisable(GL_FRAGMENT_PROGRAM_ARB); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1155 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1156 if (data->fragment_program_UYVY != 0) { |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1157 data->glDeleteProgramsARB(1, &data->fragment_program_UYVY); |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1158 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1159 } |
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
1160 |
2328
91e601d9df8b
re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
1161 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
1162 SDL_GL_DeleteContext(data->context); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1163 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1164 SDL_free(data); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1165 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1166 SDL_free(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1167 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1168 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
1169 #endif /* SDL_VIDEO_RENDER_OGL */ |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1170 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1171 /* vi: set ts=4 sw=4 expandtab: */ |