vertexshader.c 9.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * IDirect3DVertexShader9 implementation
 *
 * Copyright 2002-2003 Jason Edmeades
 *                     Raphael Junqueira
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24
 */

#include "config.h"
#include "d3d9_private.h"

25
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26 27

/* IDirect3DVertexShader9 IUnknown parts follow: */
28
static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29
    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
30 31 32

    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
33
        IUnknown_AddRef(iface);
34
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
35
        return S_OK;
36 37 38
    }

    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
H. Verbeet's avatar
H. Verbeet committed
39
    *ppobj = NULL;
40 41 42
    return E_NOINTERFACE;
}

43
static ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
44
    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
45 46
    ULONG ref = InterlockedIncrement(&This->ref);

47
    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
48 49

    return ref;
50 51
}

52
static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
53
    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
54 55
    ULONG ref = InterlockedDecrement(&This->ref);

56
    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
57 58

    if (ref == 0) {
59
        EnterCriticalSection(&d3d9_cs);
60
        IWineD3DVertexShader_Release(This->wineD3DVertexShader);
61
        LeaveCriticalSection(&d3d9_cs);
62
        IUnknown_Release(This->parentDevice);
63 64 65 66 67 68
        HeapFree(GetProcessHeap(), 0, This);
    }
    return ref;
}

/* IDirect3DVertexShader9 Interface follow: */
69
static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
70
    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
71 72 73 74
    IWineD3DDevice *myDevice = NULL;
    HRESULT hr = D3D_OK;
    TRACE("(%p) : Relay\n", This);

75
    EnterCriticalSection(&d3d9_cs);
76 77 78 79 80 81
    if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
        hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
        IWineD3DDevice_Release(myDevice);
    } else {
        *ppDevice = NULL;
    }
82
    LeaveCriticalSection(&d3d9_cs);
83
    TRACE("(%p) returning (%p)\n", This, *ppDevice);
84
    return hr;
85 86
}

87
static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
88
    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
89
    HRESULT hr;
90
    TRACE("(%p) : Relay\n", This);
91 92 93 94 95

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
96 97 98
}


99
static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
100
{
101
    /* IUnknown */
102 103
    IDirect3DVertexShader9Impl_QueryInterface,
    IDirect3DVertexShader9Impl_AddRef,
104 105
    IDirect3DVertexShader9Impl_Release,
    /* IDirect3DVertexShader9 */
106 107 108 109 110 111 112
    IDirect3DVertexShader9Impl_GetDevice,
    IDirect3DVertexShader9Impl_GetFunction
};


/* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
113
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
114 115 116 117 118 119 120
    HRESULT hrc = D3D_OK;
    IDirect3DVertexShader9Impl *object;

    /* Setup a stub object for now */
    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
    if (NULL == object) {
121
        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
122 123 124 125 126
        return D3DERR_OUTOFVIDEOMEMORY;
    }

    object->ref = 1;
    object->lpVtbl = &Direct3DVertexShader9_Vtbl;
127
    EnterCriticalSection(&d3d9_cs);
128
    hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, NULL /* declaration */, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
129
    LeaveCriticalSection(&d3d9_cs);
130 131

    if (FAILED(hrc)) {
132

133 134 135 136
        /* free up object */
        FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
        HeapFree(GetProcessHeap(), 0, object);
    }else{
137 138
        IUnknown_AddRef(iface);
        object->parentDevice = iface;
139
        *ppShader = (IDirect3DVertexShader9 *)object;
140
        TRACE("(%p) : Created vertex shader %p\n", This, object);
141 142 143 144
    }

    TRACE("(%p) : returning %p\n", This, *ppShader);
    return hrc;
145 146 147
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
148
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
149 150
    HRESULT hrc = D3D_OK;

151
    TRACE("(%p) : Relay\n", This);
152
    EnterCriticalSection(&d3d9_cs);
153
    hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
154
    LeaveCriticalSection(&d3d9_cs);
155

156
    TRACE("(%p) : returning hr(%u)\n", This, hrc);
157
    return hrc;
158 159 160
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9** ppShader) {
161
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
162 163 164
    IWineD3DVertexShader *pShader;
    HRESULT hrc = D3D_OK;

165
    TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
166
    EnterCriticalSection(&d3d9_cs);
167
    hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
168
    if(hrc == D3D_OK && pShader != NULL){
169 170 171
       hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
       IWineD3DVertexShader_Release(pShader);
    } else {
172
        WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
173
    }
174
    LeaveCriticalSection(&d3d9_cs);
175 176
    TRACE("(%p) : returning %p\n", This, *ppShader);
    return hrc;
177 178 179
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
180
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
181
    HRESULT hr;
182
    TRACE("(%p) : Relay\n", This);
183 184 185 186 187

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
188 189 190
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
191
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
192 193
    HRESULT hr;

194
    TRACE("(%p) : Relay\n", This);
195 196 197 198
    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
199 200 201
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
202
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
203
    HRESULT hr;
204
    TRACE("(%p) : Relay\n", This);
205 206 207 208 209

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
210 211 212
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
213
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
214
    HRESULT hr;
215
    TRACE("(%p) : Relay\n", This);
216 217 218 219 220

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
221 222 223
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
224
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
225
    HRESULT hr;
226
    TRACE("(%p) : Relay\n", This);
227 228 229 230 231

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
232 233 234
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
235
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
236
    HRESULT hr;
237
    TRACE("(%p) : Relay\n", This);
238 239 240 241 242

    EnterCriticalSection(&d3d9_cs);
    hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
    LeaveCriticalSection(&d3d9_cs);
    return hr;
243
}