2 * IDirect3DVertexShader9 implementation
4 * Copyright 2002-2003 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 HRESULT WINAPI
IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface
, REFIID riid
, LPVOID
* ppobj
) {
29 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
31 if (IsEqualGUID(riid
, &IID_IUnknown
)
32 || IsEqualGUID(riid
, &IID_IDirect3DVertexShader9
)) {
33 IDirect3DVertexShader9Impl_AddRef(iface
);
38 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
42 ULONG WINAPI
IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface
) {
43 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
44 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
48 ULONG WINAPI
IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface
) {
49 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
50 ULONG ref
= --This
->ref
;
52 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
54 HeapFree(GetProcessHeap(), 0, This
);
59 /* IDirect3DVertexShader9 Interface follow: */
60 HRESULT WINAPI
IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface
, IDirect3DDevice9
** ppDevice
) {
61 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
62 TRACE("(%p) : returning %p\n", This
, This
->Device
);
63 *ppDevice
= (LPDIRECT3DDEVICE9
) This
->Device
;
64 IDirect3DDevice9Impl_AddRef(*ppDevice
);
68 HRESULT WINAPI
IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface
, VOID
* pData
, UINT
* pSizeOfData
) {
69 IDirect3DVertexShader9Impl
*This
= (IDirect3DVertexShader9Impl
*)iface
;
70 FIXME("(%p) : stub\n", This
);
75 IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl
=
77 IDirect3DVertexShader9Impl_QueryInterface
,
78 IDirect3DVertexShader9Impl_AddRef
,
79 IDirect3DVertexShader9Impl_Release
,
80 IDirect3DVertexShader9Impl_GetDevice
,
81 IDirect3DVertexShader9Impl_GetFunction
85 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
86 HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface
, CONST DWORD
* pFunction
, IDirect3DVertexShader9
** ppShader
) {
87 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
88 FIXME("(%p) : stub\n", This
);
92 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface
, IDirect3DVertexShader9
* pShader
) {
93 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
95 This
->UpdateStateBlock
->VertexShader
= pShader
;
96 This
->UpdateStateBlock
->Changed
.vertexShader
= TRUE
;
97 This
->UpdateStateBlock
->Set
.vertexShader
= TRUE
;
99 /* Handle recording of state blocks */
100 if (This
->isRecordingState
) {
101 TRACE("Recording... not performing anything\n");
105 * TODO: merge HAL shaders context switching from prototype
110 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface
, IDirect3DVertexShader9
** ppShader
) {
111 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
112 TRACE("(%p) : GetVertexShader returning %p\n", This
, This
->StateBlock
->VertexShader
);
113 *ppShader
= This
->StateBlock
->VertexShader
;
114 IDirect3DVertexShader9Impl_AddRef(*ppShader
);
118 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface
, UINT Register
, CONST
float* pConstantData
, UINT Vector4fCount
) {
119 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
121 if (Register
+ Vector4fCount
> D3D_VSHADER_MAX_CONSTANTS
) {
122 ERR("(%p) : SetVertexShaderConstant C[%u] invalid\n", This
, Register
);
123 return D3DERR_INVALIDCALL
;
125 if (NULL
== pConstantData
) {
126 return D3DERR_INVALIDCALL
;
128 if (Vector4fCount
> 1) {
129 CONST FLOAT
* f
= pConstantData
;
131 TRACE("(%p) : SetVertexShaderConstant C[%u..%u]=\n", This
, Register
, Register
+ Vector4fCount
- 1);
132 for (i
= 0; i
< Vector4fCount
; ++i
) {
133 TRACE("{%f, %f, %f, %f}\n", f
[0], f
[1], f
[2], f
[3]);
137 const FLOAT
* f
= (const FLOAT
*) pConstantData
;
138 TRACE("(%p) : SetVertexShaderConstant, C[%u]={%f, %f, %f, %f}\n", This
, Register
, f
[0], f
[1], f
[2], f
[3]);
140 This
->UpdateStateBlock
->Changed
.vertexShaderConstant
= TRUE
;
141 memcpy(&This
->UpdateStateBlock
->vertexShaderConstantF
[Register
], pConstantData
, Vector4fCount
* 4 * sizeof(FLOAT
));
145 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface
, UINT Register
, float* pConstantData
, UINT Vector4fCount
) {
146 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
148 TRACE("(%p) : C[%u] count=%u\n", This
, Register
, Vector4fCount
);
149 if (Register
+ Vector4fCount
> D3D_VSHADER_MAX_CONSTANTS
) {
150 return D3DERR_INVALIDCALL
;
152 if (NULL
== pConstantData
) {
153 return D3DERR_INVALIDCALL
;
155 memcpy(pConstantData
, &This
->UpdateStateBlock
->vertexShaderConstantF
[Register
], Vector4fCount
* 4 * sizeof(FLOAT
));
159 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface
, UINT Register
, CONST
int* pConstantData
, UINT Vector4iCount
) {
160 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
162 if (Register
+ Vector4iCount
> D3D_VSHADER_MAX_CONSTANTS
) {
163 ERR("(%p) : SetVertexShaderConstantI C[%u] invalid\n", This
, Register
);
164 return D3DERR_INVALIDCALL
;
166 if (NULL
== pConstantData
) {
167 return D3DERR_INVALIDCALL
;
169 if (Vector4iCount
> 1) {
170 CONST
int* f
= pConstantData
;
172 TRACE("(%p) : SetVertexShaderConstantI C[%u..%u]=\n", This
, Register
, Register
+ Vector4iCount
- 1);
173 for (i
= 0; i
< Vector4iCount
; ++i
) {
174 TRACE("{%d, %d, %d, %d}\n", f
[0], f
[1], f
[2], f
[3]);
178 CONST
int* f
= pConstantData
;
179 TRACE("(%p) : SetVertexShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This
, Register
, f
[0], f
[1], f
[2], f
[3]);
181 This
->UpdateStateBlock
->Changed
.vertexShaderConstant
= TRUE
;
182 memcpy(&This
->UpdateStateBlock
->vertexShaderConstantI
[Register
], pConstantData
, Vector4iCount
* 4 * sizeof(int));
186 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface
, UINT Register
, int* pConstantData
, UINT Vector4iCount
) {
187 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
189 TRACE("(%p) : C[%u] count=%u\n", This
, Register
, Vector4iCount
);
190 if (Register
+ Vector4iCount
> D3D_VSHADER_MAX_CONSTANTS
) {
191 return D3DERR_INVALIDCALL
;
193 if (NULL
== pConstantData
) {
194 return D3DERR_INVALIDCALL
;
196 memcpy(pConstantData
, &This
->UpdateStateBlock
->vertexShaderConstantI
[Register
], Vector4iCount
* 4 * sizeof(FLOAT
));
200 HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface
, UINT Register
, CONST BOOL
* pConstantData
, UINT BoolCount
) {
201 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
204 if (Register
+ BoolCount
> D3D_VSHADER_MAX_CONSTANTS
) {
205 ERR("(%p) : SetVertexShaderConstantB C[%u] invalid\n", This
, Register
);
206 return D3DERR_INVALIDCALL
;
208 if (NULL
== pConstantData
) {
209 return D3DERR_INVALIDCALL
;
212 CONST BOOL
* f
= pConstantData
;
213 TRACE("(%p) : SetVertexShaderConstantB C[%u..%u]=\n", This
, Register
, Register
+ BoolCount
- 1);
214 for (i
= 0; i
< BoolCount
; ++i
) {
215 TRACE("{%u}\n", f
[i
]);
218 CONST BOOL
* f
= pConstantData
;
219 TRACE("(%p) : SetVertexShaderConstantB, C[%u]={%u}\n", This
, Register
, f
[0]);
221 This
->UpdateStateBlock
->Changed
.vertexShaderConstant
= TRUE
;
222 for (i
= 0; i
< BoolCount
; ++i
) {
223 This
->UpdateStateBlock
->vertexShaderConstantB
[Register
] = pConstantData
[i
];
228 HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface
, UINT Register
, BOOL
* pConstantData
, UINT BoolCount
) {
229 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
230 FIXME("(%p) : stub\n", This
);