Commit 32593c2b authored by Sam Lantinga's avatar Sam Lantinga

Fixed Direct3D rendering

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403244
parent 4123b08d
...@@ -27,6 +27,14 @@ ...@@ -27,6 +27,14 @@
/* Direct3D renderer implementation */ /* Direct3D renderer implementation */
#if 1 /* This takes more memory but you won't lose your texture data */
#define D3DPOOL_SDL D3DPOOL_MANAGED
#define SDL_MEMORY_POOL_MANAGED
#else
#define D3DPOOL_SDL D3DPOOL_DEFAULT
#define SDL_MEMORY_POOL_DEFAULT
#endif
static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags); static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
static int D3D_DisplayModeChanged(SDL_Renderer * renderer); static int D3D_DisplayModeChanged(SDL_Renderer * renderer);
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
...@@ -473,7 +481,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -473,7 +481,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w, IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
texture->h, 1, 0, texture->h, 1, 0,
PixelFormatToD3DFMT(texture->format), PixelFormatToD3DFMT(texture->format),
D3DPOOL_MANAGED, &data->texture, NULL); D3DPOOL_SDL, &data->texture, NULL);
if (FAILED(result)) { if (FAILED(result)) {
D3D_SetError("CreateTexture()", result); D3D_SetError("CreateTexture()", result);
return -1; return -1;
...@@ -547,6 +555,7 @@ D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -547,6 +555,7 @@ D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
return 0; return 0;
} }
#ifdef SDL_MEMORY_POOL_DEFAULT
static int static int
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch) const SDL_Rect * rect, const void *pixels, int pitch)
...@@ -605,6 +614,43 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -605,6 +614,43 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
} }
return 0; return 0;
} }
#else
static int
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
RECT d3drect;
D3DLOCKED_RECT locked;
const Uint8 *src;
Uint8 *dst;
int row, length;
HRESULT result;
d3drect.left = rect->x;
d3drect.right = rect->x + rect->w;
d3drect.top = rect->y;
d3drect.bottom = rect->y + rect->h;
result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
if (FAILED(result)) {
D3D_SetError("LockRect()", result);
return -1;
}
src = pixels;
dst = locked.pBits;
length = rect->w * SDL_BYTESPERPIXEL(texture->format);
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += locked.Pitch;
}
IDirect3DTexture9_UnlockRect(data->texture, 0);
return 0;
}
#endif // SDL_MEMORY_POOL_DEFAULT
static int static int
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
......
...@@ -83,7 +83,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) ...@@ -83,7 +83,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
{ {
int i, n; int i, n;
int window_w, window_h; int window_w, window_h;
SDL_Rect area, *position, *velocity; SDL_Rect *position, *velocity;
SDL_SelectRenderer(window); SDL_SelectRenderer(window);
...@@ -291,8 +291,8 @@ main(int argc, char *argv[]) ...@@ -291,8 +291,8 @@ main(int argc, char *argv[])
/* Print out some timing information */ /* Print out some timing information */
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
printf("%2.2f frames per second\n", double fps = ((double) frames * 1000) / (now - then);
((double) frames * 1000) / (now - then)); printf("%2.2f frames per second\n", fps);
} }
quit(0); quit(0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment