annotate src/video/windows/SDL_ceddrawrender.c @ 5071:55ff76cdbbb8

HAVE_GCC_ATOMICS covers the test and set
author Sam Lantinga <slouken@libsdl.org>
date Fri, 21 Jan 2011 21:45:55 -0800
parents e8916fe9cfc8
children da10636e5eca
rev   line source
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 Stefan Klug
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 klug.stefan@gmx.de
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_config.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #if SDL_VIDEO_RENDER_DDRAW
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
29 #include "SDL_windowsvideo.h"
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "../SDL_yuv_sw_c.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #if 0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #define DDRAW_LOG(...) printf(__VA_ARGS__)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #else
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #define DDRAW_LOG(...)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 /* DirectDraw renderer implementation */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 static SDL_Renderer *DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 static int DDRAW_DisplayModeChanged(SDL_Renderer * renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 static int DDRAW_CreateTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 static int DDRAW_QueryTexturePixels(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 SDL_Texture * texture, void **pixels,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 int *pitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 static int DDRAW_SetTextureColorMod(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 static int DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 static int DDRAW_SetTextureBlendMode(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 static int DDRAW_SetTextureScaleMode(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 static int DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 const SDL_Rect * rect, const void *pixels,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 int pitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 static int DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 const SDL_Rect * rect, int markDirty,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 void **pixels, int *pitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 static void DDRAW_UnlockTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 static void DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 int numrects, const SDL_Rect * rects);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 static int DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 static int DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 int y2);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 static int DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 static int DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 const SDL_Rect * srcrect,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 const SDL_Rect * dstrect);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 static void DDRAW_RenderPresent(SDL_Renderer * renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 static void DDRAW_DestroyTexture(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 SDL_Texture * texture);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 static void DDRAW_DestroyRenderer(SDL_Renderer * renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SDL_RenderDriver DDRAW_RenderDriver = {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 DDRAW_CreateRenderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 "ddraw",
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 (SDL_TEXTUREMODULATE_NONE),
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 (SDL_BLENDMODE_NONE),
4929
aa8888658021 Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents: 4569
diff changeset
88 (SDL_SCALEMODE_NONE),
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 0,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 {0},
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 0,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 0}
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 typedef struct
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 IDirectDraw *ddraw;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 IDirectDrawSurface *primary;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 } DDRAW_RenderData;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 typedef struct
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 RECT lock;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 IDirectDrawSurface *surface;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 } DDRAW_TextureData;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 DDRAW_SetError(const char *prefix, HRESULT result)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 const char *error;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 switch (result) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 case DDERR_CANTCREATEDC:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 error = "CANTCREATEDC";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 case DDERR_CANTLOCKSURFACE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 error = "CANTLOCKSURFACE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 case DDERR_CLIPPERISUSINGHWND:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 error = "CLIPPERISUSINGHWND";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 case DDERR_COLORKEYNOTSET:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 error = "COLORKEYNOTSET";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 case DDERR_CURRENTLYNOTAVAIL:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 error = "CURRENTLYNOTAVAIL";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 case DDERR_DCALREADYCREATED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 error = "DCALREADYCREATED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 case DDERR_DEVICEDOESNTOWNSURFACE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 error = "DEVICEDOESNTOWNSURFACE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 case DDERR_DIRECTDRAWALREADYCREATED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 error = "DIRECTDRAWALREADYCREATED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 case DDERR_EXCLUSIVEMODEALREADYSET:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 error = "EXCLUSIVEMODEALREADYSET";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 case DDERR_GENERIC:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 error = "GENERIC";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 case DDERR_HEIGHTALIGN:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 error = "HEIGHTALIGN";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 case DDERR_IMPLICITLYCREATED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 error = "IMPLICITLYCREATED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 case DDERR_INCOMPATIBLEPRIMARY:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 error = "INCOMPATIBLEPRIMARY";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 case DDERR_INVALIDCAPS:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 error = "INVALIDCAPS";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 case DDERR_INVALIDCLIPLIST:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 error = "INVALIDCLIPLIST";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 case DDERR_INVALIDMODE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 error = "INVALIDMODE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 case DDERR_INVALIDOBJECT:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 error = "INVALIDOBJECT";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 case DDERR_INVALIDPARAMS:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 error = "INVALIDPARAMS";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 case DDERR_INVALIDPIXELFORMAT:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 error = "INVALIDPIXELFORMAT";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 case DDERR_INVALIDPOSITION:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 error = "INVALIDPOSITION";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 case DDERR_INVALIDRECT:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 error = "INVALIDRECT";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 case DDERR_LOCKEDSURFACES:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 error = "LOCKEDSURFACES";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 case DDERR_MOREDATA:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 error = "MOREDATA";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 case DDERR_NOALPHAHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 error = "NOALPHAHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 case DDERR_NOBLTHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 error = "NOBLTHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 case DDERR_NOCLIPLIST:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 error = "NOCLIPLIST";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 case DDERR_NOCLIPPERATTACHED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 error = "NOCLIPPERATTACHED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 case DDERR_NOCOLORCONVHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 error = "NOCOLORCONVHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 case DDERR_NOCOLORKEYHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 error = "NOCOLORKEYHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 case DDERR_NOCOOPERATIVELEVELSET:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 error = "NOCOOPERATIVELEVELSET";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 case DDERR_NODC:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 error = "NODC";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 case DDERR_NOFLIPHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 error = "NOFLIPHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 case DDERR_NOOVERLAYDEST:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 error = "NOOVERLAYDEST";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 case DDERR_NOOVERLAYHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 error = "NOOVERLAYHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 case DDERR_NOPALETTEATTACHED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 error = "NOPALETTEATTACHED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 case DDERR_NOPALETTEHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 error = "NOPALETTEHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 case DDERR_NORASTEROPHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 error = "NORASTEROPHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 case DDERR_NOSTRETCHHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 error = "NOSTRETCHHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 case DDERR_NOTAOVERLAYSURFACE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 error = "NOTAOVERLAYSURFACE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 case DDERR_NOTFLIPPABLE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 error = "NOTFLIPPABLE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 case DDERR_NOTFOUND:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 error = "NOTFOUND";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 case DDERR_NOTLOCKED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 error = "NOTLOCKED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 case DDERR_NOTPALETTIZED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 error = "NOTPALETTIZED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 case DDERR_NOVSYNCHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 error = "NOVSYNCHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 case DDERR_NOZOVERLAYHW:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 error = "NOZOVERLAYHW";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 case DDERR_OUTOFCAPS:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 error = "OUTOFCAPS";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 case DDERR_OUTOFMEMORY:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 error = "OUTOFMEMORY";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 case DDERR_OUTOFVIDEOMEMORY:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 error = "OUTOFVIDEOMEMORY";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 case DDERR_OVERLAPPINGRECTS:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 error = "OVERLAPPINGRECTS";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 case DDERR_OVERLAYNOTVISIBLE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 error = "OVERLAYNOTVISIBLE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 case DDERR_PALETTEBUSY:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 error = "PALETTEBUSY";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 case DDERR_PRIMARYSURFACEALREADYEXISTS:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 error = "PRIMARYSURFACEALREADYEXISTS";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 case DDERR_REGIONTOOSMALL:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 error = "REGIONTOOSMALL";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 case DDERR_SURFACEBUSY:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 error = "SURFACEBUSY";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 case DDERR_SURFACELOST:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 error = "SURFACELOST";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 case DDERR_TOOBIGHEIGHT:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 error = "TOOBIGHEIGHT";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 case DDERR_TOOBIGSIZE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 error = "TOOBIGSIZE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 case DDERR_TOOBIGWIDTH:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 error = "TOOBIGWIDTH";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 case DDERR_UNSUPPORTED:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 error = "UNSUPPORTED";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 case DDERR_UNSUPPORTEDFORMAT:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 error = "UNSUPPORTEDFORMAT";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 case DDERR_VERTICALBLANKINPROGRESS:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 error = "VERTICALBLANKINPROGRESS";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 case DDERR_VIDEONOTACTIVE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 error = "VIDEONOTACTIVE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 case DDERR_WASSTILLDRAWING:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 error = "WASSTILLDRAWING";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 case DDERR_WRONGMODE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 error = "WRONGMODE";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 error = "UNKNOWN";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 SDL_SetError("%s: %s", prefix, error);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 static SDL_bool
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 PixelFormatToDDPIXELFORMAT(Uint32 format, LPDDPIXELFORMAT dst)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 SDL_zerop(dst);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 dst->dwSize = sizeof(*dst);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 if (SDL_ISPIXELFORMAT_FOURCC(format)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 dst->dwFlags = DDPF_FOURCC;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 dst->dwFourCC = format;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 } else if (SDL_ISPIXELFORMAT_INDEXED(format)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 SDL_SetError("Indexed pixelformats are not supported.");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 return SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 int bpp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 Uint32 Rmask, Gmask, Bmask, Amask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 if (!SDL_PixelFormatEnumToMasks
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 SDL_SetError("pixelformat not supported");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 return SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 if (!Rmask && !Gmask && !Bmask) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 dst->dwFlags = DDPF_ALPHA;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 dst->dwAlphaBitDepth = bpp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 dst->dwFlags = DDPF_RGB;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 dst->dwRGBBitCount = bpp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 dst->dwRBitMask = Rmask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 dst->dwGBitMask = Gmask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 dst->dwBBitMask = Bmask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 if (Amask) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 dst->dwFlags |= DDPF_ALPHAPIXELS;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 dst->dwRGBAlphaBitMask = Amask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 return SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 static SDL_bool
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 DDRAW_IsTextureFormatAvailable(IDirectDraw * ddraw, Uint32 display_format,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 Uint32 texture_format)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 int bpp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 Uint32 Rmask, Gmask, Bmask, Amask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 if (SDL_ISPIXELFORMAT_FOURCC(texture_format)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 //TODO I don't expect DDRAW to support all 4CC formats, but I don't know which ones
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 return SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 //These are only basic checks
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 if (SDL_ISPIXELFORMAT_INDEXED(texture_format)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 return SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 if (!SDL_PixelFormatEnumToMasks
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 (texture_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 return SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 switch (bpp) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 case 4:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 case 8:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 case 16:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 case 24:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 case 32:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 return SDL_FALSE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 return SDL_TRUE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 DDRAW_AddRenderDriver(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 SDL_RendererInfo *info = &DDRAW_RenderDriver.info;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
394 SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 if (data->ddraw) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 int i;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 int formats[] = {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 SDL_PIXELFORMAT_INDEX8,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 SDL_PIXELFORMAT_RGB332,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 SDL_PIXELFORMAT_RGB444,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 SDL_PIXELFORMAT_RGB555,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 SDL_PIXELFORMAT_ARGB4444,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 SDL_PIXELFORMAT_ARGB1555,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 SDL_PIXELFORMAT_RGB565,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 SDL_PIXELFORMAT_RGB888,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 SDL_PIXELFORMAT_ARGB8888,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 SDL_PIXELFORMAT_ARGB2101010,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 for (i = 0; i < SDL_arraysize(formats); ++i) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 if (DDRAW_IsTextureFormatAvailable
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 (data->ddraw, mode->format, formats[i])) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 formats[i];
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 //TODO the fourcc formats should get fetched from IDirectDraw::GetFourCCCodes
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 SDL_PIXELFORMAT_YV12;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 SDL_PIXELFORMAT_IYUV;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 SDL_PIXELFORMAT_YUY2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 SDL_PIXELFORMAT_UYVY;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 SDL_PIXELFORMAT_YVYU;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430
3520
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
431 for (i = 0; i < _this->num_displays; ++i)
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
432 SDL_AddRenderDriver(&_this->displays[i], &DDRAW_RenderDriver);
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
433 }
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 SDL_Renderer *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
440 SDL_VideoDisplay *display = window->display;
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 SDL_Renderer *renderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 DDRAW_RenderData *data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 DDSURFACEDESC ddsd;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 if (!renderer) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 data = (DDRAW_RenderData *) SDL_calloc(1, sizeof(*data));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 data->ddraw = videodata->ddraw;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461
4569
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
462 videodata->render = RENDER_DDRAW;
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
463
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 renderer->DisplayModeChanged = DDRAW_DisplayModeChanged;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 renderer->CreateTexture = DDRAW_CreateTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 renderer->QueryTexturePixels = DDRAW_QueryTexturePixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 renderer->SetTextureColorMod = DDRAW_SetTextureColorMod;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 renderer->SetTextureAlphaMod = DDRAW_SetTextureAlphaMod;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 renderer->SetTextureBlendMode = DDRAW_SetTextureBlendMode;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 renderer->SetTextureScaleMode = DDRAW_SetTextureScaleMode;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 renderer->UpdateTexture = DDRAW_UpdateTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 renderer->LockTexture = DDRAW_LockTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 renderer->UnlockTexture = DDRAW_UnlockTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 renderer->DirtyTexture = DDRAW_DirtyTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 renderer->RenderPoint = DDRAW_RenderPoint;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 renderer->RenderLine = DDRAW_RenderLine;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 renderer->RenderFill = DDRAW_RenderFill;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 renderer->RenderCopy = DDRAW_RenderCopy;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 renderer->RenderPresent = DDRAW_RenderPresent;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 renderer->DestroyTexture = DDRAW_DestroyTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 renderer->DestroyRenderer = DDRAW_DestroyRenderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 renderer->info = DDRAW_RenderDriver.info;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
484 renderer->window = window;
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 renderer->driverdata = data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 renderer->info.flags = SDL_RENDERER_ACCELERATED;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 SDL_zero(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 ddsd.dwSize = sizeof(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 ddsd.dwFlags = DDSD_CAPS;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 if (window->flags & SDL_WINDOW_FULLSCREEN) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 //TODO handle non fullscreen
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 SDL_SetError("DirectDraw renderer has only fullscreen implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 if (flags & SDL_RENDERER_PRESENTFLIP2) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 ddsd.dwBackBufferCount = 2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 ddsd.dwBackBufferCount = 3;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 } else if (flags & SDL_RENDERER_PRESENTCOPY) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 //TODO what is the best approximation to this mode
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 if (flags & SDL_RENDERER_PRESENTVSYNC) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 SDL_SetError("DirectDraw renderer with v-sync is not implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 data->ddraw->lpVtbl->SetCooperativeLevel(data->ddraw,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 windowdata->hwnd,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 DDSCL_NORMAL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 DDRAW_SetError("CreateDevice()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 data->ddraw->lpVtbl->CreateSurface(data->ddraw, &ddsd, &data->primary,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 DDRAW_SetError("CreateDevice()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 return renderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 DDRAW_Reset(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 result = IDirect3DDevice9_Reset(data->device, &data->pparams);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 if (FAILED(result)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 if (result == D3DERR_DEVICELOST) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 /* Don't worry about it, we'll reset later... *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 D3D_SetError("Reset()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 IDirect3DDevice9_SetVertexShader(data->device, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 IDirect3DDevice9_SetFVF(data->device,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 D3DCULL_NONE);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 DDRAW_DisplayModeChanged(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
573 SDL_Window *window = renderer->window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
574 SDL_VideoDisplay *display = window->display;
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 data->pparams.BackBufferWidth = window->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 data->pparams.BackBufferHeight = window->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 if (window->flags & SDL_WINDOW_FULLSCREEN) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 data->pparams.BackBufferFormat =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 PixelFormatToD3DFMT(display->fullscreen_mode.format);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 return D3D_Reset(renderer); */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 DDRAW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 DDRAW_RenderData *renderdata = (DDRAW_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
592 SDL_Window *window = renderer->window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
593 SDL_VideoDisplay *display = window->display;
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 Uint32 display_format = display->current_mode.format;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 DDRAW_TextureData *data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 DDSURFACEDESC ddsd;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 data = (DDRAW_TextureData *) SDL_calloc(1, sizeof(*data));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 SDL_zero(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 ddsd.dwSize = sizeof(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_HEIGHT | DDSD_WIDTH;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 ddsd.dwWidth = texture->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 ddsd.dwHeight = texture->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 if (!PixelFormatToDDPIXELFORMAT(texture->format, &ddsd.ddpfPixelFormat)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 texture->driverdata = data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 renderdata->ddraw->lpVtbl->CreateSurface(renderdata->ddraw, &ddsd,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 &data->surface, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 DDRAW_SetError("CreateTexture", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632 DDRAW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 void **pixels, int *pitch)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 SDL_SetError("QueryTexturePixels is not implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641 DDRAW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647 DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
651
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653 DDRAW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
655 switch (texture->blendMode) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 case SDL_BLENDMODE_NONE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
657 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
658 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
659 SDL_Unsupported();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
660 texture->blendMode = SDL_BLENDMODE_NONE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
661 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
662 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
663 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 DDRAW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
668 switch (texture->scaleMode) {
4929
aa8888658021 Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents: 4569
diff changeset
669 case SDL_SCALEMODE_NONE:
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 SDL_Unsupported();
4929
aa8888658021 Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents: 4569
diff changeset
672 texture->scaleMode = SDL_SCALEMODE_NONE;
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
678 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679 DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680 const SDL_Rect * rect, const void *pixels, int pitch)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
683
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
684 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685 SDL_SetError("UpdateTexture is not implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
687 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
689 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690 DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
691 const SDL_Rect * rect, int markDirty, void **pixels,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692 int *pitch)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
694 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
696 DDSURFACEDESC ddsd;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
697
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
698 SDL_zero(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
699 ddsd.dwSize = sizeof(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
700
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
701 /**
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
702 * On a Axim x51v locking a subrect returns the startaddress of the whole surface,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
703 * wheras on my ASUS MyPal 696 the startaddress of the locked area is returned,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704 * thats why I always lock the whole surface and calculate the pixels pointer by hand.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
705 * This shouldn't be a speed problem, as multiple locks aren't available on DDraw Mobile
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
706 * see http://msdn.microsoft.com/en-us/library/ms858221.aspx
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
707 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
708
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
709 result = data->surface->lpVtbl->Lock(data->surface, NULL, &ddsd, 0, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
710 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
711 DDRAW_SetError("LockRect()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
712 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
713 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
714
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
715 *pixels = ddsd.lpSurface + rect->y * ddsd.lPitch + rect->x * ddsd.lXPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
716 *pitch = ddsd.lPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
717 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
718 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
719
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
720 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
721 DDRAW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
722 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
723 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
724
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725 data->surface->lpVtbl->Unlock(data->surface, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
726 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
727
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
728 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
729 DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
730 int numrects, const SDL_Rect * rects)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
731 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
732 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
733
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
734 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
735 DDRAW_SetBlendMode(DDRAW_RenderData * data, int blendMode)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
736 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
737 switch (blendMode) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
738
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
739 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
740 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
741
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
742 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
743 DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
744 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
745 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
746 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
747
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
748 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
749 DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
750 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
751 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
752 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
753
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
754 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
755 DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
756 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
757 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
758 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
759
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
761 DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
762 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
763 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
764 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
765 DDRAW_TextureData *texturedata =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766 (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
767 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768 RECT srcr;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769 RECT dstr;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
770 DDBLTFX bltfx;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
771
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772 srcr.left = srcrect->x;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
773 srcr.top = srcrect->y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
774 srcr.right = srcrect->x + srcrect->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
775 srcr.bottom = srcrect->y + srcrect->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
776
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
777 dstr.left = dstrect->x;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
778 dstr.top = dstrect->y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779 dstr.right = dstrect->x + dstrect->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
780 dstr.bottom = dstrect->y + dstrect->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
781
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
782 SDL_zero(bltfx);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
783 bltfx.dwSize = sizeof(bltfx);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
784 bltfx.dwROP = SRCCOPY;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
785
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
786 data->primary->lpVtbl->Blt(data->primary, &dstr, texturedata->surface,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
787 &srcr, DDBLT_ROP, &bltfx);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
789 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
790 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
791
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
792 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793 DDRAW_RenderPresent(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
794 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
796 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
797
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
798 return;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
799
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
800 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801 data->primary->lpVtbl->Flip(data->primary, NULL, DDFLIP_INTERVAL1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
802 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
803 DDRAW_SetError("Present()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
804 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
805 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
806
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 DDRAW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
809 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
811
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
812 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813 return;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
815
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
816 data->surface->lpVtbl->Release(data->surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818 texture->driverdata = NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
822 DDRAW_DestroyRenderer(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
824 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
825
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
826 if (data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827 data->primary->lpVtbl->Release(data->primary);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
828 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
829 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
830 SDL_free(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
832
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
833 #endif /* SDL_VIDEO_RENDER_DDRAW */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
834
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
835 /* vi: set ts=4 sw=4 expandtab: */