Removed some more uses of the non-standard ICOM_THIS macro.
[wine/multimedia.git] / dlls / d3d9 / pixelshader.c
blobb6f12da36566b721729f7b23e95f2b9b7c39e17a
1 /*
2 * IDirect3DPixelShader9 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
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
22 #include "config.h"
24 #include <stdarg.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "wingdi.h"
32 #include "wine/debug.h"
34 #include "d3d9_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
38 /* IDirect3DPixelShader9 IUnknown parts follow: */
39 HRESULT WINAPI IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSHADER9 iface, REFIID riid, LPVOID* ppobj) {
40 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
42 if (IsEqualGUID(riid, &IID_IUnknown)
43 || IsEqualGUID(riid, &IID_IDirect3DPixelShader9)) {
44 IDirect3DPixelShader9Impl_AddRef(iface);
45 *ppobj = This;
46 return D3D_OK;
49 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
50 return E_NOINTERFACE;
53 ULONG WINAPI IDirect3DPixelShader9Impl_AddRef(LPDIRECT3DPIXELSHADER9 iface) {
54 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
55 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
56 return ++(This->ref);
59 ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface) {
60 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
61 ULONG ref = --This->ref;
63 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
64 if (ref == 0) {
65 HeapFree(GetProcessHeap(), 0, This);
67 return ref;
70 /* IDirect3DPixelShader9 Interface follow: */
71 HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface, IDirect3DDevice9** ppDevice) {
72 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
73 TRACE("(%p) : returning %p\n", This, This->Device);
74 *ppDevice = (LPDIRECT3DDEVICE9) This->Device;
75 IDirect3DDevice9Impl_AddRef(*ppDevice);
76 return D3D_OK;
79 HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
80 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
81 FIXME("(%p): stub\n", This);
82 return D3D_OK;
86 IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl =
88 IDirect3DPixelShader9Impl_QueryInterface,
89 IDirect3DPixelShader9Impl_AddRef,
90 IDirect3DPixelShader9Impl_Release,
91 IDirect3DPixelShader9Impl_GetDevice,
92 IDirect3DPixelShader9Impl_GetFunction
96 /* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow: */
97 HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) {
98 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
99 FIXME("(%p) : stub\n", This);
100 return D3D_OK;
103 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9* pShader) {
104 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
106 This->UpdateStateBlock->PixelShader = pShader;
107 This->UpdateStateBlock->Changed.pixelShader = TRUE;
108 This->UpdateStateBlock->Set.pixelShader = TRUE;
110 /* Handle recording of state blocks */
111 if (This->isRecordingState) {
112 TRACE("Recording... not performing anything\n");
113 return D3D_OK;
116 * TODO: merge HAL shaders context switching from prototype
118 return D3D_OK;
121 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9** ppShader) {
122 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
123 TRACE("(%p) : GetPixelShader returning %p\n", This, This->StateBlock->PixelShader);
124 *ppShader = This->StateBlock->PixelShader;
125 IDirect3DPixelShader9Impl_AddRef(*ppShader);
126 return D3D_OK;
129 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
130 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
132 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
133 ERR("(%p) : SetPixelShaderConstant C[%u] invalid\n", This, Register);
134 return D3DERR_INVALIDCALL;
136 if (NULL == pConstantData) {
137 return D3DERR_INVALIDCALL;
139 if (Vector4fCount > 1) {
140 CONST FLOAT* f = pConstantData;
141 UINT i;
142 TRACE("(%p) : SetPixelShaderConstant C[%u..%u]=\n", This, Register, Register + Vector4fCount - 1);
143 for (i = 0; i < Vector4fCount; ++i) {
144 TRACE("{%f, %f, %f, %f}\n", f[0], f[1], f[2], f[3]);
145 f += 4;
147 } else {
148 FLOAT* f = (FLOAT*) pConstantData;
149 TRACE("(%p) : SetPixelShaderConstant, C[%u]={%f, %f, %f, %f}\n", This, Register, f[0], f[1], f[2], f[3]);
151 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
152 memcpy(&This->UpdateStateBlock->pixelShaderConstantF[Register], pConstantData, Vector4fCount * 4 * sizeof(FLOAT));
153 return D3D_OK;
156 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
157 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
159 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4fCount);
160 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
161 return D3DERR_INVALIDCALL;
163 if (NULL == pConstantData) {
164 return D3DERR_INVALIDCALL;
166 memcpy(pConstantData, &This->UpdateStateBlock->pixelShaderConstantF[Register], Vector4fCount * 4 * sizeof(FLOAT));
167 return D3D_OK;
170 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
171 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
173 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
174 ERR("(%p) : SetPixelShaderConstantI C[%u] invalid\n", This, Register);
175 return D3DERR_INVALIDCALL;
177 if (NULL == pConstantData) {
178 return D3DERR_INVALIDCALL;
180 if (Vector4iCount > 1) {
181 CONST int* f = pConstantData;
182 UINT i;
183 TRACE("(%p) : SetPixelShaderConstantI C[%u..%u]=\n", This, Register, Register + Vector4iCount - 1);
184 for (i = 0; i < Vector4iCount; ++i) {
185 TRACE("{%d, %d, %d, %d}\n", f[0], f[1], f[2], f[3]);
186 f += 4;
188 } else {
189 CONST int* f = pConstantData;
190 TRACE("(%p) : SetPixelShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This, Register, f[0], f[1], f[2], f[3]);
192 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
193 memcpy(&This->UpdateStateBlock->pixelShaderConstantI[Register], pConstantData, Vector4iCount * 4 * sizeof(int));
194 return D3D_OK;
197 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
198 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
200 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4iCount);
201 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
202 return D3DERR_INVALIDCALL;
204 if (NULL == pConstantData) {
205 return D3DERR_INVALIDCALL;
207 memcpy(pConstantData, &This->UpdateStateBlock->pixelShaderConstantI[Register], Vector4iCount * 4 * sizeof(FLOAT));
208 return D3D_OK;
211 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
212 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
213 UINT i;
215 if (Register + BoolCount > D3D_VSHADER_MAX_CONSTANTS) {
216 ERR("(%p) : SetPixelShaderConstantB C[%u] invalid\n", This, Register);
217 return D3DERR_INVALIDCALL;
219 if (NULL == pConstantData) {
220 return D3DERR_INVALIDCALL;
222 if (BoolCount > 1) {
223 CONST BOOL* f = pConstantData;
224 TRACE("(%p) : SetPixelShaderConstantB C[%u..%u]=\n", This, Register, Register + BoolCount - 1);
225 for (i = 0; i < BoolCount; ++i) {
226 TRACE("{%u}\n", f[i]);
228 } else {
229 CONST BOOL* f = pConstantData;
230 TRACE("(%p) : SetPixelShaderConstantB, C[%u]={%u}\n", This, Register, f[0]);
232 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
233 for (i = 0; i < BoolCount; ++i) {
234 This->UpdateStateBlock->pixelShaderConstantB[Register] = pConstantData[i];
236 return D3D_OK;
239 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
240 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
241 FIXME("(%p) : stub\n", This);
242 return D3D_OK;