comparison src/video/win32/SDL_d3drender.c @ 3549:686f0e69cd37

Finished implementing RenderReadPixels()
author Sam Lantinga <slouken@libsdl.org>
date Sat, 12 Dec 2009 04:01:40 +0000
parents 0267b8b1595c
children 4a39f28cd935
comparison
equal deleted inserted replaced
3548:79af7b478fae 3549:686f0e69cd37
1204 1204
1205 static int 1205 static int
1206 D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, 1206 D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1207 Uint32 format, void * pixels, int pitch) 1207 Uint32 format, void * pixels, int pitch)
1208 { 1208 {
1209 BYTE * pBytes; 1209 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1210 D3DLOCKED_RECT lockedRect; 1210 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1211 BYTE b, g, r, a; 1211 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1212 unsigned long index; 1212 D3DSURFACE_DESC desc;
1213 int cur_mouse;
1214 int x, y;
1215
1216 LPDIRECT3DSURFACE9 backBuffer; 1213 LPDIRECT3DSURFACE9 backBuffer;
1217 LPDIRECT3DSURFACE9 pickOffscreenSurface; 1214 LPDIRECT3DSURFACE9 surface;
1218 D3DSURFACE_DESC desc; 1215 RECT d3drect;
1219 1216 D3DLOCKED_RECT locked;
1220 D3D_RenderData * data = (D3D_RenderData *) renderer->driverdata; 1217 HRESULT result;
1221 1218
1222 IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); 1219 result = IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
1223 1220 if (FAILED(result)) {
1224 1221 D3D_SetError("GetBackBuffer()", result);
1225 IDirect3DSurface9_GetDesc(backBuffer, &desc); 1222 return -1;
1226 1223 }
1227 IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pickOffscreenSurface, NULL); 1224
1228 1225 result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
1229 IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, pickOffscreenSurface); 1226 if (FAILED(result)) {
1230 1227 D3D_SetError("GetDesc()", result);
1231 IDirect3DSurface9_LockRect(pickOffscreenSurface, &lockedRect, NULL, D3DLOCK_READONLY); 1228 IDirect3DSurface9_Release(backBuffer);
1232 pBytes = (BYTE*)lockedRect.pBits; 1229 return -1;
1233 IDirect3DSurface9_UnlockRect(pickOffscreenSurface); 1230 }
1234 1231
1235 // just to debug --> 1232 result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
1236 cur_mouse = SDL_SelectMouse(-1); 1233 if (FAILED(result)) {
1237 SDL_GetMouseState(cur_mouse, &x, &y); 1234 D3D_SetError("CreateOffscreenPlainSurface()", result);
1238 index = (x * 4 + (y * lockedRect.Pitch)); 1235 IDirect3DSurface9_Release(backBuffer);
1239 1236 return -1;
1240 b = pBytes[index]; 1237 }
1241 g = pBytes[index+1]; 1238
1242 r = pBytes[index+2]; 1239 result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface);
1243 a = pBytes[index+3]; 1240 if (FAILED(result)) {
1244 // <-- 1241 D3D_SetError("GetRenderTargetData()", result);
1245 1242 IDirect3DSurface9_Release(surface);
1246 return -1; 1243 IDirect3DSurface9_Release(backBuffer);
1244 return -1;
1245 }
1246
1247 d3drect.left = rect->x;
1248 d3drect.right = rect->x + rect->w;
1249 d3drect.top = rect->y;
1250 d3drect.bottom = rect->y + rect->h;
1251
1252 result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
1253 if (FAILED(result)) {
1254 D3D_SetError("LockRect()", result);
1255 IDirect3DSurface9_Release(surface);
1256 IDirect3DSurface9_Release(backBuffer);
1257 return -1;
1258 }
1259
1260 SDL_ConvertPixels(rect->w, rect->h,
1261 display->current_mode.format, locked.pBits, locked.Pitch,
1262 format, pixels, pitch);
1263
1264 IDirect3DSurface9_UnlockRect(surface);
1265
1266 IDirect3DSurface9_Release(surface);
1267 IDirect3DSurface9_Release(backBuffer);
1268
1269 return 0;
1247 } 1270 }
1248 1271
1249 static int 1272 static int
1250 D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, 1273 D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1251 Uint32 format, const void * pixels, int pitch) 1274 Uint32 format, const void * pixels, int pitch)