comparison src/video/win32/SDL_d3drender.c @ 3427:36cf454ba065

Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 09 Nov 2009 05:20:11 +0000
parents fd207dce9f94
children cd763d104465
comparison
equal deleted inserted replaced
3426:ee0178f1c507 3427:36cf454ba065
70 static int D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, 70 static int D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
71 int y2); 71 int y2);
72 static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); 72 static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
73 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 73 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
74 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 74 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
75 static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
76 void * pixels, int pitch);
75 static void D3D_RenderPresent(SDL_Renderer * renderer); 77 static void D3D_RenderPresent(SDL_Renderer * renderer);
76 static void D3D_DestroyTexture(SDL_Renderer * renderer, 78 static void D3D_DestroyTexture(SDL_Renderer * renderer,
77 SDL_Texture * texture); 79 SDL_Texture * texture);
78 static void D3D_DestroyRenderer(SDL_Renderer * renderer); 80 static void D3D_DestroyRenderer(SDL_Renderer * renderer);
79 81
365 renderer->DirtyTexture = D3D_DirtyTexture; 367 renderer->DirtyTexture = D3D_DirtyTexture;
366 renderer->RenderPoint = D3D_RenderPoint; 368 renderer->RenderPoint = D3D_RenderPoint;
367 renderer->RenderLine = D3D_RenderLine; 369 renderer->RenderLine = D3D_RenderLine;
368 renderer->RenderFill = D3D_RenderFill; 370 renderer->RenderFill = D3D_RenderFill;
369 renderer->RenderCopy = D3D_RenderCopy; 371 renderer->RenderCopy = D3D_RenderCopy;
372 renderer->RenderReadPixels = D3D_RenderReadPixels;
370 renderer->RenderPresent = D3D_RenderPresent; 373 renderer->RenderPresent = D3D_RenderPresent;
371 renderer->DestroyTexture = D3D_DestroyTexture; 374 renderer->DestroyTexture = D3D_DestroyTexture;
372 renderer->DestroyRenderer = D3D_DestroyRenderer; 375 renderer->DestroyRenderer = D3D_DestroyRenderer;
373 renderer->info = D3D_RenderDriver.info; 376 renderer->info = D3D_RenderDriver.info;
374 renderer->window = window->id; 377 renderer->window = window->id;
1143 return -1; 1146 return -1;
1144 } 1147 }
1145 return 0; 1148 return 0;
1146 } 1149 }
1147 1150
1151 static int
1152 D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1153 void * pixels, int pitch)
1154 {
1155 BYTE * pBytes;
1156 D3DLOCKED_RECT lockedRect;
1157 BYTE b, g, r, a;
1158 unsigned long index;
1159 int cur_mouse;
1160 int x, y;
1161
1162 LPDIRECT3DSURFACE9 backBuffer;
1163 LPDIRECT3DSURFACE9 pickOffscreenSurface;
1164 D3DSURFACE_DESC desc;
1165
1166 D3D_RenderData * data = (D3D_RenderData *) renderer->driverdata;
1167
1168 IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
1169
1170
1171 IDirect3DSurface9_GetDesc(backBuffer, &desc);
1172
1173 IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pickOffscreenSurface, NULL);
1174
1175 IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, pickOffscreenSurface);
1176
1177 IDirect3DSurface9_LockRect(pickOffscreenSurface, &lockedRect, NULL, D3DLOCK_READONLY);
1178 pBytes = (BYTE*)lockedRect.pBits;
1179 IDirect3DSurface9_UnlockRect(pickOffscreenSurface);
1180
1181 // just to debug -->
1182 cur_mouse = SDL_SelectMouse(-1);
1183 SDL_GetMouseState(cur_mouse, &x, &y);
1184 index = (x * 4 + (y * lockedRect.Pitch));
1185
1186 b = pBytes[index];
1187 g = pBytes[index+1];
1188 r = pBytes[index+2];
1189 a = pBytes[index+3];
1190 // <--
1191
1192 return -1;
1193 }
1194
1148 static void 1195 static void
1149 D3D_RenderPresent(SDL_Renderer * renderer) 1196 D3D_RenderPresent(SDL_Renderer * renderer)
1150 { 1197 {
1151 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; 1198 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1152 HRESULT result; 1199 HRESULT result;