annotate src/video/win32/SDL_ceddrawrender.c @ 4785:ef8b32ef9793

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