vertexshader.c 8.15 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
        IWineD3DVertexShader_Release(This->wineD3DVertexShader);
60
        IUnknown_Release(This->parentDevice);
61 62 63 64 65 66
        HeapFree(GetProcessHeap(), 0, This);
    }
    return ref;
}

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

    if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
        hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
        IWineD3DDevice_Release(myDevice);
    } else {
        *ppDevice = NULL;
    }
79
    TRACE("(%p) returning (%p)\n", This, *ppDevice);
80
    return hr;
81 82
}

83
static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
84
    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
85 86 87

    TRACE("(%p) : Relay\n", This);
    return IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
88 89 90
}


91
static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
92
{
93
    /* IUnknown */
94 95
    IDirect3DVertexShader9Impl_QueryInterface,
    IDirect3DVertexShader9Impl_AddRef,
96 97
    IDirect3DVertexShader9Impl_Release,
    /* IDirect3DVertexShader9 */
98 99 100 101 102 103 104
    IDirect3DVertexShader9Impl_GetDevice,
    IDirect3DVertexShader9Impl_GetFunction
};


/* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
105
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
106 107 108 109 110 111 112
    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) {
113
        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
114 115 116 117 118
        return D3DERR_OUTOFVIDEOMEMORY;
    }

    object->ref = 1;
    object->lpVtbl = &Direct3DVertexShader9_Vtbl;
119
    hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, NULL /* declaration */, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
120 121

    if (FAILED(hrc)) {
122

123 124 125 126
        /* free up object */
        FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
        HeapFree(GetProcessHeap(), 0, object);
    }else{
127 128
        IUnknown_AddRef(iface);
        object->parentDevice = iface;
129
        *ppShader = (IDirect3DVertexShader9 *)object;
130
        TRACE("(%p) : Created vertex shader %p\n", This, object);
131 132 133 134
    }

    TRACE("(%p) : returning %p\n", This, *ppShader);
    return hrc;
135 136 137
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
138
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
139 140
    HRESULT hrc = D3D_OK;

141
    TRACE("(%p) : Relay\n", This);
142 143
    hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);

144
    TRACE("(%p) : returning hr(%u)\n", This, hrc);
145
    return hrc;
146 147 148
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9** ppShader) {
149
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
150 151 152
    IWineD3DVertexShader *pShader;
    HRESULT hrc = D3D_OK;

153
    TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
154
    hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
155
    if(hrc == D3D_OK && pShader != NULL){
156 157 158
       hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
       IWineD3DVertexShader_Release(pShader);
    } else {
159
        WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
160 161 162
    }
    TRACE("(%p) : returning %p\n", This, *ppShader);
    return hrc;
163 164 165
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
166 167 168
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    TRACE("(%p) : Relay\n", This);
    return IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
169 170 171
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
172 173 174
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    TRACE("(%p) : Relay\n", This);
    return IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
175 176 177
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
178 179 180
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    TRACE("(%p) : Relay\n", This);
    return IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
181 182 183
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
184 185 186
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    TRACE("(%p) : Relay\n", This);
    return IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
187 188 189
}

HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
190 191 192
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    TRACE("(%p) : Relay\n", This);
    return IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
193 194 195
}

HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
196
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
197 198
    TRACE("(%p) : Relay\n", This);
    return IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
199
}