author  Sam Lantinga <slouken@libsdl.org> 
Sun, 23 Jul 2006 00:19:12 +0000  
changeset 1928  861bc36f0ab3 
parent 1927  aeb8263d377a 
child 1952  420716272158 
permissions  rwrr 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

1 
/* 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

2 
SDL  Simple DirectMedia Layer 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

3 
Copyright (C) 19972006 Sam Lantinga 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

4 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

5 
This library is free software; you can redistribute it and/or 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

6 
modify it under the terms of the GNU Lesser General Public 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

7 
License as published by the Free Software Foundation; either 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

8 
version 2.1 of the License, or (at your option) any later version. 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

9 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

10 
This library is distributed in the hope that it will be useful, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

11 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

12 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

13 
Lesser General Public License for more details. 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

14 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

15 
You should have received a copy of the GNU Lesser General Public 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

16 
License along with this library; if not, write to the Free Software 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

17 
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 021101301 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 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

24 
#if SDL_VIDEO_OPENGL 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

25 

8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

26 
#include "SDL_video.h" 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

27 
#include "SDL_opengl.h" 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

28 
#include "SDL_sysvideo.h" 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

29 
#include "SDL_pixels_c.h" 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

30 
#include "SDL_rect_c.h" 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

31 
#include "SDL_yuv_sw_c.h" 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

32 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

33 
/* OpenGL renderer implementation */ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

34 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

35 
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); 
1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

36 
static int GL_ActivateRenderer(SDL_Renderer * renderer); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

37 
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

38 
static int GL_SetTexturePalette(SDL_Renderer * renderer, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

39 
SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

40 
const SDL_Color * colors, int firstcolor, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

41 
int ncolors); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

42 
static int GL_GetTexturePalette(SDL_Renderer * renderer, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

43 
SDL_Texture * texture, SDL_Color * colors, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

44 
int firstcolor, int ncolors); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

45 
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

46 
const SDL_Rect * rect, const void *pixels, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

47 
int pitch); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

48 
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

49 
const SDL_Rect * rect, int markDirty, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

50 
void **pixels, int *pitch); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

51 
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

52 
static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

53 
int numrects, const SDL_Rect * rects); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

54 
static int GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

55 
Uint32 color); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

56 
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

57 
const SDL_Rect * srcrect, const SDL_Rect * dstrect, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

58 
int blendMode, int scaleMode); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

59 
static void GL_RenderPresent(SDL_Renderer * renderer); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

60 
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

61 
static void GL_DestroyRenderer(SDL_Renderer * renderer); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

62 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

63 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

64 
SDL_RenderDriver GL_RenderDriver = { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

65 
GL_CreateRenderer, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

66 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

67 
"opengl", 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

68 
(SDL_Renderer_PresentDiscard  SDL_Renderer_PresentVSync  
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

69 
SDL_Renderer_Accelerated), 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

70 
(SDL_TextureBlendMode_None  SDL_TextureBlendMode_Mask  
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

71 
SDL_TextureBlendMode_Blend  SDL_TextureBlendMode_Add  
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

72 
SDL_TextureBlendMode_Mod), 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

73 
(SDL_TextureScaleMode_None  SDL_TextureScaleMode_Fast  
1921
f3399f779a1d
Bug fixes to the OpenGL renderer
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset

74 
SDL_TextureScaleMode_Slow), 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

75 
16, 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

76 
{ 
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

77 
SDL_PixelFormat_Index1LSB, 
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

78 
SDL_PixelFormat_Index1MSB, 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

79 
SDL_PixelFormat_Index8, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

80 
SDL_PixelFormat_RGB332, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

81 
SDL_PixelFormat_RGB444, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

82 
SDL_PixelFormat_RGB555, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

83 
SDL_PixelFormat_ARGB4444, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

84 
SDL_PixelFormat_ARGB1555, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

85 
SDL_PixelFormat_RGB565, 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

86 
SDL_PixelFormat_RGB24, 
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

87 
SDL_PixelFormat_BGR24, 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

88 
SDL_PixelFormat_RGB888, 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

89 
SDL_PixelFormat_BGR888, 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

90 
SDL_PixelFormat_ARGB8888, 
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

91 
SDL_PixelFormat_ABGR8888, 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

92 
SDL_PixelFormat_ARGB2101010}, 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

93 
0, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

94 
0} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

95 
}; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

96 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

97 
typedef struct 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

98 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

99 
SDL_GLContext context; 
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

100 
SDL_bool GL_ARB_texture_rectangle_supported; 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

101 
int blendMode; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

102 
int scaleMode; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

103 

aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

104 
/* OpenGL functions */ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

105 
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

106 
#include "SDL_glfuncs.h" 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

107 
#undef SDL_PROC 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

108 
} GL_RenderData; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

109 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

110 
typedef struct 
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 
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

113 
GLenum type; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

114 
GLfloat texw; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

115 
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

116 
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

117 
GLenum formattype; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

118 
void *pixels; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

119 
int pitch; 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

120 
SDL_DirtyRectList dirty; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

121 
} GL_TextureData; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

122 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

123 

1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

124 
static void 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

125 
GL_SetError(const char *prefix, GLenum result) 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

126 
{ 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

127 
const char *error; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

128 

69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

129 
switch (result) { 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

130 
case GL_NO_ERROR: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

131 
error = "GL_NO_ERROR"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

132 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

133 
case GL_INVALID_ENUM: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

134 
error = "GL_INVALID_ENUM"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

135 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

136 
case GL_INVALID_VALUE: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

137 
error = "GL_INVALID_VALUE"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

138 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

139 
case GL_INVALID_OPERATION: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

140 
error = "GL_INVALID_OPERATION"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

141 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

142 
case GL_STACK_OVERFLOW: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

143 
error = "GL_STACK_OVERFLOW"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

144 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

145 
case GL_STACK_UNDERFLOW: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

146 
error = "GL_STACK_UNDERFLOW"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

147 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

148 
case GL_OUT_OF_MEMORY: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

149 
error = "GL_OUT_OF_MEMORY"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

150 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

151 
case GL_TABLE_TOO_LARGE: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

152 
error = "GL_TABLE_TOO_LARGE"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

153 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

154 
default: 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

155 
error = "UNKNOWN"; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

156 
break; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

157 
} 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

158 
SDL_SetError("%s: %s", prefix, error); 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

159 
} 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

160 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

161 
static int 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

162 
GL_LoadFunctions(GL_RenderData * data) 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

163 
{ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

164 
#if defined(__QNXNTO__) && (_NTO_VERSION < 630) 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

165 
#define __SDL_NOGETPROCADDR__ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

166 
#elif defined(__MINT__) 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

167 
#define __SDL_NOGETPROCADDR__ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

168 
#endif 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

169 
#ifdef __SDL_NOGETPROCADDR__ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

170 
#define SDL_PROC(ret,func,params) data>func=func; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

171 
#else 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

172 
#define SDL_PROC(ret,func,params) \ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

173 
do { \ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

174 
data>func = SDL_GL_GetProcAddress(#func); \ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

175 
if ( ! data>func ) { \ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

176 
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

177 
return 1; \ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

178 
} \ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

179 
} while ( 0 ); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

180 
#endif /* __SDL_NOGETPROCADDR__ */ 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

181 

aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

182 
#include "SDL_glfuncs.h" 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

183 
#undef SDL_PROC 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

184 
return 0; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

185 
} 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

186 

1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

187 
void 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

188 
GL_AddRenderDriver(_THIS) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

189 
{ 
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

190 
if (_this>GL_CreateContext) { 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

191 
SDL_AddRenderDriver(0, &GL_RenderDriver); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

192 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

193 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

194 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

195 
SDL_Renderer * 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

196 
GL_CreateRenderer(SDL_Window * window, Uint32 flags) 
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 
SDL_Renderer *renderer; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

199 
GL_RenderData *data; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

200 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

201 
if (!(window>flags & SDL_WINDOW_OPENGL)) { 
1928
861bc36f0ab3
Fixed crash with multiple windows
Sam Lantinga <slouken@libsdl.org>
parents:
1927
diff
changeset

202 
if (SDL_RecreateWindow(window, window>flags  SDL_WINDOW_OPENGL) < 0) { 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

203 
return NULL; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

204 
} 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

205 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

206 

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

207 
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

208 
if (!renderer) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

209 
SDL_OutOfMemory(); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

210 
return NULL; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

211 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

212 

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

213 
data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

214 
if (!data) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

215 
GL_DestroyRenderer(renderer); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

216 
SDL_OutOfMemory(); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

217 
return NULL; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

218 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

219 

1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

220 
renderer>ActivateRenderer = GL_ActivateRenderer; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

221 
renderer>CreateTexture = GL_CreateTexture; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

222 
renderer>SetTexturePalette = GL_SetTexturePalette; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

223 
renderer>GetTexturePalette = GL_GetTexturePalette; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

224 
renderer>UpdateTexture = GL_UpdateTexture; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

225 
renderer>LockTexture = GL_LockTexture; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

226 
renderer>UnlockTexture = GL_UnlockTexture; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

227 
renderer>DirtyTexture = GL_DirtyTexture; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

228 
renderer>RenderFill = GL_RenderFill; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

229 
renderer>RenderCopy = GL_RenderCopy; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

230 
renderer>RenderPresent = GL_RenderPresent; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

231 
renderer>DestroyTexture = GL_DestroyTexture; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

232 
renderer>DestroyRenderer = GL_DestroyRenderer; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

233 
renderer>info = GL_RenderDriver.info; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

234 
renderer>window = window>id; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

235 
renderer>driverdata = data; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

236 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

237 
renderer>info.flags = 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

238 
(SDL_Renderer_PresentDiscard  SDL_Renderer_Accelerated); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

239 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

240 
if (GL_LoadFunctions(data) < 0) { 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

241 
GL_DestroyRenderer(renderer); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

242 
return NULL; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

243 
} 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

244 

1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

245 
data>context = SDL_GL_CreateContext(window>id); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

246 
if (!data>context) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

247 
GL_DestroyRenderer(renderer); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

248 
return NULL; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

249 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

250 
if (SDL_GL_MakeCurrent(window>id, data>context) < 0) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

251 
GL_DestroyRenderer(renderer); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

252 
return NULL; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

253 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

254 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

255 
if (flags & SDL_Renderer_PresentVSync) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

256 
SDL_GL_SetSwapInterval(1); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

257 
} else { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

258 
SDL_GL_SetSwapInterval(0); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

259 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

260 
if (SDL_GL_GetSwapInterval() > 0) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

261 
renderer>info.flags = SDL_Renderer_PresentVSync; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

262 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

263 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

264 
data>glGetIntegerv(GL_MAX_TEXTURE_SIZE, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

265 
&renderer>info.max_texture_width); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

266 
data>glGetIntegerv(GL_MAX_TEXTURE_SIZE, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

267 
&renderer>info.max_texture_height); 
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

268 

1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

269 
if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

270 
 SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

271 
data>GL_ARB_texture_rectangle_supported = SDL_TRUE; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

272 
} 
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

273 

1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

274 
/* Set up parameters for rendering */ 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

275 
data>blendMode = 1; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

276 
data>scaleMode = 1; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

277 
data>glDisable(GL_DEPTH_TEST); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

278 
data>glDisable(GL_CULL_FACE); 
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

279 
if (data>GL_ARB_texture_rectangle_supported) { 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

280 
data>glEnable(GL_TEXTURE_RECTANGLE_ARB); 
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

281 
} else { 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

282 
data>glEnable(GL_TEXTURE_2D); 
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

283 
} 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

284 
data>glMatrixMode(GL_PROJECTION); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

285 
data>glLoadIdentity(); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

286 
data>glMatrixMode(GL_MODELVIEW); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

287 
data>glLoadIdentity(); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

288 
data>glViewport(0, 0, window>w, window>h); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

289 
data>glOrtho(0.0, (GLdouble) window>w, (GLdouble) window>h, 0.0, 0.0, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

290 
1.0); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

291 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

292 
return renderer; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

293 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

294 

1923
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

295 
static int 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

296 
GL_ActivateRenderer(SDL_Renderer * renderer) 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

297 
{ 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

298 
GL_RenderData *data = (GL_RenderData *) renderer>driverdata; 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

299 
SDL_Window *window = SDL_GetWindowFromID(renderer>window); 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

300 

d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

301 
return SDL_GL_MakeCurrent(window>id, data>context); 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

302 
} 
d4572b97b08f
Switch OpenGL contexts when switching render contexts.
Sam Lantinga <slouken@libsdl.org>
parents:
1922
diff
changeset

303 

1922
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

304 
static __inline__ int 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

305 
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

306 
{ 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

307 
int value = 1; 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

308 

4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

309 
while (value < input) { 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

310 
value <<= 1; 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

311 
} 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

312 
return value; 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

313 
} 
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

314 

1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

315 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

316 
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

317 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

318 
GL_RenderData *renderdata = (GL_RenderData *) renderer>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

319 
SDL_Window *window = SDL_GetWindowFromID(renderer>window); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

320 
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

321 
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

322 
GLenum format, type; 
1922
4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
Sam Lantinga <slouken@libsdl.org>
parents:
1921
diff
changeset

323 
int texture_w, texture_h; 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

324 
GLenum result; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

325 

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

326 
switch (texture>format) { 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

327 
case SDL_PixelFormat_Index1LSB: 
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

328 
case SDL_PixelFormat_Index1MSB: 
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

329 
internalFormat = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

330 
format = GL_COLOR_INDEX; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

331 
type = GL_BITMAP; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

332 
break; 
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

333 
case SDL_PixelFormat_Index8: 
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

334 
internalFormat = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

335 
format = GL_COLOR_INDEX; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

336 
type = GL_UNSIGNED_BYTE; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

337 
break; 
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

338 
case SDL_PixelFormat_RGB332: 
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

339 
internalFormat = GL_R3_G3_B2; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

340 
format = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

341 
type = GL_UNSIGNED_BYTE_3_3_2; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

342 
break; 
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

343 
case SDL_PixelFormat_RGB444: 
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

344 
internalFormat = GL_RGB4; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

345 
format = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

346 
type = GL_UNSIGNED_SHORT_4_4_4_4; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

347 
break; 
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

348 
case SDL_PixelFormat_RGB555: 
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

349 
internalFormat = GL_RGB5; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

350 
format = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

351 
type = GL_UNSIGNED_SHORT_5_5_5_1; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

352 
break; 
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

353 
case SDL_PixelFormat_ARGB4444: 
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

354 
internalFormat = GL_RGBA4; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

355 
format = GL_BGRA; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

356 
type = GL_UNSIGNED_SHORT_4_4_4_4_REV; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

357 
break; 
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

358 
case SDL_PixelFormat_ARGB1555: 
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

359 
internalFormat = GL_RGB5_A1; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

360 
format = GL_BGRA; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

361 
type = GL_UNSIGNED_SHORT_1_5_5_5_REV; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

362 
break; 
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

363 
case SDL_PixelFormat_RGB565: 
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

364 
internalFormat = GL_RGB8; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

365 
format = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

366 
type = GL_UNSIGNED_SHORT_5_6_5; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

367 
break; 
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 
case SDL_PixelFormat_RGB24: 
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 
internalFormat = GL_RGB8; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

370 
format = GL_RGB; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

371 
type = GL_UNSIGNED_BYTE; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

372 
break; 
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

373 
case SDL_PixelFormat_RGB888: 
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

374 
internalFormat = GL_RGB8; 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

375 
format = GL_BGRA; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

376 
type = GL_UNSIGNED_BYTE; 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

377 
break; 
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

378 
case SDL_PixelFormat_BGR24: 
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

379 
internalFormat = GL_RGB8; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

380 
format = GL_BGR; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

381 
type = GL_UNSIGNED_BYTE; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

382 
break; 
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

383 
case SDL_PixelFormat_BGR888: 
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

384 
internalFormat = GL_RGB8; 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

385 
format = GL_RGBA; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

386 
type = GL_UNSIGNED_BYTE; 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

387 
break; 
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

388 
case SDL_PixelFormat_ARGB8888: 
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

389 
internalFormat = GL_RGBA8; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

390 
format = GL_BGRA; 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

391 
type = GL_UNSIGNED_BYTE; 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

392 
break; 
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

393 
case SDL_PixelFormat_ABGR8888: 
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

394 
internalFormat = GL_RGBA8; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

395 
format = GL_RGBA; 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

396 
type = GL_UNSIGNED_BYTE; 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

397 
break; 
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

398 
case SDL_PixelFormat_ARGB2101010: 
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

399 
internalFormat = GL_RGB10_A2; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

400 
format = GL_BGRA; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

401 
type = GL_UNSIGNED_INT_2_10_10_10_REV; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

402 
break; 
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 
default: 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

404 
SDL_SetError("Unsupported texture format"); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

405 
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

406 
} 
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

407 

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

408 
data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

409 
if (!data) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

410 
SDL_OutOfMemory(); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

411 
return 1; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

412 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

413 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

414 
texture>driverdata = data; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

415 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

416 
renderdata>glGetError(); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

417 
renderdata>glGenTextures(1, &data>texture); 
1926
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

418 
if (renderdata>GL_ARB_texture_rectangle_supported) { 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

419 
data>type = GL_TEXTURE_RECTANGLE_ARB; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

420 
texture_w = texture>w; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

421 
texture_h = texture>h; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

422 
data>texw = (GLfloat) texture>w; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

423 
data>texh = (GLfloat) texture>h; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

424 
} else { 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

425 
data>type = GL_TEXTURE_2D; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

426 
texture_w = power_of_2(texture>w); 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

427 
texture_h = power_of_2(texture>h); 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

428 
data>texw = (GLfloat) texture>w / texture_w; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

429 
data>texh = (GLfloat) texture>h / texture_h; 
307355678142
Added SDL_GL_ExtensionSupported()
Sam Lantinga <slouken@libsdl.org>
parents:
1924
diff
changeset

430 
} 
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

431 
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

432 
data>formattype = type; 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

433 
renderdata>glBindTexture(data>type, data>texture); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

434 
renderdata>glTexImage2D(data>type, 0, internalFormat, texture_w, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

435 
texture_h, 0, format, type, NULL); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

436 
result = renderdata>glGetError(); 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

437 
if (result != GL_NO_ERROR) { 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

438 
GL_SetError("glTexImage2D()", result); 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

439 
return 1; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

440 
} 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

441 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

442 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

443 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

444 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

445 
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

446 
const SDL_Color * colors, int firstcolor, int ncolors) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

447 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

448 
GL_RenderData *renderdata = (GL_RenderData *) renderer>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

449 
GL_TextureData *data = (GL_TextureData *) texture>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

450 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

451 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

452 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

453 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

454 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

455 
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

456 
SDL_Color * colors, int firstcolor, int ncolors) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

457 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

458 
GL_TextureData *data = (GL_TextureData *) texture>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

459 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

460 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

461 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

462 

1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

463 
static void 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

464 
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

465 
int pitch) 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

466 
{ 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

467 
if (texture>format == SDL_PixelFormat_Index1LSB) { 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

468 
renderdata>glPixelStorei(GL_UNPACK_LSB_FIRST, 1); 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

469 
} else if (texture>format == SDL_PixelFormat_Index1MSB) { 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

470 
renderdata>glPixelStorei(GL_UNPACK_LSB_FIRST, 0); 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

471 
} 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

472 
renderdata>glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

473 
renderdata>glPixelStorei(GL_UNPACK_ROW_LENGTH, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

474 
pitch / SDL_BYTESPERPIXEL(texture>format)); 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

475 
} 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

476 

1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

477 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

478 
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

479 
const SDL_Rect * rect, const void *pixels, int pitch) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

480 
{ 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

481 
GL_RenderData *renderdata = (GL_RenderData *) renderer>driverdata; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

482 
GL_TextureData *data = (GL_TextureData *) texture>driverdata; 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

483 
GLenum result; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

484 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

485 
renderdata>glGetError(); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

486 
SetupTextureUpdate(renderdata, texture, pitch); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

487 
renderdata>glBindTexture(data>type, data>texture); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

488 
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

489 
rect>h, data>format, data>formattype, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

490 
pixels); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

491 
result = renderdata>glGetError(); 
1924
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

492 
if (result != GL_NO_ERROR) { 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

493 
GL_SetError("glTexSubImage2D()", result); 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

494 
return 1; 
69217fdd2c0a
If the OpenGL renderer is selected for a nonOpenGL window, recreate the window with OpenGL enabled.
Sam Lantinga <slouken@libsdl.org>
parents:
1923
diff
changeset

495 
} 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

496 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

497 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

498 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

499 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

500 
GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

501 
const SDL_Rect * rect, int markDirty, void **pixels, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

502 
int *pitch) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

503 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

504 
GL_TextureData *data = (GL_TextureData *) texture>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

505 

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

506 
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

507 
data>pitch = texture>w * SDL_BYTESPERPIXEL(texture>format); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

508 
data>pixels = SDL_malloc(texture>h * data>pitch); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

509 
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

510 
SDL_OutOfMemory(); 
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

511 
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

512 
} 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

513 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

514 

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

515 
if (markDirty) { 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

516 
SDL_AddDirtyRect(&data>dirty, rect); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

517 
} 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

518 

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

519 
*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

520 
(void *) ((Uint8 *) data>pixels + rect>y * data>pitch + 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

521 
rect>x * SDL_BYTESPERPIXEL(texture>format)); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

522 
*pitch = data>pitch; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

523 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

524 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

525 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

526 
static void 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

527 
GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

528 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

529 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

530 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

531 
static void 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

532 
GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

533 
const SDL_Rect * rects) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

534 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

535 
GL_TextureData *data = (GL_TextureData *) texture>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

536 
int i; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

537 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

538 
for (i = 0; i < numrects; ++i) { 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

539 
SDL_AddDirtyRect(&data>dirty, &rects[i]); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

540 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

541 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

542 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

543 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

544 
GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 color) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

545 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

546 
GL_RenderData *data = (GL_RenderData *) renderer>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

547 
SDL_Window *window = SDL_GetWindowFromID(renderer>window); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

548 
GLclampf r, g, b, a; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

549 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

550 
a = ((GLclampf) ((color >> 24) & 0xFF)) / 255.0f; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

551 
r = ((GLclampf) ((color >> 16) & 0xFF)) / 255.0f; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

552 
g = ((GLclampf) ((color >> 8) & 0xFF)) / 255.0f; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

553 
b = ((GLclampf) (color & 0xFF)) / 255.0f; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

554 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

555 
data>glClearColor(r, g, b, a); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

556 
data>glViewport(rect>x, window>h  rect>y, rect>w, rect>h); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

557 
data>glClear(GL_COLOR_BUFFER_BIT); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

558 
data>glViewport(0, 0, window>w, window>h); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

559 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

560 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

561 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

562 
static int 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

563 
GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

564 
const SDL_Rect * srcrect, const SDL_Rect * dstrect, 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

565 
int blendMode, int scaleMode) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

566 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

567 
GL_RenderData *data = (GL_RenderData *) renderer>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

568 
GL_TextureData *texturedata = (GL_TextureData *) texture>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

569 
int minx, miny, maxx, maxy; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

570 
GLfloat minu, maxu, minv, maxv; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

571 

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

572 
if (texturedata>dirty.count > 0) { 
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

573 
SDL_DirtyRect *dirty; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

574 
void *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

575 
int bpp = SDL_BYTESPERPIXEL(texture>format); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

576 
int pitch = texturedata>pitch; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

577 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

578 
SetupTextureUpdate(data, texture, pitch); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

579 
data>glBindTexture(texturedata>type, texturedata>texture); 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

580 
for (dirty = texturedata>dirty.list; dirty; dirty = dirty>next) { 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

581 
SDL_Rect *rect = &dirty>rect; 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

582 
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

583 
(void *) ((Uint8 *) texturedata>pixels + rect>y * pitch + 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

584 
rect>x * bpp); 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

585 
data>glTexSubImage2D(texturedata>type, 0, rect>x, rect>y, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

586 
rect>w, rect>h, texturedata>format, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

587 
texturedata>formattype, pixels); 
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

588 
} 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

589 
SDL_ClearDirtyRects(&texturedata>dirty); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

590 
} 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

591 

1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

592 
minx = dstrect>x; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

593 
miny = dstrect>y; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

594 
maxx = dstrect>x + dstrect>w; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

595 
maxy = dstrect>y + dstrect>h; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

596 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

597 
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

598 
minu *= texturedata>texw; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

599 
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

600 
maxu *= texturedata>texw; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

601 
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

602 
minv *= texturedata>texh; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

603 
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

604 
maxv *= texturedata>texh; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

605 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

606 
data>glBindTexture(texturedata>type, texturedata>texture); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

607 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

608 
if (blendMode != data>blendMode) { 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

609 
switch (blendMode) { 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

610 
case SDL_TextureBlendMode_None: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

611 
data>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

612 
data>glDisable(GL_BLEND); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

613 
break; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

614 
case SDL_TextureBlendMode_Mask: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

615 
case SDL_TextureBlendMode_Blend: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

616 
data>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

617 
data>glEnable(GL_BLEND); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

618 
data>glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

619 
break; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

620 
case SDL_TextureBlendMode_Add: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

621 
data>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

622 
data>glEnable(GL_BLEND); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

623 
data>glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

624 
break; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

625 
case SDL_TextureBlendMode_Mod: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

626 
data>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

627 
data>glEnable(GL_BLEND); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

628 
data>glBlendFunc(GL_ZERO, GL_SRC_COLOR); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

629 
break; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

630 
} 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

631 
data>blendMode = blendMode; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

632 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

633 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

634 
if (scaleMode != data>scaleMode) { 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

635 
switch (scaleMode) { 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

636 
case SDL_TextureScaleMode_None: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

637 
case SDL_TextureScaleMode_Fast: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

638 
data>glTexParameteri(texturedata>type, GL_TEXTURE_MIN_FILTER, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

639 
GL_NEAREST); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

640 
data>glTexParameteri(texturedata>type, GL_TEXTURE_MAG_FILTER, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

641 
GL_NEAREST); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

642 
break; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

643 
case SDL_TextureScaleMode_Slow: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

644 
case SDL_TextureScaleMode_Best: 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

645 
data>glTexParameteri(texturedata>type, GL_TEXTURE_MIN_FILTER, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

646 
GL_LINEAR); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

647 
data>glTexParameteri(texturedata>type, GL_TEXTURE_MAG_FILTER, 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

648 
GL_LINEAR); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

649 
break; 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

650 
} 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

651 
data>scaleMode = scaleMode; 
1918
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 

1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

654 
data>glBegin(GL_TRIANGLE_STRIP); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

655 
data>glTexCoord2f(minu, minv); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

656 
data>glVertex2i(minx, miny); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

657 
data>glTexCoord2f(maxu, minv); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

658 
data>glVertex2i(maxx, miny); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

659 
data>glTexCoord2f(minu, maxv); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

660 
data>glVertex2i(minx, maxy); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

661 
data>glTexCoord2f(maxu, maxv); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

662 
data>glVertex2i(maxx, maxy); 
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

663 
data>glEnd(); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

664 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

665 
return 0; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

666 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

667 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

668 
static void 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

669 
GL_RenderPresent(SDL_Renderer * renderer) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

670 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

671 
SDL_GL_SwapWindow(renderer>window); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

672 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

673 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

674 
static void 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

675 
GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

676 
{ 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

677 
GL_RenderData *renderdata = (GL_RenderData *) renderer>driverdata; 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

678 
GL_TextureData *data = (GL_TextureData *) texture>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

679 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

680 
if (!data) { 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

681 
return; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

682 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

683 
if (data>texture) { 
1927
aeb8263d377a
OpenGL renderer is feature complete!
Sam Lantinga <slouken@libsdl.org>
parents:
1926
diff
changeset

684 
renderdata>glDeleteTextures(1, &data>texture); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

685 
} 
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

686 
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

687 
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

688 
} 
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

689 
SDL_FreeDirtyRects(&data>dirty); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

690 
SDL_free(data); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

691 
texture>driverdata = NULL; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

692 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

693 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

694 
void 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

695 
GL_DestroyRenderer(SDL_Renderer * renderer) 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

696 
{ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

697 
GL_RenderData *data = (GL_RenderData *) renderer>driverdata; 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

698 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

699 
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

700 
if (data>context) { 
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 
SDL_GL_MakeCurrent(0, NULL); 
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1919
diff
changeset

702 
SDL_GL_DeleteContext(data>context); 
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

703 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

704 
SDL_free(data); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

705 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

706 
SDL_free(renderer); 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

707 
} 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

708 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

709 
#endif /* SDL_VIDEO_OPENGL */ 
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

710 

092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

711 
/* vi: set ts=4 sw=4 expandtab: */ 