annotate src/video/SDL_renderer_gl.c @ 5153:1435f8a6425c

Nobody is currently maintaining the QNX code, so removing it for now.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Feb 2011 21:40:03 -0800
parents be02be2ea897
children
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
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
1918
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
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
48 if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
49 return SDL_BYTESPERPIXEL(format);
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
50 }
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
51
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
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) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
54 case SDL_PIXELFORMAT_YV12:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
55 case SDL_PIXELFORMAT_IYUV:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
56 case SDL_PIXELFORMAT_YUY2:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
57 case SDL_PIXELFORMAT_UYVY:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
58 case SDL_PIXELFORMAT_YVYU:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
59 return 2;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
60 default:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
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);
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
69 static void GL_WindowEvent(SDL_Renderer * renderer,
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
70 const SDL_WindowEvent *event);
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_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 const SDL_Rect * rect, const void *pixels,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 int pitch);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 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
79 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
80 int *pitch);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 int numrects, const SDL_Rect * rects);
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
84 static int GL_RenderClear(SDL_Renderer * renderer);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
85 static int GL_RenderDrawPoints(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
86 const SDL_Point * points, int count);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
87 static int GL_RenderDrawLines(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
88 const SDL_Point * points, int count);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
89 static int GL_RenderFillRects(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
90 const SDL_Rect ** rects, int count);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 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
92 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
93 static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
94 Uint32 pixel_format, void * pixels, int pitch);
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
95 static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
96 Uint32 pixel_format, const void * pixels, int pitch);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 static void GL_RenderPresent(SDL_Renderer * renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 static void GL_DestroyRenderer(SDL_Renderer * renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 SDL_RenderDriver GL_RenderDriver = {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 GL_CreateRenderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 "opengl",
5145
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5144
diff changeset
106 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
5152
be02be2ea897 Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents: 5151
diff changeset
107 13,
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
109 SDL_PIXELFORMAT_RGB332,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
110 SDL_PIXELFORMAT_RGB444,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
111 SDL_PIXELFORMAT_RGB555,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
112 SDL_PIXELFORMAT_ARGB4444,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
113 SDL_PIXELFORMAT_ARGB1555,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
114 SDL_PIXELFORMAT_RGB565,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
115 SDL_PIXELFORMAT_RGB24,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
116 SDL_PIXELFORMAT_BGR24,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
117 SDL_PIXELFORMAT_RGB888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
118 SDL_PIXELFORMAT_BGR888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
119 SDL_PIXELFORMAT_ARGB8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
120 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
121 SDL_PIXELFORMAT_ARGB2101010},
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 0,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 0}
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 };
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 typedef struct
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 SDL_GLContext context;
2833
c2e182a37f5f Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents: 2832
diff changeset
129 SDL_bool updateSize;
2233
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
130 SDL_bool GL_ARB_texture_rectangle_supported;
1974
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
131 SDL_bool GL_EXT_paletted_texture_supported;
2845
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
132 SDL_bool GL_APPLE_ycbcr_422_supported;
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
133 SDL_bool GL_MESA_ycbcr_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
134 SDL_bool GL_ARB_fragment_program_supported;
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
135 int blendMode;
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
136
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
137 /* OpenGL functions */
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
138 #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
139 #include "SDL_glfuncs.h"
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
140 #undef SDL_PROC
1974
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
141
2233
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
142 void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
143 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
144
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
145 PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
146 PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
147 PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
148 PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
149 PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
150 PFNGLBINDPROGRAMARBPROC glBindProgramARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
151 PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
152
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
153 /* (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
154 GLuint fragment_program_UYVY;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 } GL_RenderData;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 typedef struct
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 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
160 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
161 GLenum type;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 GLfloat texw;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 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
164 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
165 GLenum formattype;
1974
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
166 Uint8 *palette;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 void *pixels;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 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
169 SDL_DirtyRectList dirty;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
170 int HACK_RYAN_FIXME;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 } GL_TextureData;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
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
174 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
175 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
176 {
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
177 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
178
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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 }
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 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
209 }
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
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
211 static int
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
212 GL_LoadFunctions(GL_RenderData * data)
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
213 {
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
214 #ifdef __SDL_NOGETPROCADDR__
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
215 #define SDL_PROC(ret,func,params) data->func=func;
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
216 #else
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
217 #define SDL_PROC(ret,func,params) \
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
218 do { \
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
219 data->func = SDL_GL_GetProcAddress(#func); \
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
220 if ( ! data->func ) { \
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
221 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
222 return -1; \
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
223 } \
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
224 } while ( 0 );
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
225 #endif /* __SDL_NOGETPROCADDR__ */
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
226
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
227 #include "SDL_glfuncs.h"
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
228 #undef SDL_PROC
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
229 return 0;
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
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 SDL_Renderer *
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 GL_CreateRenderer(SDL_Window * window, Uint32 flags)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 SDL_Renderer *renderer;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 GL_RenderData *data;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1928
diff changeset
237 GLint value;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
1974
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
239 /* Render directly to the window, unless we're compositing */
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
240 #ifndef __MACOSX__
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
241 if (flags & SDL_RENDERER_SINGLEBUFFER) {
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
242 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
243 }
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
244 #endif
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 if (!(window->flags & SDL_WINDOW_OPENGL)) {
1928
861bc36f0ab3 Fixed crash with multiple windows
Sam Lantinga <slouken@libsdl.org>
parents: 1927
diff changeset
246 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
247 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
248 }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250
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
251 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 if (!renderer) {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 SDL_OutOfMemory();
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 return NULL;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 }
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 data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 if (!data) {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 GL_DestroyRenderer(renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 SDL_OutOfMemory();
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 return NULL;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
264 renderer->WindowEvent = GL_WindowEvent;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 renderer->CreateTexture = GL_CreateTexture;
2222
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
266 renderer->QueryTexturePixels = GL_QueryTexturePixels;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 renderer->UpdateTexture = GL_UpdateTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 renderer->LockTexture = GL_LockTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 renderer->UnlockTexture = GL_UnlockTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 renderer->DirtyTexture = GL_DirtyTexture;
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
271 renderer->RenderClear = GL_RenderClear;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
272 renderer->RenderDrawPoints = GL_RenderDrawPoints;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
273 renderer->RenderDrawLines = GL_RenderDrawLines;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
274 renderer->RenderFillRects = GL_RenderFillRects;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 renderer->RenderCopy = GL_RenderCopy;
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
276 renderer->RenderReadPixels = GL_RenderReadPixels;
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
277 renderer->RenderWritePixels = GL_RenderWritePixels;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 renderer->RenderPresent = GL_RenderPresent;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 renderer->DestroyTexture = GL_DestroyTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 renderer->DestroyRenderer = GL_DestroyRenderer;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 renderer->info = GL_RenderDriver.info;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3607
diff changeset
282 renderer->window = window;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 renderer->driverdata = data;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284
5145
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5144
diff changeset
285 renderer->info.flags = SDL_RENDERER_ACCELERATED;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
287 if (GL_LoadFunctions(data) < 0) {
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
288 GL_DestroyRenderer(renderer);
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
289 return NULL;
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
290 }
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
291
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3607
diff changeset
292 data->context = SDL_GL_CreateContext(window);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 if (!data->context) {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 GL_DestroyRenderer(renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 return NULL;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3607
diff changeset
297 if (SDL_GL_MakeCurrent(window, data->context) < 0) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 GL_DestroyRenderer(renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 return NULL;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 }
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
301 #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
302 /* 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
303 /* 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
304 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
305 */
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
306 #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
307
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
308 if (flags & SDL_RENDERER_PRESENTVSYNC) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 SDL_GL_SetSwapInterval(1);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 } else {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 SDL_GL_SetSwapInterval(0);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 if (SDL_GL_GetSwapInterval() > 0) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
314 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1928
diff changeset
317 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1928
diff changeset
318 renderer->info.max_texture_width = value;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1928
diff changeset
319 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1928
diff changeset
320 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
321
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
322 if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
323 || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
324 data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
325 }
2845
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
326 if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
327 data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
328 }
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
329 if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
330 data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
1cc5d5b164e2 Added official support for GL_APPLE_ycbcr_422 and GL_MESA_ycbcr_texture
Sam Lantinga <slouken@libsdl.org>
parents: 2844
diff changeset
331 }
2233
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
332 if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
333 data->glTextureRangeAPPLE =
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
334 (void (*)(GLenum, GLsizei, const GLvoid *))
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
335 SDL_GL_GetProcAddress("glTextureRangeAPPLE");
fb01ee9716bc Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents: 2230
diff changeset
336 }
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
337
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
338 /* 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
339 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
340 /* !!! 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
341 /* !!! 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
342 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
343 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
344 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
345 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
346 data->glProgramLocalParameter4fvARB =
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
347 (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 }
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
359
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 /* Set up parameters for rendering */
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
361 data->blendMode = -1;
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
362 data->glDisable(GL_DEPTH_TEST);
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
363 data->glDisable(GL_CULL_FACE);
3262
e3d33bd599eb Stefan Ullinger
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
364 /* This ended up causing video discrepancies between OpenGL and Direct3D */
e3d33bd599eb Stefan Ullinger
Sam Lantinga <slouken@libsdl.org>
parents: 3253
diff changeset
365 /*data->glEnable(GL_LINE_SMOOTH);*/
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
366 if (data->GL_ARB_texture_rectangle_supported) {
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
367 data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
368 } else {
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
369 data->glEnable(GL_TEXTURE_2D);
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
370 }
2833
c2e182a37f5f Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents: 2832
diff changeset
371 data->updateSize = SDL_TRUE;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 return renderer;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
376 static SDL_GLContext SDL_CurrentContext = NULL;
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
377
1923
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
378 static int
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
379 GL_ActivateRenderer(SDL_Renderer * renderer)
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
380 {
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
381 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3607
diff changeset
382 SDL_Window *window = renderer->window;
1923
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
383
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
384 if (SDL_CurrentContext != data->context) {
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
385 if (SDL_GL_MakeCurrent(window, data->context) < 0) {
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
386 return -1;
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
387 }
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
388 SDL_CurrentContext = data->context;
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
389 }
2833
c2e182a37f5f Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents: 2832
diff changeset
390 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
391 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
392 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
393 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
394 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
395 data->glViewport(0, 0, window->w, window->h);
3324
0f19b2fa4125 -0.5 is causing trouble according to comments in bug #783
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
396 data->glOrtho(0.0, (GLdouble) window->w,
0f19b2fa4125 -0.5 is causing trouble according to comments in bug #783
Sam Lantinga <slouken@libsdl.org>
parents: 3283
diff changeset
397 (GLdouble) window->h, 0.0, 0.0, 1.0);
2833
c2e182a37f5f Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents: 2832
diff changeset
398 data->updateSize = SDL_FALSE;
c2e182a37f5f Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents: 2832
diff changeset
399 }
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
400 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
401 }
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
402
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
403 static void
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
404 GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
405 {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
406 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
407
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
408 if (event->event == SDL_WINDOWEVENT_RESIZED) {
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
409 /* Rebind the context to the window area and update matrices */
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
410 SDL_CurrentContext = NULL;
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
411 data->updateSize = SDL_TRUE;
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
412 }
1923
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
413 }
d4572b97b08f Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents: 1922
diff changeset
414
1922
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
415 static __inline__ int
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
416 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
417 {
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
418 int value = 1;
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
419
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
420 while (value < input) {
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
421 value <<= 1;
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
422 }
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
423 return value;
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
424 }
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
425
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
426
2858
a38fcb093081 A little cleanup for SDL snapshot release
Sam Lantinga <slouken@libsdl.org>
parents: 2848
diff changeset
427 //#define DEBUG_PROGRAM_COMPILE 1
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
428
3468
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
429 static void
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
430 set_shader_error(GL_RenderData * data, const char *prefix)
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
431 {
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
432 GLint pos = 0;
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
433 const GLubyte *errstr;
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
434 data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
435 errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
3479
6f887204fa7a Whoops, actually set the SDL error, don't just print the error.
Sam Lantinga <slouken@libsdl.org>
parents: 3475
diff changeset
436 SDL_SetError("%s: shader compile error at position %d: %s",
3468
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
437 prefix, (int) pos, (const char *) errstr);
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
438 }
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
439
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
440 static GLuint
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
441 compile_shader(GL_RenderData * data, GLenum shader_type, const char *_code)
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
442 {
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
443 const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
444 const char *replacement = have_texture_rects ? "RECT" : "2D";
2918
bd518fc76f28 Updated to build on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
445 const size_t replacementlen = SDL_strlen(replacement);
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
446 const char *token = "%TEXTURETARGET%";
2918
bd518fc76f28 Updated to build on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
447 const size_t tokenlen = SDL_strlen(token);
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
448 char *code = NULL;
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
449 char *ptr = NULL;
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
450 GLuint program = 0;
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
451
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
452 /*
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
453 * The TEX instruction needs a different target depending on what we use.
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
454 * To handle this, we use "%TEXTURETARGET%" and replace the string before
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
455 * compiling the shader.
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
456 */
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
457 code = SDL_strdup(_code);
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
458 if (code == NULL)
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
459 return 0;
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
460
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
461 for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr + 1, token)) {
2918
bd518fc76f28 Updated to build on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
462 SDL_memcpy(ptr, replacement, replacementlen);
bd518fc76f28 Updated to build on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
463 SDL_memmove(ptr + replacementlen, ptr + tokenlen,
bd518fc76f28 Updated to build on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
464 SDL_strlen(ptr + tokenlen) + 1);
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
465 }
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
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 #if DEBUG_PROGRAM_COMPILE
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
468 printf("compiling shader:\n%s\n\n", code);
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
469 #endif
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
470
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
471 data->glGetError(); /* flush any existing error state. */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
472 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
473 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
474 data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
3253
5d7ef5970073 Fixed issues building 64-bit Windows binary
Sam Lantinga <slouken@libsdl.org>
parents: 3041
diff changeset
475 (GLsizei)SDL_strlen(code), code);
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
476
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
477 SDL_free(code);
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
478
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
479 if (data->glGetError() == GL_INVALID_OPERATION) {
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
480 #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
481 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
482 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
483 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
484 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
485 printf("program compile error at position %d: %s\n\n",
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
486 (int) pos, (const char *) errstr);
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
487 #endif
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
488 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
489 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
490 return 0;
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
491 }
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
492
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
493 return program;
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
494 }
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
495
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
496
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
497 /*
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
498 * Fragment program that renders from UYVY textures.
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
499 * The UYVY to RGB equasion is:
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
500 * R = 1.164(Y-16) + 1.596(Cr-128)
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
501 * G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
502 * B = 1.164(Y-16) + 2.018(Cb-128)
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
503 * Byte layout is Cb, Y1, Cr, Y2, stored in the R, G, B, A channels.
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
504 * 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
505 *
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
506 * !!! FIXME: this ignores blendmodes, etc.
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
507 * !!! FIXME: this could be more efficient...use a dot product for green, etc.
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
508 */
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
509 static const char *fragment_program_UYVY_source_code = "!!ARBfp1.0\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
510 /* outputs... */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
511 "OUTPUT outcolor = result.color;\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
512 /* scratch registers... */
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
513 "TEMP uyvy;\n" "TEMP luminance;\n" "TEMP work;\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
514 /* Halve the coordinates to grab the correct 32 bits for the fragment. */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
515 "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
516 /* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
2847
7d020441fa81 Don't hardcode RECT for fragment program texture targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 2846
diff changeset
517 "TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
518 /* Do subtractions (128/255, 16/255, 128/255, 16/255) */
2846
3d7833d5a4be Slight optimization of the shader, no need to scale into 0..255
Sam Lantinga <slouken@libsdl.org>
parents: 2845
diff changeset
519 "SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
520 /* Choose the luminance component by texcoord. */
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
521 /* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
522 "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
523 "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
524 /* Multiply luminance by its magic value. */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
525 "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
526 /* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
527 "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
528 /* Add luminance to Cr and Cb, store to RGB channels. */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
529 "ADD work.rgb, luminance, uyvy;\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
530 /* Do final addition for Green channel. (!!! FIXME: this should be a DPH?) */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
531 "ADD work.g, work.g, uyvy.w;\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
532 /* Make sure alpha channel is fully opaque. (!!! FIXME: blend modes!) */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
533 "MOV work.a, { 1.0 };\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
534 /* Store out the final fragment color... */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
535 "MOV outcolor, work;\n"
2848
8a3aa505ecba Comment cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 2847
diff changeset
536 /* ...and we're done! */
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
537 "END\n";
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
538
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
539 static __inline__ SDL_bool
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
540 convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
541 GLint* internalFormat, GLenum* format, GLenum* type)
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
542 {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
543 switch (pixel_format) {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
544 case SDL_PIXELFORMAT_RGB332:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
545 *internalFormat = GL_R3_G3_B2;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
546 *format = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
547 *type = GL_UNSIGNED_BYTE_3_3_2;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
548 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
549 case SDL_PIXELFORMAT_RGB444:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
550 *internalFormat = GL_RGB4;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
551 *format = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
552 *type = GL_UNSIGNED_SHORT_4_4_4_4;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
553 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
554 case SDL_PIXELFORMAT_RGB555:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
555 *internalFormat = GL_RGB5;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
556 *format = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
557 *type = GL_UNSIGNED_SHORT_5_5_5_1;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
558 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
559 case SDL_PIXELFORMAT_ARGB4444:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
560 *internalFormat = GL_RGBA4;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
561 *format = GL_BGRA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
562 *type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
563 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
564 case SDL_PIXELFORMAT_ARGB1555:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
565 *internalFormat = GL_RGB5_A1;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
566 *format = GL_BGRA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
567 *type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
568 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
569 case SDL_PIXELFORMAT_RGB565:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
570 *internalFormat = GL_RGB8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
571 *format = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
572 *type = GL_UNSIGNED_SHORT_5_6_5;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
573 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
574 case SDL_PIXELFORMAT_RGB24:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
575 *internalFormat = GL_RGB8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
576 *format = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
577 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
578 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
579 case SDL_PIXELFORMAT_RGB888:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
580 *internalFormat = GL_RGB8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
581 *format = GL_BGRA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
582 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
583 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
584 case SDL_PIXELFORMAT_BGR24:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
585 *internalFormat = GL_RGB8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
586 *format = GL_BGR;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
587 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
588 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
589 case SDL_PIXELFORMAT_BGR888:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
590 *internalFormat = GL_RGB8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
591 *format = GL_RGBA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
592 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
593 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
594 case SDL_PIXELFORMAT_ARGB8888:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
595 #ifdef __MACOSX__
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
596 *internalFormat = GL_RGBA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
597 *format = GL_BGRA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
598 *type = GL_UNSIGNED_INT_8_8_8_8_REV;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
599 #else
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
600 *internalFormat = GL_RGBA8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
601 *format = GL_BGRA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
602 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
603 #endif
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
604 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
605 case SDL_PIXELFORMAT_ABGR8888:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
606 *internalFormat = GL_RGBA8;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
607 *format = GL_RGBA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
608 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
609 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
610 case SDL_PIXELFORMAT_ARGB2101010:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
611 *internalFormat = GL_RGB10_A2;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
612 *format = GL_BGRA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
613 *type = GL_UNSIGNED_INT_2_10_10_10_REV;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
614 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
615 case SDL_PIXELFORMAT_UYVY:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
616 if (renderdata->GL_APPLE_ycbcr_422_supported) {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
617 *internalFormat = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
618 *format = GL_YCBCR_422_APPLE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
619 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
620 *type = GL_UNSIGNED_SHORT_8_8_APPLE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
621 #else
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
622 *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
623 #endif
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
624 } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
3494
61d95a87c327 Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3479
diff changeset
625 *internalFormat = GL_YCBCR_MESA;
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
626 *format = GL_YCBCR_MESA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
627 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
628 *type = GL_UNSIGNED_SHORT_8_8_MESA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
629 #else
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
630 *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
631 #endif
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
632 } else if (renderdata->GL_ARB_fragment_program_supported) {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
633 *internalFormat = GL_RGBA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
634 *format = GL_RGBA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
635 *type = GL_UNSIGNED_BYTE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
636 } else {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
637 return SDL_FALSE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
638 }
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
639 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
640 case SDL_PIXELFORMAT_YUY2:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
641 if (renderdata->GL_APPLE_ycbcr_422_supported) {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
642 *internalFormat = GL_RGB;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
643 *format = GL_YCBCR_422_APPLE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
644 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
645 *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
646 #else
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
647 *type = GL_UNSIGNED_SHORT_8_8_APPLE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
648 #endif
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
649 } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
3494
61d95a87c327 Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3479
diff changeset
650 *internalFormat = GL_YCBCR_MESA;
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
651 *format = GL_YCBCR_MESA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
652 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
653 *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
654 #else
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
655 *type = GL_UNSIGNED_SHORT_8_8_MESA;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
656 #endif
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
657 } else {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
658 return SDL_FALSE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
659 }
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
660 break;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
661 default:
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
662 return SDL_FALSE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
663 }
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
664 return SDL_TRUE;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
665 }
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
666
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 static int
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
668 GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 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
672 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
673 GLenum format, type;
1922
4905cac7a4bd Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents: 1921
diff changeset
674 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
675 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
676 GLenum result;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
678 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
679
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
680 if (!convert_format(renderdata, texture->format, &internalFormat,
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
681 &format, &type)) {
4990
397e748d901a Improved error message for unsupported texture format
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
682 SDL_SetError("Texture format %s not supported by OpenGL",
397e748d901a Improved error message for unsupported texture format
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
683 SDL_GetPixelFormatName(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
684 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
685 }
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
686 if (texture->format == SDL_PIXELFORMAT_UYVY &&
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
687 !renderdata->GL_APPLE_ycbcr_422_supported &&
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
688 !renderdata->GL_MESA_ycbcr_texture_supported &&
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
689 renderdata->GL_ARB_fragment_program_supported) {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
690 if (renderdata->fragment_program_UYVY == 0) {
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
691 renderdata->fragment_program_UYVY =
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
692 compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
693 fragment_program_UYVY_source_code);
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
694 if (renderdata->fragment_program_UYVY == 0) {
3468
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
695 set_shader_error(renderdata, "UYVY");
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
696 return -1;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
697 }
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
698 }
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
699 shader = renderdata->fragment_program_UYVY;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
700 }
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
701
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
702 data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
703 if (!data) {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704 SDL_OutOfMemory();
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
705 return -1;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
706 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
707
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
708 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
709
2222
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
710 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
711 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
712 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
713 if (!data->pixels) {
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
714 SDL_OutOfMemory();
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
715 SDL_free(data);
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
716 return -1;
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
717 }
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
718 }
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
719
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
720 texture->driverdata = data;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
721
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
722 renderdata->glGetError();
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
723 renderdata->glGenTextures(1, &data->texture);
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
724 if (renderdata->GL_ARB_texture_rectangle_supported) {
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
725 data->type = GL_TEXTURE_RECTANGLE_ARB;
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
726 texture_w = texture->w;
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
727 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
728 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
729 data->texh = (GLfloat) texture_h;
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
730 } else {
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
731 data->type = GL_TEXTURE_2D;
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
732 texture_w = power_of_2(texture->w);
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
733 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
734 data->texw = (GLfloat) (texture->w) / texture_w;
1926
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
735 data->texh = (GLfloat) texture->h / texture_h;
307355678142 Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
736 }
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
737
2839
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
738 /* YUV formats use RGBA but are really two bytes per pixel */
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
739 if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
3707
d8308bc267bc Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
740 texture_w /= 2;
d8308bc267bc Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
741 if (data->type == GL_TEXTURE_2D) {
d8308bc267bc Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
742 data->texw *= 2.0f;
d8308bc267bc Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
743 }
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
744 data->HACK_RYAN_FIXME = 2;
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
745 } else {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
746 data->HACK_RYAN_FIXME = 1;
2839
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
747 }
f89700cc9272 Progress, maybe. :)
Sam Lantinga <slouken@libsdl.org>
parents: 2836
diff changeset
748
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
749 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
750 data->formattype = type;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
751 renderdata->glEnable(data->type);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
752 renderdata->glBindTexture(data->type, data->texture);
2230
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
753 renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
5141
da10636e5eca Making the API simpler, scaling is always defined as linear interpolation and should be supported as much as possible on all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5088
diff changeset
754 GL_LINEAR);
2230
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
755 renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
5141
da10636e5eca Making the API simpler, scaling is always defined as linear interpolation and should be supported as much as possible on all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5088
diff changeset
756 GL_LINEAR);
2230
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
757 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
758 GL_CLAMP_TO_EDGE);
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
759 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
760 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
761 #ifdef __MACOSX__
2230
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
762 #ifndef GL_TEXTURE_STORAGE_HINT_APPLE
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
763 #define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
764 #endif
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
765 #ifndef STORAGE_CACHED_APPLE
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
766 #define STORAGE_CACHED_APPLE 0x85BE
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
767 #endif
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
768 #ifndef STORAGE_SHARED_APPLE
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
769 #define STORAGE_SHARED_APPLE 0x85BF
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
770 #endif
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
771 if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
772 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
773 GL_STORAGE_SHARED_APPLE);
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
774 } else {
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
775 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
776 GL_STORAGE_CACHED_APPLE);
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
777 }
2809
7e257c3a3bf0 Temporary fix for Mac OS X crash in textoverlay
Sam Lantinga <slouken@libsdl.org>
parents: 2808
diff changeset
778 /* 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
779 #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
780 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
781 && 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
782 /*
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
783 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
784 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
785 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
786 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
787 }
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
788 */
2230
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
789 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
790 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
791 texture_h, 0, format, type, data->pixels);
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
792 } else
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
793 #endif
2809
7e257c3a3bf0 Temporary fix for Mac OS X crash in textoverlay
Sam Lantinga <slouken@libsdl.org>
parents: 2808
diff changeset
794 #endif
2230
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
795 {
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
796 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
797 texture_h, 0, format, type, NULL);
9b7d29d2432b Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
798 }
3041
20d65430e63c Fixed OpenGL state issue reported by Dmytro Bogovych
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
799 renderdata->glDisable(data->type);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
800 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
801 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
802 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
803 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
804 }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
805 return 0;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
806 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 static int
2222
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
809 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
810 void **pixels, int *pitch)
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
811 {
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
812 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
813
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
814 *pixels = data->pixels;
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
815 *pitch = data->pitch;
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
816 return 0;
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
817 }
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1986
diff changeset
818
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
819 static void
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
820 SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
821 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
822 {
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
823 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
824 renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
825 (pitch / bytes_per_pixel(texture->format)) /
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
826 ((GL_TextureData *) texture->driverdata)->
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
827 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
828 }
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
829
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
830 static int
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
832 const SDL_Rect * rect, const void *pixels, int pitch)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
833 {
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
834 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
835 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
836 GLenum result;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
837
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
838 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
839
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
840 renderdata->glGetError();
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
841 SetupTextureUpdate(renderdata, texture, pitch);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
842 renderdata->glEnable(data->type);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
843 renderdata->glBindTexture(data->type, data->texture);
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
844 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
845 rect->h, data->format, data->formattype,
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
846 pixels);
3041
20d65430e63c Fixed OpenGL state issue reported by Dmytro Bogovych
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
847 renderdata->glDisable(data->type);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
848 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
849 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
850 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
851 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
852 }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
853 return 0;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
854 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
855
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
856 static int
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
857 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
858 const SDL_Rect * rect, int markDirty, void **pixels,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
859 int *pitch)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
860 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
861 GL_TextureData *data = (GL_TextureData *) texture->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
862
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
863 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
864 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
865 }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
866
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
867 *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
868 (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
869 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
870 *pitch = data->pitch;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
871 return 0;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
872 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
873
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
874 static void
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
875 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
876 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
877 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
878
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
879 static void
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
880 GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
881 const SDL_Rect * rects)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
882 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
883 GL_TextureData *data = (GL_TextureData *) texture->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
884 int i;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
885
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
886 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
887 SDL_AddDirtyRect(&data->dirty, &rects[i]);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
888 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
889 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
890
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
891 static void
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
892 GL_SetBlendMode(GL_RenderData * data, int blendMode)
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
893 {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
894 if (blendMode != data->blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
895 switch (blendMode) {
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
896 case SDL_BLENDMODE_NONE:
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
897 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
898 data->glDisable(GL_BLEND);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
899 break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
900 case SDL_BLENDMODE_BLEND:
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
901 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
902 data->glEnable(GL_BLEND);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
903 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
904 break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
905 case SDL_BLENDMODE_ADD:
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
906 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
907 data->glEnable(GL_BLEND);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
908 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
909 break;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
910 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
911 data->blendMode = blendMode;
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
912 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
913 }
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
914
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
915 static int
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
916 GL_RenderClear(SDL_Renderer * renderer)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
917 {
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
918 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
919
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
920 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
921
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
922 data->glClearColor((GLfloat) renderer->r * inv255f,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
923 (GLfloat) renderer->g * inv255f,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
924 (GLfloat) renderer->b * inv255f,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
925 (GLfloat) renderer->a * inv255f);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
926
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
927 data->glClear(GL_COLOR_BUFFER_BIT);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
928
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
929 return 0;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
930 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
931
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
932 static int
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
933 GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
934 int count)
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
935 {
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
936 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
937 int i;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
938
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
939 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
940
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
941 GL_SetBlendMode(data, renderer->blendMode);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
942
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
943 data->glColor4f((GLfloat) renderer->r * inv255f,
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
944 (GLfloat) renderer->g * inv255f,
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
945 (GLfloat) renderer->b * inv255f,
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
946 (GLfloat) renderer->a * inv255f);
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
947
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
948 data->glBegin(GL_POINTS);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
949 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
950 data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
951 }
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
952 data->glEnd();
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
953
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
954 return 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
955 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
956
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
957 static int
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
958 GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
959 int count)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
960 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
961 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
962 int i;
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
963
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
964 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
965
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
966 GL_SetBlendMode(data, renderer->blendMode);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
967
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
968 data->glColor4f((GLfloat) renderer->r * inv255f,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
969 (GLfloat) renderer->g * inv255f,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
970 (GLfloat) renderer->b * inv255f,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
971 (GLfloat) renderer->a * inv255f);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2893
diff changeset
972
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
973 if (count > 2 &&
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
974 points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
975 data->glBegin(GL_LINE_LOOP);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
976 /* GL_LINE_LOOP takes care of the final segment */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
977 --count;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
978 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
979 data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
980 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
981 data->glEnd();
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
982 } else {
5088
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
983 #if defined(__APPLE__) || defined(__WIN32__)
4910
f205711f73d5 Fix and rename VS2010 project files, add tests to VS2010 solution, fix VS compiler warning
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4905
diff changeset
984 #else
4905
9779093454d2 This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents: 4455
diff changeset
985 int x1, y1, x2, y2;
4910
f205711f73d5 Fix and rename VS2010 project files, add tests to VS2010 solution, fix VS compiler warning
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4905
diff changeset
986 #endif
4905
9779093454d2 This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents: 4455
diff changeset
987
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
988 data->glBegin(GL_LINE_STRIP);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
989 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
990 data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
991 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
992 data->glEnd();
3474
1edb86163d62 Of COURSE that trick wouldn't work on all renderers. Fall back to something for now, hopefully figure out a better way to do this later.
Sam Lantinga <slouken@libsdl.org>
parents: 3473
diff changeset
993
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
994 /* The line is half open, so we need one more point to complete it.
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
995 * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
996 * If we have to, we can use vertical line and horizontal line textures
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
997 * for vertical and horizontal lines, and then create custom textures
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
998 * for diagonal lines and software render those. It's terrible, but at
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
999 * least it would be pixel perfect.
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1000 */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1001 data->glBegin(GL_POINTS);
5088
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
1002 #if defined(__APPLE__) || defined(__WIN32__)
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1003 /* Mac OS X and Windows seem to always leave the second point open */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1004 data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
3474
1edb86163d62 Of COURSE that trick wouldn't work on all renderers. Fall back to something for now, hopefully figure out a better way to do this later.
Sam Lantinga <slouken@libsdl.org>
parents: 3473
diff changeset
1005 #else
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1006 /* Linux seems to leave the right-most or bottom-most point open */
4905
9779093454d2 This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents: 4455
diff changeset
1007 x1 = points[0].x;
9779093454d2 This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents: 4455
diff changeset
1008 y1 = points[0].y;
9779093454d2 This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents: 4455
diff changeset
1009 x2 = points[count-1].x;
9779093454d2 This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents: 4455
diff changeset
1010 y2 = points[count-1].y;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1011
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1012 if (x1 > x2) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1013 data->glVertex2f(0.5f + x1, 0.5f + y1);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1014 } else if (x2 > x1) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1015 data->glVertex2f(0.5f + x2, 0.5f + y2);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1016 } else if (y1 > y2) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1017 data->glVertex2f(0.5f + x1, 0.5f + y1);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1018 } else if (y2 > y1) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1019 data->glVertex2f(0.5f + x2, 0.5f + y2);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1020 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1021 #endif
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1022 data->glEnd();
3474
1edb86163d62 Of COURSE that trick wouldn't work on all renderers. Fall back to something for now, hopefully figure out a better way to do this later.
Sam Lantinga <slouken@libsdl.org>
parents: 3473
diff changeset
1023 }
3455
5a7b5760c875 Include the endpoint in the line we're drawing
Sam Lantinga <slouken@libsdl.org>
parents: 3454
diff changeset
1024
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1025 return 0;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1026 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1027
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1028 static int
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
1029 GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
2925
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1030 {
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1031 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1032 int i;
2925
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1033
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1034 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1035
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
1036 GL_SetBlendMode(data, renderer->blendMode);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
1037
2925
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1038 data->glColor4f((GLfloat) renderer->r * inv255f,
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1039 (GLfloat) renderer->g * inv255f,
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1040 (GLfloat) renderer->b * inv255f,
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1041 (GLfloat) renderer->a * inv255f);
2936
066384910f50 iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
1042
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1043 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1044 const SDL_Rect *rect = rects[i];
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1045
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1046 data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3533
diff changeset
1047 }
2925
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1048
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1049 return 0;
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1050 }
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1051
7e21f7662208 Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents: 2922
diff changeset
1052 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1053 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
1054 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1055 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1056 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1057 GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1058 int minx, miny, maxx, maxy;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1059 GLfloat minu, maxu, minv, maxv;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1060
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1061 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1062
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2246
diff changeset
1063 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
1064 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
1065 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
1066 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
1067 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
1068
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1069 SetupTextureUpdate(data, texture, pitch);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1070 data->glEnable(texturedata->type);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1071 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
1072 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
1073 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
1074 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
1075 (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
1076 rect->x * bpp);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1077 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1078 rect->w / texturedata->HACK_RYAN_FIXME,
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1079 rect->h, texturedata->format,
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1080 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
1081 }
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
1082 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
1083 }
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
1084
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1085 minx = dstrect->x;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1086 miny = dstrect->y;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1087 maxx = dstrect->x + dstrect->w;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1088 maxy = dstrect->y + dstrect->h;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1089
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1090 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
1091 minu *= texturedata->texw;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1092 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
1093 maxu *= texturedata->texw;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1094 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
1095 minv *= texturedata->texh;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1096 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
1097 maxv *= texturedata->texh;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1098
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1099 data->glEnable(texturedata->type);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1100 data->glBindTexture(texturedata->type, texturedata->texture);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1101
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1102 if (texture->modMode) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1103 data->glColor4f((GLfloat) texture->r * inv255f,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1104 (GLfloat) texture->g * inv255f,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1105 (GLfloat) texture->b * inv255f,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1106 (GLfloat) texture->a * inv255f);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1107 } else {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1108 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
1109 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
1110
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
1111 GL_SetBlendMode(data, texture->blendMode);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1112
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
1113 /* Set up the shader for the copy, if any */
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
1114 if (texturedata->shader) {
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1115 data->glEnable(GL_FRAGMENT_PROGRAM_ARB);
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
1116 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, texturedata->shader);
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1117 }
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1118
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1119 data->glBegin(GL_TRIANGLE_STRIP);
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1120 data->glTexCoord2f(minu, minv);
3472
fdd2f2e9cd97 Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents: 3470
diff changeset
1121 data->glVertex2f((GLfloat) minx, (GLfloat) miny);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1122 data->glTexCoord2f(maxu, minv);
3472
fdd2f2e9cd97 Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents: 3470
diff changeset
1123 data->glVertex2f((GLfloat) maxx, (GLfloat) miny);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1124 data->glTexCoord2f(minu, maxv);
3472
fdd2f2e9cd97 Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents: 3470
diff changeset
1125 data->glVertex2f((GLfloat) minx, (GLfloat) maxy);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1126 data->glTexCoord2f(maxu, maxv);
3472
fdd2f2e9cd97 Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents: 3470
diff changeset
1127 data->glVertex2f((GLfloat) maxx, (GLfloat) maxy);
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1128 data->glEnd();
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1129
5143
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
1130 if (texturedata->shader) {
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1131 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
1132 }
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1133
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1134 data->glDisable(texturedata->type);
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1135
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1136 return 0;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1137 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1138
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1139 static int
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1140 GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1141 Uint32 pixel_format, void * pixels, int pitch)
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1142 {
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1143 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3607
diff changeset
1144 SDL_Window *window = renderer->window;
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1145 GLint internalFormat;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1146 GLenum format, type;
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1147 Uint8 *src, *dst, *tmp;
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1148 int length, rows;
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1149
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1150 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1151
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1152 if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1153 /* FIXME: Do a temp copy to a format that is supported */
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1154 SDL_SetError("Unsupported pixel format");
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1155 return -1;
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1156 }
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1157
3446
0f969d273f65 First pass (untested) at RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3443
diff changeset
1158 data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
0f969d273f65 First pass (untested) at RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3443
diff changeset
1159 data->glPixelStorei(GL_PACK_ROW_LENGTH,
0f969d273f65 First pass (untested) at RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3443
diff changeset
1160 (pitch / bytes_per_pixel(pixel_format)));
3433
ad845d9835aa Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents: 3431
diff changeset
1161
3447
294b770c1989 Fixed GL_RenderReadPixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3446
diff changeset
1162 data->glReadPixels(rect->x, (window->h-rect->y)-rect->h, rect->w, rect->h,
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1163 format, type, pixels);
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1164
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1165 /* Flip the rows to be top-down */
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1166 length = rect->w * bytes_per_pixel(pixel_format);
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1167 src = (Uint8*)pixels + (rect->h-1)*pitch;
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1168 dst = (Uint8*)pixels;
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1169 tmp = SDL_stack_alloc(Uint8, length);
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1170 rows = rect->h / 2;
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1171 while (rows--) {
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1172 SDL_memcpy(tmp, dst, length);
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1173 SDL_memcpy(dst, src, length);
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1174 SDL_memcpy(src, tmp, length);
3447
294b770c1989 Fixed GL_RenderReadPixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3446
diff changeset
1175 dst += pitch;
294b770c1989 Fixed GL_RenderReadPixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3446
diff changeset
1176 src -= pitch;
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1177 }
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1178 SDL_stack_free(tmp);
3440
e9502d56ae94 Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents: 3435
diff changeset
1179
e9502d56ae94 Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents: 3435
diff changeset
1180 return 0;
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1181 }
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1182
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1183 static int
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1184 GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1185 Uint32 pixel_format, const void * pixels, int pitch)
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1186 {
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1187 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3607
diff changeset
1188 SDL_Window *window = renderer->window;
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1189 GLint internalFormat;
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1190 GLenum format, type;
3607
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1191 Uint8 *src, *dst, *tmp;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1192 int length, rows;
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1193
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1194 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1195
3435
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1196 if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1197 /* FIXME: Do a temp copy to a format that is supported */
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1198 SDL_SetError("Unsupported pixel format");
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1199 return -1;
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1200 }
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1201
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1202 data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1203 data->glPixelStorei(GL_UNPACK_ROW_LENGTH,
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1204 (pitch / bytes_per_pixel(pixel_format)));
9f62f47d989b You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3433
diff changeset
1205
3607
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1206 /* Flip the rows to be bottom-up */
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1207 length = rect->h * rect->w * pitch;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1208 tmp = SDL_stack_alloc(Uint8, length);
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1209 src = (Uint8*)pixels + (rect->h-1)*pitch;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1210 dst = (Uint8*)tmp;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1211 rows = rect->h;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1212 while (rows--) {
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1213 SDL_memcpy(dst, src, pitch);
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1214 dst += pitch;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1215 src -= pitch;
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1216 }
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1217
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1218 data->glRasterPos2i(rect->x, (window->h-rect->y));
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1219 data->glDrawPixels(rect->w, rect->h, format, type, tmp);
8b4c0320638e Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
1220 SDL_stack_free(tmp);
3440
e9502d56ae94 Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents: 3435
diff changeset
1221
e9502d56ae94 Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents: 3435
diff changeset
1222 return 0;
3431
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1223 }
c8fbb27627d9 Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents: 3393
diff changeset
1224
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1225 static void
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1226 GL_RenderPresent(SDL_Renderer * renderer)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1227 {
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1228 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1229
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1230 SDL_GL_SwapWindow(renderer->window);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1231 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1232
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1233 static void
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1234 GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1235 {
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1236 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1237 GL_TextureData *data = (GL_TextureData *) texture->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1238
5150
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1239 GL_ActivateRenderer(renderer);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5145
diff changeset
1240
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1241 if (!data) {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1242 return;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1243 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1244 if (data->texture) {
1927
aeb8263d377a OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
1245 renderdata->glDeleteTextures(1, &data->texture);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1246 }
1974
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
1247 if (data->palette) {
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
1248 SDL_free(data->palette);
70deaf574153 Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
1249 }
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
1250 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
1251 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
1252 }
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
1253 SDL_FreeDirtyRects(&data->dirty);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1254 SDL_free(data);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1255 texture->driverdata = NULL;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1256 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1257
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1974
diff changeset
1258 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1259 GL_DestroyRenderer(SDL_Renderer * renderer)
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1260 {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1261 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1262
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1263 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
1264 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
1265 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
1266 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
1267 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
3468
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
1268 if (data->fragment_program_UYVY &&
789b97008d8a My first OpenGL shader! Momma will be so proud!
Sam Lantinga <slouken@libsdl.org>
parents: 3458
diff changeset
1269 data->fragment_program_UYVY != ~0) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1270 data->glDeleteProgramsARB(1,
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2858
diff changeset
1271 &data->fragment_program_UYVY);
2835
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1272 }
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1273 }
f38257b5d936 Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 2833
diff changeset
1274
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
1275 /* 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
1276 SDL_GL_DeleteContext(data->context);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1277 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1278 SDL_free(data);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1279 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1280 SDL_free(renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1281 }
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1282
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1928
diff changeset
1283 #endif /* SDL_VIDEO_RENDER_OGL */
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1284
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1285 /* vi: set ts=4 sw=4 expandtab: */