Mercurial > sdl-ios-xcode
annotate src/render/opengl/SDL_renderer_gl.c @ 5159:307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
This allows me to reduce the set of formats supported by the renderers to the most optimal set, for a nice speed boost.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 03 Feb 2011 00:19:40 -0800 |
parents | fb424691cfc7 |
children | 657543cc92f9 |
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 | 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_opengl.h" |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
27 #include "../SDL_sysrender.h" |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
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
|
29 #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
|
30 #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
|
31 #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
|
32 |
2778
38dfc890ee6b
Preliminary support for YUV textures
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
33 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 /* OpenGL renderer implementation */ |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
36 /* 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
|
37 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
|
38 */ |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
39 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
40 /* Used to re-create the window with OpenGL capability */ |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
41 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
42 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
43 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
|
44 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 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
|
46 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
|
47 const SDL_WindowEvent *event); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 const SDL_Rect * rect, const void *pixels, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 int pitch); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
53 const SDL_Rect * rect, void **pixels, int *pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 const SDL_Rect ** rects, int count); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 Uint32 pixel_format, const void * pixels, int pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 static void GL_RenderPresent(SDL_Renderer * renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 static void GL_DestroyRenderer(SDL_Renderer * renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 SDL_RenderDriver GL_RenderDriver = { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 GL_CreateRenderer, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 "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
|
77 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
78 1, |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
79 {SDL_PIXELFORMAT_ARGB8888}, |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 0, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 0} |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 }; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 typedef struct |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 SDL_GLContext context; |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
87 SDL_bool updateSize; |
2233
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
88 SDL_bool GL_ARB_texture_rectangle_supported; |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
89 int blendMode; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
90 |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
91 /* OpenGL functions */ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
92 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
93 #include "../../video/SDL_glfuncs.h" |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
94 #undef SDL_PROC |
1974
70deaf574153
Added paletted OpenGL texture support.
Sam Lantinga <slouken@libsdl.org>
parents:
1970
diff
changeset
|
95 |
2233
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
96 void (*glTextureRangeAPPLE) (GLenum target, GLsizei length, |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
97 const GLvoid * pointer); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 } GL_RenderData; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 typedef struct |
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 GLuint 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
|
103 GLenum type; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 GLfloat texw; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 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
|
106 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
|
107 GLenum formattype; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 void *pixels; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 int pitch; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 } GL_TextureData; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
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
|
113 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
|
114 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
|
115 { |
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
|
116 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
|
117 |
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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 } |
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
|
147 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
|
148 } |
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
|
149 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
150 static int |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
151 GL_LoadFunctions(GL_RenderData * data) |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
152 { |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
153 #ifdef __SDL_NOGETPROCADDR__ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
154 #define SDL_PROC(ret,func,params) data->func=func; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
155 #else |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
156 #define SDL_PROC(ret,func,params) \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
157 do { \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
158 data->func = SDL_GL_GetProcAddress(#func); \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
159 if ( ! data->func ) { \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
160 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
|
161 return -1; \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
162 } \ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
163 } while ( 0 ); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
164 #endif /* __SDL_NOGETPROCADDR__ */ |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
165 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
166 #include "../../video/SDL_glfuncs.h" |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
167 #undef SDL_PROC |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
168 return 0; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
169 } |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
170 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 SDL_Renderer * |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 GL_CreateRenderer(SDL_Window * window, Uint32 flags) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 SDL_Renderer *renderer; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 GL_RenderData *data; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
176 GLint value; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
177 Uint32 window_flags; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
179 window_flags = SDL_GetWindowFlags(window); |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
180 if (!(window_flags & SDL_WINDOW_OPENGL)) { |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
181 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
|
182 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
|
183 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset
|
186 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 if (!renderer) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 SDL_OutOfMemory(); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 |
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
|
192 data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 if (!data) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 GL_DestroyRenderer(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 SDL_OutOfMemory(); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 |
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
|
199 renderer->WindowEvent = GL_WindowEvent; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 renderer->CreateTexture = GL_CreateTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 renderer->UpdateTexture = GL_UpdateTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 renderer->LockTexture = GL_LockTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 renderer->UnlockTexture = GL_UnlockTexture; |
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
|
204 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
|
205 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
|
206 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
|
207 renderer->RenderFillRects = GL_RenderFillRects; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 renderer->RenderCopy = GL_RenderCopy; |
3431
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
209 renderer->RenderReadPixels = GL_RenderReadPixels; |
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
210 renderer->RenderWritePixels = GL_RenderWritePixels; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 renderer->RenderPresent = GL_RenderPresent; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 renderer->DestroyTexture = GL_DestroyTexture; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 renderer->DestroyRenderer = GL_DestroyRenderer; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 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
|
215 renderer->window = window; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 renderer->driverdata = data; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 |
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
|
218 renderer->info.flags = SDL_RENDERER_ACCELERATED; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
220 if (GL_LoadFunctions(data) < 0) { |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
221 GL_DestroyRenderer(renderer); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
222 return NULL; |
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 |
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
|
225 data->context = SDL_GL_CreateContext(window); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 if (!data->context) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 GL_DestroyRenderer(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 } |
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
|
230 if (SDL_GL_MakeCurrent(window, data->context) < 0) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 GL_DestroyRenderer(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 return NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 } |
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
|
234 #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
|
235 /* 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
|
236 /* 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
|
237 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
|
238 */ |
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
|
239 #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
|
240 |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
241 if (flags & SDL_RENDERER_PRESENTVSYNC) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 SDL_GL_SetSwapInterval(1); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 } else { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 SDL_GL_SetSwapInterval(0); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 if (SDL_GL_GetSwapInterval() > 0) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1952
diff
changeset
|
247 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
250 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
251 renderer->info.max_texture_width = value; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
252 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
253 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
|
254 |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
255 if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
256 || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
257 data->GL_ARB_texture_rectangle_supported = SDL_TRUE; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
258 } |
2233
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
259 if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) { |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
260 data->glTextureRangeAPPLE = |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
261 (void (*)(GLenum, GLsizei, const GLvoid *)) |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
262 SDL_GL_GetProcAddress("glTextureRangeAPPLE"); |
fb01ee9716bc
Test using glTextureRangeAPPLE
Sam Lantinga <slouken@libsdl.org>
parents:
2230
diff
changeset
|
263 } |
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
|
264 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 /* Set up parameters for rendering */ |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
266 data->blendMode = -1; |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
267 data->glDisable(GL_DEPTH_TEST); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
268 data->glDisable(GL_CULL_FACE); |
3262 | 269 /* This ended up causing video discrepancies between OpenGL and Direct3D */ |
270 /*data->glEnable(GL_LINE_SMOOTH);*/ | |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
271 if (data->GL_ARB_texture_rectangle_supported) { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
272 data->glEnable(GL_TEXTURE_RECTANGLE_ARB); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
273 } else { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
274 data->glEnable(GL_TEXTURE_2D); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
275 } |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
276 data->updateSize = SDL_TRUE; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 return renderer; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
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
|
281 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
|
282 |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
283 static int |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
284 GL_ActivateRenderer(SDL_Renderer * renderer) |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
285 { |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
286 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
|
287 SDL_Window *window = renderer->window; |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
288 |
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
|
289 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
|
290 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
|
291 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
|
292 } |
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
|
293 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
|
294 } |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
295 if (data->updateSize) { |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
296 int w, h; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
297 |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
298 SDL_GetWindowSize(window, &w, &h); |
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
|
299 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
|
300 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
|
301 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
|
302 data->glLoadIdentity(); |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
303 data->glViewport(0, 0, w, h); |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
304 data->glOrtho(0.0, (GLdouble) w, (GLdouble) h, 0.0, 0.0, 1.0); |
2833
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
305 data->updateSize = SDL_FALSE; |
c2e182a37f5f
Whoops, can't call glOrtho() repeatedly
Sam Lantinga <slouken@libsdl.org>
parents:
2832
diff
changeset
|
306 } |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
307 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
|
308 } |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
309 |
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
|
310 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
|
311 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
|
312 { |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
313 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
|
314 |
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
|
315 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
|
316 /* 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
|
317 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
|
318 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
|
319 } |
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
320 } |
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset
|
321 |
1922
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
322 static __inline__ int |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
323 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
|
324 { |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
325 int value = 1; |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
326 |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
327 while (value < input) { |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
328 value <<= 1; |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
329 } |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
330 return value; |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
331 } |
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
332 |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
333 static __inline__ SDL_bool |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
334 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
|
335 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
|
336 { |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
337 switch (pixel_format) { |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
338 case SDL_PIXELFORMAT_RGB888: |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
339 case SDL_PIXELFORMAT_ARGB8888: |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
340 *internalFormat = GL_RGBA8; |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
341 *format = GL_BGRA; |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
342 *type = GL_UNSIGNED_INT_8_8_8_8_REV; |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
343 break; |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
344 default: |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
345 return SDL_FALSE; |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
346 } |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
347 return SDL_TRUE; |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
348 } |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
349 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 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
|
355 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
|
356 GLenum format, type; |
1922
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset
|
357 int texture_w, texture_h; |
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
|
358 GLenum result; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 |
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
|
360 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
|
361 |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
362 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
|
363 &format, &type)) { |
4990
397e748d901a
Improved error message for unsupported texture format
Sam Lantinga <slouken@libsdl.org>
parents:
4929
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 } |
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
|
368 |
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
|
369 data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 if (!data) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 SDL_OutOfMemory(); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 return -1; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
375 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
376 data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
377 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
|
378 if (!data->pixels) { |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
379 SDL_OutOfMemory(); |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
380 SDL_free(data); |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
381 return -1; |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
382 } |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
383 } |
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
1986
diff
changeset
|
384 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 texture->driverdata = data; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
387 renderdata->glGetError(); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
388 renderdata->glGenTextures(1, &data->texture); |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
389 if (renderdata->GL_ARB_texture_rectangle_supported) { |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
390 data->type = GL_TEXTURE_RECTANGLE_ARB; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
391 texture_w = texture->w; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
392 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
|
393 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
|
394 data->texh = (GLfloat) texture_h; |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
395 } else { |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
396 data->type = GL_TEXTURE_2D; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
397 texture_w = power_of_2(texture->w); |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
398 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
|
399 data->texw = (GLfloat) (texture->w) / texture_w; |
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
400 data->texh = (GLfloat) texture->h / texture_h; |
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset
|
401 } |
2835
f38257b5d936
Initial pixel shader support for YUV textures in the GL renderer.
Ryan C. Gordon <icculus@icculus.org>
parents:
2833
diff
changeset
|
402 |
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
|
403 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
|
404 data->formattype = type; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
405 renderdata->glEnable(data->type); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
406 renderdata->glBindTexture(data->type, data->texture); |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
407 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
|
408 GL_LINEAR); |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
409 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
|
410 GL_LINEAR); |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
411 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
|
412 GL_CLAMP_TO_EDGE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
413 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
|
414 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
|
415 #ifdef __MACOSX__ |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
416 #ifndef GL_TEXTURE_STORAGE_HINT_APPLE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
417 #define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
418 #endif |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
419 #ifndef STORAGE_CACHED_APPLE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
420 #define STORAGE_CACHED_APPLE 0x85BE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
421 #endif |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
422 #ifndef STORAGE_SHARED_APPLE |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
423 #define STORAGE_SHARED_APPLE 0x85BF |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
424 #endif |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
425 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
426 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
|
427 GL_STORAGE_SHARED_APPLE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
428 } else { |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
429 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
|
430 GL_STORAGE_CACHED_APPLE); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
431 } |
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
|
432 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
|
433 && texture->format == SDL_PIXELFORMAT_ARGB8888) { |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
434 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
|
435 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
|
436 texture_h, 0, format, type, data->pixels); |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
437 } |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
438 else |
2809
7e257c3a3bf0
Temporary fix for Mac OS X crash in textoverlay
Sam Lantinga <slouken@libsdl.org>
parents:
2808
diff
changeset
|
439 #endif |
2230
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
440 { |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
441 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
|
442 texture_h, 0, format, type, NULL); |
9b7d29d2432b
Optimized OpenGL renderer for Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
443 } |
3041
20d65430e63c
Fixed OpenGL state issue reported by Dmytro Bogovych
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
444 renderdata->glDisable(data->type); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
445 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
|
446 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
|
447 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
|
448 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
|
449 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 |
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
|
453 static void |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
454 SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
455 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
|
456 { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
457 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
|
458 renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
459 (pitch / SDL_BYTESPERPIXEL(texture->format))); |
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
|
460 } |
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
|
461 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 const SDL_Rect * rect, const void *pixels, int pitch) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
466 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 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
|
468 GLenum result; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 |
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
|
470 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
|
471 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
472 renderdata->glGetError(); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
473 SetupTextureUpdate(renderdata, texture, pitch); |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
474 renderdata->glEnable(data->type); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
475 renderdata->glBindTexture(data->type, data->texture); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
476 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
|
477 rect->h, data->format, data->formattype, |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
478 pixels); |
3041
20d65430e63c
Fixed OpenGL state issue reported by Dmytro Bogovych
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
479 renderdata->glDisable(data->type); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 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
|
484 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
486 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 static int |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
490 const SDL_Rect * rect, void **pixels, int *pitch) |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 |
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
|
494 *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
|
495 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
496 rect->x * SDL_BYTESPERPIXEL(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
|
497 *pitch = data->pitch; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 { |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
504 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
505 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
506 |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
507 GL_ActivateRenderer(renderer); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
509 SetupTextureUpdate(renderdata, texture, data->pitch); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
510 renderdata->glEnable(data->type); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
511 renderdata->glBindTexture(data->type, data->texture); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
512 renderdata->glTexSubImage2D(data->type, 0, 0, 0, texture->w, texture->h, |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
513 data->format, data->formattype, data->pixels); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
514 renderdata->glDisable(data->type); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 |
2936
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
517 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
|
518 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
|
519 { |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
520 if (blendMode != data->blendMode) { |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
521 switch (blendMode) { |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
522 case SDL_BLENDMODE_NONE: |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
523 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
|
524 data->glDisable(GL_BLEND); |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
525 break; |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
526 case SDL_BLENDMODE_BLEND: |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
527 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
|
528 data->glEnable(GL_BLEND); |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
529 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
|
530 break; |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
531 case SDL_BLENDMODE_ADD: |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
532 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
|
533 data->glEnable(GL_BLEND); |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
534 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
|
535 break; |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
536 } |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
537 data->blendMode = blendMode; |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
538 } |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
539 } |
066384910f50
iPhone build compiles again (drawing routines need to be implemented)
Sam Lantinga <slouken@libsdl.org>
parents:
2927
diff
changeset
|
540 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 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
|
542 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
|
543 { |
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
|
544 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
|
545 |
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
|
546 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
|
547 |
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
|
548 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
|
549 (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
|
550 (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
|
551 (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
|
552 |
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
|
553 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
|
554 |
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
|
555 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
|
556 } |
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
|
557 |
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
|
558 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
|
559 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
|
560 int count) |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
561 { |
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
562 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
|
563 int i; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
564 |
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
|
565 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
|
566 |
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
|
567 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
|
568 |
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
569 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
|
570 (GLfloat) renderer->g * inv255f, |
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
571 (GLfloat) renderer->b * inv255f, |
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
572 (GLfloat) renderer->a * inv255f); |
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
573 |
2901 | 574 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
|
575 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
|
576 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
|
577 } |
2901 | 578 data->glEnd(); |
579 | |
580 return 0; | |
581 } | |
582 | |
583 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
|
584 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
|
585 int count) |
2901 | 586 { |
587 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
|
588 int i; |
2901 | 589 |
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
|
590 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
|
591 |
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
|
592 GL_SetBlendMode(data, renderer->blendMode); |
2901 | 593 |
594 data->glColor4f((GLfloat) renderer->r * inv255f, | |
595 (GLfloat) renderer->g * inv255f, | |
596 (GLfloat) renderer->b * inv255f, | |
597 (GLfloat) renderer->a * inv255f); | |
598 | |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
599 if (count > 2 && |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
600 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
|
601 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
|
602 /* 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
|
603 --count; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
604 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
|
605 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
|
606 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
607 data->glEnd(); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
608 } else { |
5088
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
5062
diff
changeset
|
609 #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
|
610 #else |
4905
9779093454d2
This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents:
4455
diff
changeset
|
611 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
|
612 #endif |
4905
9779093454d2
This fixes SDL_renderer_gl so that it builds with c89.
Sam Lantinga <slouken@libsdl.org>
parents:
4455
diff
changeset
|
613 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
614 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
|
615 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
|
616 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
|
617 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
618 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
|
619 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
620 /* 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
|
621 * 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
|
622 * 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
|
623 * 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
|
624 * 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
|
625 * 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
|
626 */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
627 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
|
628 #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
|
629 /* 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
|
630 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
|
631 #else |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
632 /* 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
638 if (x1 > x2) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
639 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
|
640 } else if (x2 > x1) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
641 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
|
642 } else if (y1 > y2) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
643 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
|
644 } else if (y2 > y1) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
645 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
|
646 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
647 #endif |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
648 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
|
649 } |
3455
5a7b5760c875
Include the endpoint in the line we're drawing
Sam Lantinga <slouken@libsdl.org>
parents:
3454
diff
changeset
|
650 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
651 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
652 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
653 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
654 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
|
655 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
|
656 { |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
657 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
|
658 int i; |
2925
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
659 |
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
|
660 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
|
661 |
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
|
662 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
|
663 |
2925
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
664 data->glColor4f((GLfloat) renderer->r * inv255f, |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
665 (GLfloat) renderer->g * inv255f, |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
666 (GLfloat) renderer->b * inv255f, |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
667 (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
|
668 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
669 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
|
670 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
|
671 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3533
diff
changeset
|
672 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
|
673 } |
2925
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
674 |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
675 return 0; |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
676 } |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
677 |
7e21f7662208
Swapped functions to match the other renderer files
Sam Lantinga <slouken@libsdl.org>
parents:
2922
diff
changeset
|
678 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
679 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
|
680 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
681 { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
682 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
683 GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
684 int minx, miny, maxx, maxy; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
685 GLfloat minu, maxu, minv, maxv; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
686 |
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
|
687 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
|
688 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
689 minx = dstrect->x; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
690 miny = dstrect->y; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 maxx = dstrect->x + dstrect->w; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 maxy = dstrect->y + dstrect->h; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
693 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
694 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
|
695 minu *= texturedata->texw; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
696 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
|
697 maxu *= texturedata->texw; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
698 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
|
699 minv *= texturedata->texh; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
700 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
|
701 maxv *= texturedata->texh; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
702 |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
703 data->glEnable(texturedata->type); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
704 data->glBindTexture(texturedata->type, texturedata->texture); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
705 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
706 if (texture->modMode) { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
707 data->glColor4f((GLfloat) texture->r * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
708 (GLfloat) texture->g * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
709 (GLfloat) texture->b * inv255f, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
710 (GLfloat) texture->a * inv255f); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
711 } else { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
712 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
|
713 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1975
diff
changeset
|
714 |
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
|
715 GL_SetBlendMode(data, texture->blendMode); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
716 |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
717 data->glBegin(GL_TRIANGLE_STRIP); |
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
718 data->glTexCoord2f(minu, minv); |
3472
fdd2f2e9cd97
Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents:
3470
diff
changeset
|
719 data->glVertex2f((GLfloat) minx, (GLfloat) miny); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
720 data->glTexCoord2f(maxu, minv); |
3472
fdd2f2e9cd97
Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents:
3470
diff
changeset
|
721 data->glVertex2f((GLfloat) maxx, (GLfloat) miny); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
722 data->glTexCoord2f(minu, maxv); |
3472
fdd2f2e9cd97
Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents:
3470
diff
changeset
|
723 data->glVertex2f((GLfloat) minx, (GLfloat) maxy); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
724 data->glTexCoord2f(maxu, maxv); |
3472
fdd2f2e9cd97
Fixed the coordinates for pixel coverage in blits
Sam Lantinga <slouken@libsdl.org>
parents:
3470
diff
changeset
|
725 data->glVertex2f((GLfloat) maxx, (GLfloat) maxy); |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
726 data->glEnd(); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
727 |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
728 data->glDisable(texturedata->type); |
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2858
diff
changeset
|
729 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
730 return 0; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
731 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
732 |
3431
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
733 static int |
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
734 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
|
735 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
|
736 { |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
737 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
|
738 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
|
739 GLint internalFormat; |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
740 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
|
741 Uint8 *src, *dst, *tmp; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
742 int w, h, length, rows; |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
743 |
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
|
744 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
|
745 |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
746 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
|
747 /* 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
|
748 SDL_SetError("Unsupported pixel format"); |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
749 return -1; |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
750 } |
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
751 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
752 SDL_GetWindowSize(window, &w, &h); |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
753 |
3446
0f969d273f65
First pass (untested) at RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3443
diff
changeset
|
754 data->glPixelStorei(GL_PACK_ALIGNMENT, 1); |
0f969d273f65
First pass (untested) at RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3443
diff
changeset
|
755 data->glPixelStorei(GL_PACK_ROW_LENGTH, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
756 (pitch / SDL_BYTESPERPIXEL(pixel_format))); |
3433
ad845d9835aa
Hmm, this isn't going to work, is it?
Sam Lantinga <slouken@libsdl.org>
parents:
3431
diff
changeset
|
757 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
758 data->glReadPixels(rect->x, (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
|
759 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
|
760 |
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3433
diff
changeset
|
761 /* Flip the rows to be top-down */ |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
762 length = rect->w * SDL_BYTESPERPIXEL(pixel_format); |
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
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 SDL_memcpy(src, tmp, length); |
3447
294b770c1989
Fixed GL_RenderReadPixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3446
diff
changeset
|
771 dst += pitch; |
294b770c1989
Fixed GL_RenderReadPixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3446
diff
changeset
|
772 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
|
773 } |
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3433
diff
changeset
|
774 SDL_stack_free(tmp); |
3440
e9502d56ae94
Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
775 |
e9502d56ae94
Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
776 return 0; |
3431
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
777 } |
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
778 |
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
779 static int |
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
780 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
|
781 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
|
782 { |
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
|
783 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
|
784 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
|
785 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
|
786 GLenum format, type; |
3607
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
787 Uint8 *src, *dst, *tmp; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
788 int w, h, 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
|
789 |
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
|
790 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
|
791 |
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
|
792 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
|
793 /* 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
|
794 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
|
795 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
|
796 } |
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3433
diff
changeset
|
797 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
798 SDL_GetWindowSize(window, &w, &h); |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
799 |
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
|
800 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
|
801 data->glPixelStorei(GL_UNPACK_ROW_LENGTH, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
802 (pitch / SDL_BYTESPERPIXEL(pixel_format))); |
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
|
803 |
3607
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
804 /* Flip the rows to be bottom-up */ |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
805 length = rect->h * rect->w * pitch; |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
806 tmp = SDL_stack_alloc(Uint8, length); |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
807 src = (Uint8*)pixels + (rect->h-1)*pitch; |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
808 dst = (Uint8*)tmp; |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
809 rows = rect->h; |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
810 while (rows--) { |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
811 SDL_memcpy(dst, src, pitch); |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
812 dst += pitch; |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
813 src -= pitch; |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
814 } |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
815 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5153
diff
changeset
|
816 data->glRasterPos2i(rect->x, (h-rect->y)); |
3607
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
817 data->glDrawPixels(rect->w, rect->h, format, type, tmp); |
8b4c0320638e
Fixed GL_RenderWritePixels() - thanks Ryan!
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
818 SDL_stack_free(tmp); |
3440
e9502d56ae94
Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
819 |
e9502d56ae94
Added missing return values
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
820 return 0; |
3431
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
821 } |
c8fbb27627d9
Work in progress on OpenGL ReadPixels/WritePixels interface
Sam Lantinga <slouken@libsdl.org>
parents:
3393
diff
changeset
|
822 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
823 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
824 GL_RenderPresent(SDL_Renderer * renderer) |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
825 { |
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
|
826 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
|
827 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
828 SDL_GL_SwapWindow(renderer->window); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
829 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
830 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
831 static void |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
832 GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
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; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
836 |
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
|
837 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
|
838 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
839 if (!data) { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
840 return; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
841 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
842 if (data->texture) { |
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset
|
843 renderdata->glDeleteTextures(1, &data->texture); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
844 } |
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
|
845 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
|
846 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
|
847 } |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
848 SDL_free(data); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
849 texture->driverdata = NULL; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
850 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
851 |
1975
ccef0d0c40c6
Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents:
1974
diff
changeset
|
852 static void |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
853 GL_DestroyRenderer(SDL_Renderer * renderer) |
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 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
856 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
857 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
|
858 if (data->context) { |
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
|
859 /* 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
|
860 SDL_GL_DeleteContext(data->context); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
861 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
862 SDL_free(data); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
863 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
864 SDL_free(renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
865 } |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
866 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
1928
diff
changeset
|
867 #endif /* SDL_VIDEO_RENDER_OGL */ |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
868 |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
869 /* vi: set ts=4 sw=4 expandtab: */ |