annotate src/video/win32/SDL_ceddrawrender.c @ 3280:00cace2d9080

Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
author Sam Lantinga <slouken@libsdl.org>
date Sat, 19 Sep 2009 13:29:40 +0000
parents 6338b7f2d024
children 83518f8fcd61
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
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
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
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "SDL_win32video.h"
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),
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 (SDL_TEXTURESCALEMODE_NONE),
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;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 SDL_DisplayMode *mode = &SDL_CurrentDisplay.desktop_mode;
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
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 SDL_AddRenderDriver(0, &DDRAW_RenderDriver);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 SDL_Renderer *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 SDL_Renderer *renderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 DDRAW_RenderData *data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 DDSURFACEDESC ddsd;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 if (!renderer) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 data = (DDRAW_RenderData *) SDL_calloc(1, sizeof(*data));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 data->ddraw = videodata->ddraw;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 renderer->DisplayModeChanged = DDRAW_DisplayModeChanged;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 renderer->CreateTexture = DDRAW_CreateTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 renderer->QueryTexturePixels = DDRAW_QueryTexturePixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 renderer->SetTextureColorMod = DDRAW_SetTextureColorMod;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 renderer->SetTextureAlphaMod = DDRAW_SetTextureAlphaMod;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 renderer->SetTextureBlendMode = DDRAW_SetTextureBlendMode;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 renderer->SetTextureScaleMode = DDRAW_SetTextureScaleMode;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 renderer->UpdateTexture = DDRAW_UpdateTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 renderer->LockTexture = DDRAW_LockTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 renderer->UnlockTexture = DDRAW_UnlockTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 renderer->DirtyTexture = DDRAW_DirtyTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 renderer->RenderPoint = DDRAW_RenderPoint;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 renderer->RenderLine = DDRAW_RenderLine;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 renderer->RenderFill = DDRAW_RenderFill;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 renderer->RenderCopy = DDRAW_RenderCopy;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 renderer->RenderPresent = DDRAW_RenderPresent;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 renderer->DestroyTexture = DDRAW_DestroyTexture;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 renderer->DestroyRenderer = DDRAW_DestroyRenderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 renderer->info = DDRAW_RenderDriver.info;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 renderer->window = window->id;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 renderer->driverdata = data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 renderer->info.flags = SDL_RENDERER_ACCELERATED;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 SDL_zero(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 ddsd.dwSize = sizeof(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 ddsd.dwFlags = DDSD_CAPS;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 if (window->flags & SDL_WINDOW_FULLSCREEN) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 //TODO handle non fullscreen
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 SDL_SetError("DirectDraw renderer has only fullscreen implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 if (flags & SDL_RENDERER_PRESENTFLIP2) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 ddsd.dwBackBufferCount = 2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 ddsd.dwBackBufferCount = 3;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 } else if (flags & SDL_RENDERER_PRESENTCOPY) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 //TODO what is the best approximation to this mode
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 if (flags & SDL_RENDERER_PRESENTVSYNC) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 SDL_SetError("DirectDraw renderer with v-sync is not implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 data->ddraw->lpVtbl->SetCooperativeLevel(data->ddraw,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 windowdata->hwnd,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 DDSCL_NORMAL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 DDRAW_SetError("CreateDevice()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 data->ddraw->lpVtbl->CreateSurface(data->ddraw, &ddsd, &data->primary,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 DDRAW_SetError("CreateDevice()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 DDRAW_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 return renderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 DDRAW_Reset(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 result = IDirect3DDevice9_Reset(data->device, &data->pparams);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 if (FAILED(result)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 if (result == D3DERR_DEVICELOST) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 /* Don't worry about it, we'll reset later... *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 D3D_SetError("Reset()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 IDirect3DDevice9_SetVertexShader(data->device, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 IDirect3DDevice9_SetFVF(data->device,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 D3DCULL_NONE);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 DDRAW_DisplayModeChanged(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 data->pparams.BackBufferWidth = window->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 data->pparams.BackBufferHeight = window->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 if (window->flags & SDL_WINDOW_FULLSCREEN) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 data->pparams.BackBufferFormat =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 PixelFormatToD3DFMT(display->fullscreen_mode.format);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 return D3D_Reset(renderer); */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 DDRAW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 DDRAW_RenderData *renderdata = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 Uint32 display_format = display->current_mode.format;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 DDRAW_TextureData *data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 DDSURFACEDESC ddsd;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 data = (DDRAW_TextureData *) SDL_calloc(1, sizeof(*data));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 SDL_zero(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 ddsd.dwSize = sizeof(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_HEIGHT | DDSD_WIDTH;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 ddsd.dwWidth = texture->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 ddsd.dwHeight = texture->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 if (!PixelFormatToDDPIXELFORMAT(texture->format, &ddsd.ddpfPixelFormat)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 texture->driverdata = data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 renderdata->ddraw->lpVtbl->CreateSurface(renderdata->ddraw, &ddsd,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 &data->surface, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 DDRAW_SetError("CreateTexture", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 DDRAW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 void **pixels, int *pitch)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632 SDL_SetError("QueryTexturePixels is not implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 DDRAW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649 DDRAW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
651 switch (texture->blendMode) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 case SDL_BLENDMODE_NONE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
655 SDL_Unsupported();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 texture->blendMode = SDL_BLENDMODE_NONE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
657 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
658 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
659 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
660
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
661 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
662 DDRAW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
663 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664 switch (texture->scaleMode) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665 case SDL_TEXTURESCALEMODE_NONE:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 SDL_Unsupported();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
668 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675 DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 const SDL_Rect * rect, const void *pixels, int pitch)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
678 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 SDL_SetError("UpdateTexture is not implemented");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
683 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
684
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686 DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
687 const SDL_Rect * rect, int markDirty, void **pixels,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688 int *pitch)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
689 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
691 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692 DDSURFACEDESC ddsd;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
694 SDL_zero(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695 ddsd.dwSize = sizeof(ddsd);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
696
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
697 /**
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
698 * On a Axim x51v locking a subrect returns the startaddress of the whole surface,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
699 * wheras on my ASUS MyPal 696 the startaddress of the locked area is returned,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
700 * thats why I always lock the whole surface and calculate the pixels pointer by hand.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
701 * This shouldn't be a speed problem, as multiple locks aren't available on DDraw Mobile
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
702 * see http://msdn.microsoft.com/en-us/library/ms858221.aspx
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
703 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
705 result = data->surface->lpVtbl->Lock(data->surface, NULL, &ddsd, 0, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
706 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
707 DDRAW_SetError("LockRect()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
708 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
709 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
710
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
711 *pixels = ddsd.lpSurface + rect->y * ddsd.lPitch + rect->x * ddsd.lXPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
712 *pitch = ddsd.lPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
713 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
714 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
715
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
716 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
717 DDRAW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
718 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
719 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
720
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
721 data->surface->lpVtbl->Unlock(data->surface, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
722 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
723
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
724 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725 DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
726 int numrects, const SDL_Rect * rects)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
727 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
728 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
729
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
730 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
731 DDRAW_SetBlendMode(DDRAW_RenderData * data, int blendMode)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
732 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
733 switch (blendMode) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
734
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
735 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
736 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
737
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
738 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
739 DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
740 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
741 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
742 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
743
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
744 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
745 DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
746 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
747 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
748 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
749
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
750 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
751 DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
752 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
753 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
754 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
755
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
756 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
757 DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
758 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
759 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
761 DDRAW_TextureData *texturedata =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
762 (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
763 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
764 RECT srcr;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
765 RECT dstr;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766 DDBLTFX bltfx;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
767
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768 srcr.left = srcrect->x;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769 srcr.top = srcrect->y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
770 srcr.right = srcrect->x + srcrect->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
771 srcr.bottom = srcrect->y + srcrect->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
773 dstr.left = dstrect->x;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
774 dstr.top = dstrect->y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
775 dstr.right = dstrect->x + dstrect->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
776 dstr.bottom = dstrect->y + dstrect->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
777
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
778 SDL_zero(bltfx);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779 bltfx.dwSize = sizeof(bltfx);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
780 bltfx.dwROP = SRCCOPY;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
781
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
782 data->primary->lpVtbl->Blt(data->primary, &dstr, texturedata->surface,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
783 &srcr, DDBLT_ROP, &bltfx);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
784
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
785 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
786 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
787
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
789 DDRAW_RenderPresent(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
790 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
791 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
792 HRESULT result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
794 return;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
796 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
797 data->primary->lpVtbl->Flip(data->primary, NULL, DDFLIP_INTERVAL1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
798 if (result != DD_OK) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
799 DDRAW_SetError("Present()", result);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
800 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
802
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
803 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
804 DDRAW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
805 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
806 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
809 return;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
811
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
812 data->surface->lpVtbl->Release(data->surface);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 texture->driverdata = NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
815 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
816
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818 DDRAW_DestroyRenderer(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
822 if (data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 data->primary->lpVtbl->Release(data->primary);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
824 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
825 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
826 SDL_free(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
828
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
829 #endif /* SDL_VIDEO_RENDER_DDRAW */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
830
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831 /* vi: set ts=4 sw=4 expandtab: */