annotate src/video/win32/SDL_d3drender.c @ 3519:1374f9275de9

Fixed compiling the D3D renderer
author Sam Lantinga <slouken@libsdl.org>
date Fri, 04 Dec 2009 08:26:32 +0000
parents 1b22878e04d0
children 83518f8fcd61
rev   line source
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #if SDL_VIDEO_RENDER_D3D
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "SDL_win32video.h"
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
27 #include "../SDL_yuv_sw_c.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 /* Direct3D renderer implementation */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2783
diff changeset
31 #if 1 /* This takes more memory but you won't lose your texture data */
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
32 #define D3DPOOL_SDL D3DPOOL_MANAGED
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
33 #define SDL_MEMORY_POOL_MANAGED
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
34 #else
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
35 #define D3DPOOL_SDL D3DPOOL_DEFAULT
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
36 #define SDL_MEMORY_POOL_DEFAULT
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
37 #endif
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
38
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
39 static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
40 static int D3D_DisplayModeChanged(SDL_Renderer * renderer);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
41 static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
42 static int D3D_QueryTexturePixels(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
43 SDL_Texture * texture, void **pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
44 int *pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
45 static int D3D_SetTexturePalette(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
46 SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
47 const SDL_Color * colors, int firstcolor,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
48 int ncolors);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
49 static int D3D_GetTexturePalette(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
50 SDL_Texture * texture, SDL_Color * colors,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
51 int firstcolor, int ncolors);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
52 static int D3D_SetTextureColorMod(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
53 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
54 static int D3D_SetTextureAlphaMod(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
55 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
56 static int D3D_SetTextureBlendMode(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
57 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
58 static int D3D_SetTextureScaleMode(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
59 SDL_Texture * texture);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
60 static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
61 const SDL_Rect * rect, const void *pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
62 int pitch);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
63 static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
64 const SDL_Rect * rect, int markDirty,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
65 void **pixels, int *pitch);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
66 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
67 static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
68 int numrects, const SDL_Rect * rects);
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
69 static int D3D_RenderPoint(SDL_Renderer * renderer, int x, int y);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
70 static int D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
71 int y2);
2919
2f91a3847ae8 Fixed compiling Windows renderers. Lines and points will be implemented later.
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
72 static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
73 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
74 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
3427
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
75 static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3480
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
76 Uint32 format, void * pixels, int pitch);
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
77 static int D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
78 Uint32 format, const void * pixels, int pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
79 static void D3D_RenderPresent(SDL_Renderer * renderer);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
80 static void D3D_DestroyTexture(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
81 SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
82 static void D3D_DestroyRenderer(SDL_Renderer * renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
85 SDL_RenderDriver D3D_RenderDriver = {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
86 D3D_CreateRenderer,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 "d3d",
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
89 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
90 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
91 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC |
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
92 SDL_RENDERER_ACCELERATED),
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
93 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
94 SDL_TEXTUREMODULATE_ALPHA),
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
95 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
96 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
97 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
98 SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
2972
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
99 0,
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
100 {0},
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 0,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 0}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 };
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 {
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
107 IDirect3D9 *d3d;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 IDirect3DDevice9 *device;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
109 D3DPRESENT_PARAMETERS pparams;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
110 SDL_bool beginScene;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
111 } D3D_RenderData;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 {
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
115 SDL_SW_YUVTexture *yuv;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
116 Uint32 format;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
117 IDirect3DTexture9 *texture;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
118 } D3D_TextureData;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
120 typedef struct
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
121 {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
122 float x, y, z;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
123 float rhw;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
124 DWORD color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
125 float u, v;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
126 } Vertex;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
127
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 static void
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
129 D3D_SetError(const char *prefix, HRESULT result)
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
130 {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
131 const char *error;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
132
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
133 switch (result) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
134 case D3DERR_WRONGTEXTUREFORMAT:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
135 error = "WRONGTEXTUREFORMAT";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
136 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
137 case D3DERR_UNSUPPORTEDCOLOROPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
138 error = "UNSUPPORTEDCOLOROPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
139 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
140 case D3DERR_UNSUPPORTEDCOLORARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
141 error = "UNSUPPORTEDCOLORARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
142 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
143 case D3DERR_UNSUPPORTEDALPHAOPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
144 error = "UNSUPPORTEDALPHAOPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
145 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
146 case D3DERR_UNSUPPORTEDALPHAARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
147 error = "UNSUPPORTEDALPHAARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
148 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
149 case D3DERR_TOOMANYOPERATIONS:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
150 error = "TOOMANYOPERATIONS";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
151 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
152 case D3DERR_CONFLICTINGTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
153 error = "CONFLICTINGTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
154 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
155 case D3DERR_UNSUPPORTEDFACTORVALUE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
156 error = "UNSUPPORTEDFACTORVALUE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
157 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
158 case D3DERR_CONFLICTINGRENDERSTATE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
159 error = "CONFLICTINGRENDERSTATE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
160 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
161 case D3DERR_UNSUPPORTEDTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
162 error = "UNSUPPORTEDTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
163 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
164 case D3DERR_CONFLICTINGTEXTUREPALETTE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
165 error = "CONFLICTINGTEXTUREPALETTE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
166 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
167 case D3DERR_DRIVERINTERNALERROR:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
168 error = "DRIVERINTERNALERROR";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
169 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
170 case D3DERR_NOTFOUND:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
171 error = "NOTFOUND";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
172 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
173 case D3DERR_MOREDATA:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
174 error = "MOREDATA";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
175 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
176 case D3DERR_DEVICELOST:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
177 error = "DEVICELOST";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
178 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
179 case D3DERR_DEVICENOTRESET:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
180 error = "DEVICENOTRESET";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
181 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
182 case D3DERR_NOTAVAILABLE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
183 error = "NOTAVAILABLE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
184 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
185 case D3DERR_OUTOFVIDEOMEMORY:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
186 error = "OUTOFVIDEOMEMORY";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
187 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
188 case D3DERR_INVALIDDEVICE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
189 error = "INVALIDDEVICE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
190 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
191 case D3DERR_INVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
192 error = "INVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
193 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
194 case D3DERR_DRIVERINVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
195 error = "DRIVERINVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
196 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
197 case D3DERR_WASSTILLDRAWING:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
198 error = "WASSTILLDRAWING";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
199 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
200 default:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
201 error = "UNKNOWN";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
202 break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
203 }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
204 SDL_SetError("%s: %s", prefix, error);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
205 }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
206
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
207 static D3DFORMAT
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
208 PixelFormatToD3DFMT(Uint32 format)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 {
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
210 switch (format) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
211 case SDL_PIXELFORMAT_INDEX8:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
212 return D3DFMT_P8;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
213 case SDL_PIXELFORMAT_RGB332:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
214 return D3DFMT_R3G3B2;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
215 case SDL_PIXELFORMAT_RGB444:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
216 return D3DFMT_X4R4G4B4;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
217 case SDL_PIXELFORMAT_RGB555:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
218 return D3DFMT_X1R5G5B5;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
219 case SDL_PIXELFORMAT_ARGB4444:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
220 return D3DFMT_A4R4G4B4;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
221 case SDL_PIXELFORMAT_ARGB1555:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
222 return D3DFMT_A1R5G5B5;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
223 case SDL_PIXELFORMAT_RGB565:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
224 return D3DFMT_R5G6B5;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
225 case SDL_PIXELFORMAT_RGB888:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
226 return D3DFMT_X8R8G8B8;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
227 case SDL_PIXELFORMAT_ARGB8888:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
228 return D3DFMT_A8R8G8B8;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
229 case SDL_PIXELFORMAT_ARGB2101010:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
230 return D3DFMT_A2R10G10B10;
3495
1b22878e04d0 Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3480
diff changeset
231 case SDL_PIXELFORMAT_YV12:
1b22878e04d0 Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3480
diff changeset
232 return MAKEFOURCC('Y','V','1','2');
1b22878e04d0 Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3480
diff changeset
233 case SDL_PIXELFORMAT_IYUV:
1b22878e04d0 Adam Strzelecki to SDL
Sam Lantinga <slouken@libsdl.org>
parents: 3480
diff changeset
234 return MAKEFOURCC('I','4','2','0');
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
235 case SDL_PIXELFORMAT_UYVY:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
236 return D3DFMT_UYVY;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
237 case SDL_PIXELFORMAT_YUY2:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
238 return D3DFMT_YUY2;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
239 default:
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
240 return D3DFMT_UNKNOWN;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
241 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
244 static SDL_bool
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
245 D3D_IsTextureFormatAvailable(IDirect3D9 * d3d, Uint32 display_format,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
246 Uint32 texture_format)
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
247 {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
248 HRESULT result;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
249
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
250 result = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, /* FIXME */
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
251 D3DDEVTYPE_HAL,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
252 PixelFormatToD3DFMT(display_format),
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
253 0,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
254 D3DRTYPE_TEXTURE,
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
255 PixelFormatToD3DFMT
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
256 (texture_format));
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
257 return FAILED(result) ? SDL_FALSE : SDL_TRUE;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
258 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
259
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
260 static void
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
261 UpdateYUVTextureData(SDL_Texture * texture)
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
262 {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
263 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
264 SDL_Rect rect;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
265 RECT d3drect;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
266 D3DLOCKED_RECT locked;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
267 HRESULT result;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
268
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
269 d3drect.left = 0;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
270 d3drect.right = texture->w;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
271 d3drect.top = 0;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
272 d3drect.bottom = texture->h;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
273
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
274 result =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
275 IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
276 if (FAILED(result)) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
277 return;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
278 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
279
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
280 rect.x = 0;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
281 rect.y = 0;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
282 rect.w = texture->w;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
283 rect.h = texture->h;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
284 SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
285 texture->h, locked.pBits, locked.Pitch);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
286
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
287 IDirect3DTexture9_UnlockRect(data->texture, 0);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
288 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
289
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 D3D_AddRenderDriver(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
2972
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
294 SDL_RendererInfo *info = &D3D_RenderDriver.info;
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
295 SDL_DisplayMode *mode = &SDL_CurrentDisplay.desktop_mode;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 if (data->d3d) {
2972
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
298 int i;
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
299 int formats[] = {
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
300 SDL_PIXELFORMAT_INDEX8,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
301 SDL_PIXELFORMAT_RGB332,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
302 SDL_PIXELFORMAT_RGB444,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
303 SDL_PIXELFORMAT_RGB555,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
304 SDL_PIXELFORMAT_ARGB4444,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
305 SDL_PIXELFORMAT_ARGB1555,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
306 SDL_PIXELFORMAT_RGB565,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
307 SDL_PIXELFORMAT_RGB888,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
308 SDL_PIXELFORMAT_ARGB8888,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
309 SDL_PIXELFORMAT_ARGB2101010,
2972
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
310 };
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
311
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
312 for (i = 0; i < SDL_arraysize(formats); ++i) {
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
313 if (D3D_IsTextureFormatAvailable
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
314 (data->d3d, mode->format, formats[i])) {
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
315 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
316 formats[i];
2972
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
317 }
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
318 }
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
319 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
320 SDL_PIXELFORMAT_YV12;
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
321 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
322 SDL_PIXELFORMAT_IYUV;
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
323 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
324 SDL_PIXELFORMAT_YUY2;
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
325 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
326 SDL_PIXELFORMAT_UYVY;
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
327 info->texture_formats[info->num_texture_formats++] =
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
328 SDL_PIXELFORMAT_YVYU;
2972
0a4b70368372 Query available formats before advertising them.
Sam Lantinga <slouken@libsdl.org>
parents: 2933
diff changeset
329
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
330 SDL_AddRenderDriver(0, &D3D_RenderDriver);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 SDL_Renderer *
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
335 D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 SDL_Renderer *renderer;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
341 D3D_RenderData *data;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
342 HRESULT result;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
343 D3DPRESENT_PARAMETERS pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
344 IDirect3DSwapChain9 *chain;
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
345 D3DCAPS9 caps;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
347 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 if (!renderer) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
353 data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 if (!data) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
355 D3D_DestroyRenderer(renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 }
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
359 data->d3d = videodata->d3d;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
361 renderer->DisplayModeChanged = D3D_DisplayModeChanged;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
362 renderer->CreateTexture = D3D_CreateTexture;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
363 renderer->QueryTexturePixels = D3D_QueryTexturePixels;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
364 renderer->SetTexturePalette = D3D_SetTexturePalette;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
365 renderer->GetTexturePalette = D3D_GetTexturePalette;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
366 renderer->SetTextureColorMod = D3D_SetTextureColorMod;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
367 renderer->SetTextureAlphaMod = D3D_SetTextureAlphaMod;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
368 renderer->SetTextureBlendMode = D3D_SetTextureBlendMode;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
369 renderer->SetTextureScaleMode = D3D_SetTextureScaleMode;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
370 renderer->UpdateTexture = D3D_UpdateTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
371 renderer->LockTexture = D3D_LockTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
372 renderer->UnlockTexture = D3D_UnlockTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
373 renderer->DirtyTexture = D3D_DirtyTexture;
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
374 renderer->RenderPoint = D3D_RenderPoint;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
375 renderer->RenderLine = D3D_RenderLine;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
376 renderer->RenderFill = D3D_RenderFill;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
377 renderer->RenderCopy = D3D_RenderCopy;
3427
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
378 renderer->RenderReadPixels = D3D_RenderReadPixels;
3480
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
379 renderer->RenderWritePixels = D3D_RenderWritePixels;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
380 renderer->RenderPresent = D3D_RenderPresent;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
381 renderer->DestroyTexture = D3D_DestroyTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
382 renderer->DestroyRenderer = D3D_DestroyRenderer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
383 renderer->info = D3D_RenderDriver.info;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 renderer->window = window->id;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 renderer->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
387 renderer->info.flags = SDL_RENDERER_ACCELERATED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
389 SDL_zero(pparams);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
390 pparams.BackBufferWidth = window->w;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
391 pparams.BackBufferHeight = window->h;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
392 if (window->flags & SDL_WINDOW_FULLSCREEN) {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
393 pparams.BackBufferFormat =
3519
1374f9275de9 Fixed compiling the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3495
diff changeset
394 PixelFormatToD3DFMT(window->fullscreen_mode.format);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
395 } else {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
396 pparams.BackBufferFormat = D3DFMT_UNKNOWN;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
397 }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
398 if (flags & SDL_RENDERER_PRESENTFLIP2) {
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
399 pparams.BackBufferCount = 2;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
400 pparams.SwapEffect = D3DSWAPEFFECT_FLIP;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
401 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
402 pparams.BackBufferCount = 3;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
403 pparams.SwapEffect = D3DSWAPEFFECT_FLIP;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
404 } else if (flags & SDL_RENDERER_PRESENTCOPY) {
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
405 pparams.BackBufferCount = 1;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
406 pparams.SwapEffect = D3DSWAPEFFECT_COPY;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
407 } else {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
408 pparams.BackBufferCount = 1;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
409 pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
410 }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
411 if (window->flags & SDL_WINDOW_FULLSCREEN) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
412 pparams.Windowed = FALSE;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
413 pparams.FullScreen_RefreshRateInHz =
3519
1374f9275de9 Fixed compiling the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3495
diff changeset
414 window->fullscreen_mode.refresh_rate;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
415 } else {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
416 pparams.Windowed = TRUE;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
417 pparams.FullScreen_RefreshRateInHz = 0;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
418 }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
419 if (flags & SDL_RENDERER_PRESENTVSYNC) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
420 pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
421 } else {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
422 pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
423 }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
424
3197
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
425 IDirect3D9_GetDeviceCaps(videodata->d3d, D3DADAPTER_DEFAULT,
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
426 D3DDEVTYPE_HAL, &caps);
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
427
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
428 result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT, /* FIXME */
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
429 D3DDEVTYPE_HAL,
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
430 windowdata->hwnd,
3197
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
431 (caps.
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
432 DevCaps &
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
433 D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
434 D3DCREATE_HARDWARE_VERTEXPROCESSING :
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
435 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
436 &pparams, &data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
437 if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
438 D3D_DestroyRenderer(renderer);
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
439 D3D_SetError("CreateDevice()", result);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
440 return NULL;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
441 }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
442 data->beginScene = SDL_TRUE;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
443
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
444 /* Get presentation parameters to fill info */
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
445 result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
446 if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
447 D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
448 D3D_SetError("GetSwapChain()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
449 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
450 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
451 result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
452 if (FAILED(result)) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
453 IDirect3DSwapChain9_Release(chain);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
454 D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
455 D3D_SetError("GetPresentParameters()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
456 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
457 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
458 IDirect3DSwapChain9_Release(chain);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
459 switch (pparams.SwapEffect) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
460 case D3DSWAPEFFECT_COPY:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
461 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
462 break;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
463 case D3DSWAPEFFECT_FLIP:
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
464 switch (pparams.BackBufferCount) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
465 case 2:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
466 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
467 break;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
468 case 3:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
469 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
470 break;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
471 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
472 break;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
473 case D3DSWAPEFFECT_DISCARD:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
474 renderer->info.flags |= SDL_RENDERER_PRESENTDISCARD;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
475 break;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
476 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
477 if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
478 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
479 }
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
480 data->pparams = pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
481
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
482 IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
483 renderer->info.max_texture_width = caps.MaxTextureWidth;
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
484 renderer->info.max_texture_height = caps.MaxTextureHeight;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1917
diff changeset
485
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
486 /* Set up parameters for rendering */
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
487 IDirect3DDevice9_SetVertexShader(data->device, NULL);
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
488 IDirect3DDevice9_SetFVF(data->device,
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
489 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
1988
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
490 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
491 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
492 D3DCULL_NONE);
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
493 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
1988
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
494 /* Enable color modulation by diffuse color */
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
495 IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
496 D3DTOP_MODULATE);
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
497 IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
498 D3DTA_TEXTURE);
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
499 IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
500 D3DTA_DIFFUSE);
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
501 /* Enable alpha modulation by diffuse alpha */
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
502 IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
503 D3DTOP_MODULATE);
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
504 IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
505 D3DTA_TEXTURE);
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
506 IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
1ee02169bbb0 Figured out how texture stages work, thanks to this:
Sam Lantinga <slouken@libsdl.org>
parents: 1987
diff changeset
507 D3DTA_DIFFUSE);
1991
3863ba81c1d6 Clear the second texture stage explicitly
Sam Lantinga <slouken@libsdl.org>
parents: 1988
diff changeset
508 /* Disable second texture stage, since we're done */
3863ba81c1d6 Clear the second texture stage explicitly
Sam Lantinga <slouken@libsdl.org>
parents: 1988
diff changeset
509 IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
3863ba81c1d6 Clear the second texture stage explicitly
Sam Lantinga <slouken@libsdl.org>
parents: 1988
diff changeset
510 D3DTOP_DISABLE);
3863ba81c1d6 Clear the second texture stage explicitly
Sam Lantinga <slouken@libsdl.org>
parents: 1988
diff changeset
511 IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
3863ba81c1d6 Clear the second texture stage explicitly
Sam Lantinga <slouken@libsdl.org>
parents: 1988
diff changeset
512 D3DTOP_DISABLE);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
513
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 return renderer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 static int
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
518 D3D_Reset(SDL_Renderer * renderer)
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
519 {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
520 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
521 HRESULT result;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
522
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
523 result = IDirect3DDevice9_Reset(data->device, &data->pparams);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
524 if (FAILED(result)) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
525 if (result == D3DERR_DEVICELOST) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
526 /* Don't worry about it, we'll reset later... */
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
527 return 0;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
528 } else {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
529 D3D_SetError("Reset()", result);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
530 return -1;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
531 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
532 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
533 IDirect3DDevice9_SetVertexShader(data->device, NULL);
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
534 IDirect3DDevice9_SetFVF(data->device,
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
535 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
536 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
537 D3DCULL_NONE);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
538 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
539 return 0;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
540 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
541
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
542 static int
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
543 D3D_DisplayModeChanged(SDL_Renderer * renderer)
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
544 {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
545 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
546 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
547 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
548
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
549 data->pparams.BackBufferWidth = window->w;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
550 data->pparams.BackBufferHeight = window->h;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
551 if (window->flags & SDL_WINDOW_FULLSCREEN) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
552 data->pparams.BackBufferFormat =
3519
1374f9275de9 Fixed compiling the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3495
diff changeset
553 PixelFormatToD3DFMT(window->fullscreen_mode.format);
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
554 } else {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
555 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
556 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
557 return D3D_Reset(renderer);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
558 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
559
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
560 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
561 D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
563 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
566 Uint32 display_format = display->current_mode.format;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
567 D3D_TextureData *data;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
568 HRESULT result;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
570 data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 if (!data) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 texture->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
578 if (SDL_ISPIXELFORMAT_FOURCC(texture->format) &&
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
579 (texture->format != SDL_PIXELFORMAT_YUY2 ||
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
580 !D3D_IsTextureFormatAvailable(renderdata->d3d, display_format,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
581 texture->format))
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
582 && (texture->format != SDL_PIXELFORMAT_YVYU
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
583 || !D3D_IsTextureFormatAvailable(renderdata->d3d, display_format,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
584 texture->format))) {
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
585 data->yuv =
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
586 SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
587 if (!data->yuv) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
588 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
589 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
590 data->format = display->current_mode.format;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
591 } else {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
592 data->format = texture->format;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
593 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
594
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
595 result =
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
596 IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
597 texture->h, 1, 0,
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
598 PixelFormatToD3DFMT(data->format),
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
599 D3DPOOL_SDL, &data->texture, NULL);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
600 if (FAILED(result)) {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
601 D3D_SetError("CreateTexture()", result);
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
602 return -1;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
603 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
605 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 static int
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
609 D3D_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
610 void **pixels, int *pitch)
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
611 {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
612 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
613
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
614 if (data->yuv) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
615 return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
616 } else {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
617 /* D3D textures don't have their pixels hanging out */
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
618 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
619 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
620 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
621
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
622 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
623 D3D_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
624 const SDL_Color * colors, int firstcolor, int ncolors)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
626 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
627 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
629 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
633 D3D_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
634 SDL_Color * colors, int firstcolor, int ncolors)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
636 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
638 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641 static int
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
642 D3D_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
643 {
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
644 return 0;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
645 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
646
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
647 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
648 D3D_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
649 {
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
650 return 0;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
651 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
652
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
653 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
654 D3D_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
655 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
656 switch (texture->blendMode) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
657 case SDL_BLENDMODE_NONE:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
658 case SDL_BLENDMODE_MASK:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
659 case SDL_BLENDMODE_BLEND:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
660 case SDL_BLENDMODE_ADD:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
661 case SDL_BLENDMODE_MOD:
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
662 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
663 default:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
664 SDL_Unsupported();
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
665 texture->blendMode = SDL_BLENDMODE_NONE;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
666 return -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
667 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
668 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
669
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
670 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
671 D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
672 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
673 switch (texture->scaleMode) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
674 case SDL_TEXTURESCALEMODE_NONE:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
675 case SDL_TEXTURESCALEMODE_FAST:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
676 case SDL_TEXTURESCALEMODE_SLOW:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
677 case SDL_TEXTURESCALEMODE_BEST:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
678 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
679 default:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
680 SDL_Unsupported();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
681 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
682 return -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
683 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
684 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
685 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
686
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
687 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
688 D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
689 const SDL_Rect * rect, const void *pixels, int pitch)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
691 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
692 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
694 if (data->yuv) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
695 if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
696 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
697 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
698 UpdateYUVTextureData(texture);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
699 return 0;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
700 } else {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
701 #ifdef SDL_MEMORY_POOL_DEFAULT
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
702 IDirect3DTexture9 *temp;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
703 RECT d3drect;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
704 D3DLOCKED_RECT locked;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
705 const Uint8 *src;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
706 Uint8 *dst;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
707 int row, length;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
708 HRESULT result;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
709
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
710 result =
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
711 IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
712 texture->h, 1, 0,
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
713 PixelFormatToD3DFMT(texture->
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
714 format),
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
715 D3DPOOL_SYSTEMMEM, &temp, NULL);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
716 if (FAILED(result)) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
717 D3D_SetError("CreateTexture()", result);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
718 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
719 }
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
720
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
721 d3drect.left = rect->x;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
722 d3drect.right = rect->x + rect->w;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
723 d3drect.top = rect->y;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
724 d3drect.bottom = rect->y + rect->h;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
726 result = IDirect3DTexture9_LockRect(temp, 0, &locked, &d3drect, 0);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
727 if (FAILED(result)) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
728 IDirect3DTexture9_Release(temp);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
729 D3D_SetError("LockRect()", result);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
730 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
731 }
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
732
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
733 src = pixels;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
734 dst = locked.pBits;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
735 length = rect->w * SDL_BYTESPERPIXEL(texture->format);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
736 for (row = 0; row < rect->h; ++row) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
737 SDL_memcpy(dst, src, length);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
738 src += pitch;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
739 dst += locked.Pitch;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
740 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
741 IDirect3DTexture9_UnlockRect(temp, 0);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
742
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
743 result =
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
744 IDirect3DDevice9_UpdateTexture(renderdata->device,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
745 (IDirect3DBaseTexture9 *) temp,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
746 (IDirect3DBaseTexture9 *)
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
747 data->texture);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
748 IDirect3DTexture9_Release(temp);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
749 if (FAILED(result)) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
750 D3D_SetError("UpdateTexture()", result);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
751 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
752 }
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
753 #else
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
754 RECT d3drect;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
755 D3DLOCKED_RECT locked;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
756 const Uint8 *src;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
757 Uint8 *dst;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
758 int row, length;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
759 HRESULT result;
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
760
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
761 d3drect.left = rect->x;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
762 d3drect.right = rect->x + rect->w;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
763 d3drect.top = rect->y;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
764 d3drect.bottom = rect->y + rect->h;
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
765
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
766 result =
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
767 IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect,
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
768 0);
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
769 if (FAILED(result)) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
770 D3D_SetError("LockRect()", result);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
771 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
772 }
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
773
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
774 src = pixels;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
775 dst = locked.pBits;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
776 length = rect->w * SDL_BYTESPERPIXEL(texture->format);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
777 for (row = 0; row < rect->h; ++row) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
778 SDL_memcpy(dst, src, length);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
779 src += pitch;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
780 dst += locked.Pitch;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
781 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
782 IDirect3DTexture9_UnlockRect(data->texture, 0);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
783 #endif // SDL_MEMORY_POOL_DEFAULT
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
784
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
785 return 0;
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
786 }
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
787 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
789 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
790 D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
791 const SDL_Rect * rect, int markDirty, void **pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
792 int *pitch)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
794 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
796 if (data->yuv) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
797 return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
798 pitch);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
799 } else {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
800 RECT d3drect;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
801 D3DLOCKED_RECT locked;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
802 HRESULT result;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
803
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
804 d3drect.left = rect->x;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
805 d3drect.right = rect->x + rect->w;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
806 d3drect.top = rect->y;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
807 d3drect.bottom = rect->y + rect->h;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
808
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
809 result =
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
810 IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect,
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
811 markDirty ? 0 :
Sam Lantinga <slouken@libsdl.org>
parents: 2973
diff changeset
812 D3DLOCK_NO_DIRTY_UPDATE);
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
813 if (FAILED(result)) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
814 D3D_SetError("LockRect()", result);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
815 return -1;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
816 }
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
817 *pixels = locked.pBits;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
818 *pitch = locked.Pitch;
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
819 return 0;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
820 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
822
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
824 D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
825 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
826 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
828 if (data->yuv) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
829 SDL_SW_UnlockYUVTexture(data->yuv);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
830 UpdateYUVTextureData(texture);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
831 } else {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
832 IDirect3DTexture9_UnlockRect(data->texture, 0);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
833 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
834 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
835
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
836 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
837 D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
838 const SDL_Rect * rects)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
839 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
840 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
841 RECT d3drect;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
842 int i;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
843
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
844 for (i = 0; i < numrects; ++i) {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
845 const SDL_Rect *rect = &rects[i];
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
846
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
847 d3drect.left = rect->x;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
848 d3drect.right = rect->x + rect->w;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
849 d3drect.top = rect->y;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
850 d3drect.bottom = rect->y + rect->h;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
851
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
852 IDirect3DTexture9_AddDirtyRect(data->texture, &d3drect);
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
853 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
854 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
855
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
856 static void
2933
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
857 D3D_SetBlendMode(D3D_RenderData * data, int blendMode)
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
858 {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
859 switch (blendMode) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
860 case SDL_BLENDMODE_NONE:
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
861 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
862 FALSE);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
863 break;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
864 case SDL_BLENDMODE_MASK:
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
865 case SDL_BLENDMODE_BLEND:
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
866 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
867 TRUE);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
868 IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
869 D3DBLEND_SRCALPHA);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
870 IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
871 D3DBLEND_INVSRCALPHA);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
872 break;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
873 case SDL_BLENDMODE_ADD:
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
874 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
875 TRUE);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
876 IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
877 D3DBLEND_SRCALPHA);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
878 IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
879 D3DBLEND_ONE);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
880 break;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
881 case SDL_BLENDMODE_MOD:
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
882 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
883 TRUE);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
884 IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
885 D3DBLEND_ZERO);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
886 IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
887 D3DBLEND_SRCCOLOR);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
888 break;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
889 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
890 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
891
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
892 static int
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
893 D3D_RenderPoint(SDL_Renderer * renderer, int x, int y)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
894 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
895 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
896 DWORD color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
897 Vertex vertices[1];
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
898 HRESULT result;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
899
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
900 if (data->beginScene) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
901 IDirect3DDevice9_BeginScene(data->device);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
902 data->beginScene = SDL_FALSE;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
903 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
904
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
905 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
906
3267
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
907 vertices[0].x = (float) x;
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
908 vertices[0].y = (float) y;
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
909 vertices[0].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
910 vertices[0].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
911 vertices[0].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
912 vertices[0].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
913 vertices[0].v = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
914
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
915 D3D_SetBlendMode(data, renderer->blendMode);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
916
2933
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
917 result =
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
918 IDirect3DDevice9_SetTexture(data->device, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
919 (IDirect3DBaseTexture9 *) 0);
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
920 if (FAILED(result)) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
921 D3D_SetError("SetTexture()", result);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
922 return -1;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
923 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
924 result =
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
925 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
926 vertices, sizeof(*vertices));
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
927 if (FAILED(result)) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
928 D3D_SetError("DrawPrimitiveUP()", result);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
929 return -1;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
930 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
931 return 0;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
932 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
933
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
934 static int
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
935 D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
936 {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
937 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
938 DWORD color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
939 Vertex vertices[2];
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
940 HRESULT result;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
941
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
942 if (data->beginScene) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
943 IDirect3DDevice9_BeginScene(data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
944 data->beginScene = SDL_FALSE;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
945 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
946
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
947 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
948
3267
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
949 vertices[0].x = (float) x1;
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
950 vertices[0].y = (float) y1;
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
951 vertices[0].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
952 vertices[0].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
953 vertices[0].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
954 vertices[0].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
955 vertices[0].v = 0.0f;
1901
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1900
diff changeset
956
3267
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
957 vertices[1].x = (float) x2;
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
958 vertices[1].y = (float) y2;
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
959 vertices[1].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
960 vertices[1].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
961 vertices[1].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
962 vertices[1].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
963 vertices[1].v = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
964
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
965 D3D_SetBlendMode(data, renderer->blendMode);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
966
2933
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
967 result =
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
968 IDirect3DDevice9_SetTexture(data->device, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
969 (IDirect3DBaseTexture9 *) 0);
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
970 if (FAILED(result)) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
971 D3D_SetError("SetTexture()", result);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
972 return -1;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
973 }
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
974 result =
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
975 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINELIST, 1,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
976 vertices, sizeof(*vertices));
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
977 if (FAILED(result)) {
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
978 D3D_SetError("DrawPrimitiveUP()", result);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
979 return -1;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
980 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
981 return 0;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
982 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
983
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
984 static int
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
985 D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
986 {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
987 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
988 float minx, miny, maxx, maxy;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
989 DWORD color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
990 Vertex vertices[4];
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
991 HRESULT result;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
992
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
993 if (data->beginScene) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
994 IDirect3DDevice9_BeginScene(data->device);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
995 data->beginScene = SDL_FALSE;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
996 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
997
3267
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
998 minx = (float) rect->x;
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
999 miny = (float) rect->y;
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
1000 maxx = (float) rect->x + rect->w;
7690aa2f5b74 testsprite2 should be pixel correct on Direct3D now.
Sam Lantinga <slouken@libsdl.org>
parents: 3197
diff changeset
1001 maxy = (float) rect->y + rect->h;
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1002
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1003 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1004
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1005 vertices[0].x = minx;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1006 vertices[0].y = miny;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1007 vertices[0].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1008 vertices[0].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1009 vertices[0].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1010 vertices[0].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1011 vertices[0].v = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1012
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1013 vertices[1].x = maxx;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1014 vertices[1].y = miny;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1015 vertices[1].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1016 vertices[1].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1017 vertices[1].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1018 vertices[1].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1019 vertices[1].v = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1020
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1021 vertices[2].x = maxx;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1022 vertices[2].y = maxy;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1023 vertices[2].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1024 vertices[2].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1025 vertices[2].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1026 vertices[2].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1027 vertices[2].v = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1028
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1029 vertices[3].x = minx;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1030 vertices[3].y = maxy;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1031 vertices[3].z = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1032 vertices[3].rhw = 1.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1033 vertices[3].color = color;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1034 vertices[3].u = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1035 vertices[3].v = 0.0f;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1036
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1037 D3D_SetBlendMode(data, renderer->blendMode);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1038
2933
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
1039 result =
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
1040 IDirect3DDevice9_SetTexture(data->device, 0,
Sam Lantinga <slouken@libsdl.org>
parents: 2932
diff changeset
1041 (IDirect3DBaseTexture9 *) 0);
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1042 if (FAILED(result)) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1043 D3D_SetError("SetTexture()", result);
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1044 return -1;
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1045 }
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1046 result =
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1047 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1048 vertices, sizeof(*vertices));
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1049 if (FAILED(result)) {
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1050 D3D_SetError("DrawPrimitiveUP()", result);
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1051 return -1;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1052 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1053 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1054 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1055
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1056 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1057 D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
1058 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1059 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1060 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1061 D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1062 float minx, miny, maxx, maxy;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1063 float minu, maxu, minv, maxv;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1064 DWORD color;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1065 Vertex vertices[4];
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1066 HRESULT result;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1067
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1068 if (data->beginScene) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1069 IDirect3DDevice9_BeginScene(data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1070 data->beginScene = SDL_FALSE;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1071 }
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1072
3279
fd207dce9f94 I think this fixes the texture pixel alignment
Sam Lantinga <slouken@libsdl.org>
parents: 3267
diff changeset
1073 minx = (float) dstrect->x - 0.5f;
fd207dce9f94 I think this fixes the texture pixel alignment
Sam Lantinga <slouken@libsdl.org>
parents: 3267
diff changeset
1074 miny = (float) dstrect->y - 0.5f;
fd207dce9f94 I think this fixes the texture pixel alignment
Sam Lantinga <slouken@libsdl.org>
parents: 3267
diff changeset
1075 maxx = (float) dstrect->x + dstrect->w - 0.5f;
fd207dce9f94 I think this fixes the texture pixel alignment
Sam Lantinga <slouken@libsdl.org>
parents: 3267
diff changeset
1076 maxy = (float) dstrect->y + dstrect->h - 0.5f;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1077
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1078 minu = (float) srcrect->x / texture->w;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1079 maxu = (float) (srcrect->x + srcrect->w) / texture->w;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1080 minv = (float) srcrect->y / texture->h;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1081 maxv = (float) (srcrect->y + srcrect->h) / texture->h;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1082
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1083 color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1084
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1085 vertices[0].x = minx;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1086 vertices[0].y = miny;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1087 vertices[0].z = 0.0f;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1088 vertices[0].rhw = 1.0f;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1089 vertices[0].color = color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1090 vertices[0].u = minu;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1091 vertices[0].v = minv;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1092
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1093 vertices[1].x = maxx;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1094 vertices[1].y = miny;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1095 vertices[1].z = 0.0f;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1096 vertices[1].rhw = 1.0f;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1097 vertices[1].color = color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1098 vertices[1].u = maxu;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1099 vertices[1].v = minv;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1100
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1101 vertices[2].x = maxx;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1102 vertices[2].y = maxy;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1103 vertices[2].z = 0.0f;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1104 vertices[2].rhw = 1.0f;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1105 vertices[2].color = color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1106 vertices[2].u = maxu;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1107 vertices[2].v = maxv;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1108
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1109 vertices[3].x = minx;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1110 vertices[3].y = maxy;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1111 vertices[3].z = 0.0f;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1112 vertices[3].rhw = 1.0f;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1113 vertices[3].color = color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1114 vertices[3].u = minu;
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
1115 vertices[3].v = maxv;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1116
2932
676754cc1acb Implemented Direct3D line and point drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2920
diff changeset
1117 D3D_SetBlendMode(data, texture->blendMode);
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
1118
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1976
diff changeset
1119 switch (texture->scaleMode) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
1120 case SDL_TEXTURESCALEMODE_NONE:
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
1121 case SDL_TEXTURESCALEMODE_FAST:
1917
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1122 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1123 D3DTEXF_POINT);
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1124 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1125 D3DTEXF_POINT);
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1126 break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
1127 case SDL_TEXTURESCALEMODE_SLOW:
1917
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1128 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1129 D3DTEXF_LINEAR);
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1130 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1131 D3DTEXF_LINEAR);
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1132 break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
1133 case SDL_TEXTURESCALEMODE_BEST:
1917
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1134 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1135 D3DTEXF_GAUSSIANQUAD);
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1136 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1137 D3DTEXF_GAUSSIANQUAD);
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1138 break;
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1139 }
3f54b3ec5a07 Implemented scaling in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
1140
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1141 result =
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
1142 IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
1143 texturedata->texture);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1144 if (FAILED(result)) {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1145 D3D_SetError("SetTexture()", result);
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1146 return -1;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1147 }
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1148 result =
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1149 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1150 vertices, sizeof(*vertices));
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1151 if (FAILED(result)) {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1152 D3D_SetError("DrawPrimitiveUP()", result);
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1153 return -1;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1154 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1155 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1156 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1157
3427
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1158 static int
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1159 D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3480
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1160 Uint32 format, void * pixels, int pitch)
3427
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1161 {
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1162 BYTE * pBytes;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1163 D3DLOCKED_RECT lockedRect;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1164 BYTE b, g, r, a;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1165 unsigned long index;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1166 int cur_mouse;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1167 int x, y;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1168
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1169 LPDIRECT3DSURFACE9 backBuffer;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1170 LPDIRECT3DSURFACE9 pickOffscreenSurface;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1171 D3DSURFACE_DESC desc;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1172
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1173 D3D_RenderData * data = (D3D_RenderData *) renderer->driverdata;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1174
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1175 IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1176
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1177
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1178 IDirect3DSurface9_GetDesc(backBuffer, &desc);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1179
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1180 IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pickOffscreenSurface, NULL);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1181
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1182 IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, pickOffscreenSurface);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1183
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1184 IDirect3DSurface9_LockRect(pickOffscreenSurface, &lockedRect, NULL, D3DLOCK_READONLY);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1185 pBytes = (BYTE*)lockedRect.pBits;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1186 IDirect3DSurface9_UnlockRect(pickOffscreenSurface);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1187
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1188 // just to debug -->
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1189 cur_mouse = SDL_SelectMouse(-1);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1190 SDL_GetMouseState(cur_mouse, &x, &y);
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1191 index = (x * 4 + (y * lockedRect.Pitch));
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1192
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1193 b = pBytes[index];
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1194 g = pBytes[index+1];
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1195 r = pBytes[index+2];
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1196 a = pBytes[index+3];
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1197 // <--
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1198
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1199 return -1;
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1200 }
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
1201
3480
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1202 static int
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1203 D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1204 Uint32 format, const void * pixels, int pitch)
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1205 {
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1206 /* Work in progress */
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1207 return -1;
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1208 }
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
1209
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1210 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1211 D3D_RenderPresent(SDL_Renderer * renderer)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1212 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1213 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1214 HRESULT result;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1215
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1216 if (!data->beginScene) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1217 IDirect3DDevice9_EndScene(data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1218 data->beginScene = SDL_TRUE;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1219 }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1220
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1221 result = IDirect3DDevice9_TestCooperativeLevel(data->device);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1222 if (result == D3DERR_DEVICELOST) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1223 /* We'll reset later */
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1224 return;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1225 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1226 if (result == D3DERR_DEVICENOTRESET) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1227 D3D_Reset(renderer);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1228 }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1229 result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1230 if (FAILED(result)) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1231 D3D_SetError("Present()", result);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1232 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1233 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1234
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1235 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1236 D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1237 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1238 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1239
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1240 if (!data) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1241 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1242 }
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
1243 if (data->yuv) {
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
1244 SDL_SW_DestroyYUVTexture(data->yuv);
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
1245 }
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1246 if (data->texture) {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1247 IDirect3DTexture9_Release(data->texture);
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
1248 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1249 SDL_free(data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1250 texture->driverdata = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1251 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1252
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1253 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1254 D3D_DestroyRenderer(SDL_Renderer * renderer)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1255 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1256 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1257
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1258 if (data) {
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1259 if (data->device) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1260 IDirect3DDevice9_Release(data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
1261 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1262 SDL_free(data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1263 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1264 SDL_free(renderer);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1265 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1266
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1267 #endif /* SDL_VIDEO_RENDER_D3D */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1268
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1269 /* vi: set ts=4 sw=4 expandtab: */