pixelshader.c 9.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * IDirect3DPixelShader9 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

/* IDirect3DPixelShader9 IUnknown parts follow: */
28
static HRESULT WINAPI IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29
    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
30

Henri Verbeet's avatar
Henri Verbeet committed
31 32
    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);

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

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

45
static ULONG WINAPI IDirect3DPixelShader9Impl_AddRef(LPDIRECT3DPIXELSHADER9 iface) {
46
    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
47 48
    ULONG ref = InterlockedIncrement(&This->ref);

Henri Verbeet's avatar
Henri Verbeet committed
49
    TRACE("%p increasing refcount to %u.\n", iface, ref);
50

51 52 53 54 55 56 57 58
    if (ref == 1)
    {
        IDirect3DDevice9Ex_AddRef(This->parentDevice);
        wined3d_mutex_lock();
        IWineD3DPixelShader_AddRef(This->wineD3DPixelShader);
        wined3d_mutex_unlock();
    }

59
    return ref;
60 61
}

62
static ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface) {
63
    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
64 65
    ULONG ref = InterlockedDecrement(&This->ref);

Henri Verbeet's avatar
Henri Verbeet committed
66
    TRACE("%p decreasing refcount to %u.\n", iface, ref);
67 68

    if (ref == 0) {
69 70
        IDirect3DDevice9Ex *parentDevice = This->parentDevice;

71
        wined3d_mutex_lock();
72
        IWineD3DPixelShader_Release(This->wineD3DPixelShader);
73
        wined3d_mutex_unlock();
74 75 76

        /* Release the device last, as it may cause the device to be destroyed. */
        IDirect3DDevice9Ex_Release(parentDevice);
77 78 79 80 81
    }
    return ref;
}

/* IDirect3DPixelShader9 Interface follow: */
82 83
static HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
{
84
    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
85

86
    TRACE("iface %p, device %p.\n", iface, device);
87

88 89 90 91
    *device = (IDirect3DDevice9 *)This->parentDevice;
    IDirect3DDevice9_AddRef(*device);

    TRACE("Returning device %p.\n", *device);
92

93 94 95
    return D3D_OK;
}

96
static HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
97
    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
98
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
99 100

    TRACE("iface %p, data %p, data_size %p.\n", iface, pData, pSizeOfData);
101

102
    wined3d_mutex_lock();
103
    hr = IWineD3DPixelShader_GetFunction(This->wineD3DPixelShader, pData, pSizeOfData);
104 105
    wined3d_mutex_unlock();

106
    return hr;
107 108 109
}


110
static const IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl =
111
{
112
    /* IUnknown */
113 114 115
    IDirect3DPixelShader9Impl_QueryInterface,
    IDirect3DPixelShader9Impl_AddRef,
    IDirect3DPixelShader9Impl_Release,
116
    /* IDirect3DPixelShader9 */
117 118 119 120
    IDirect3DPixelShader9Impl_GetDevice,
    IDirect3DPixelShader9Impl_GetFunction
};

121 122 123 124 125 126 127 128 129 130
static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
{
    HeapFree(GetProcessHeap(), 0, parent);
}

static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
{
    d3d9_pixelshader_wined3d_object_destroyed,
};

131 132 133
HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
{
    HRESULT hr;
134

135 136
    shader->ref = 1;
    shader->lpVtbl = &Direct3DPixelShader9_Vtbl;
137 138

    wined3d_mutex_lock();
139
    hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
140 141
            NULL, &shader->wineD3DPixelShader, (IUnknown *)shader,
            &d3d9_pixelshader_wined3d_parent_ops);
142
    wined3d_mutex_unlock();
143
    if (FAILED(hr))
144
    {
145 146
        WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
        return hr;
147 148
    }

149 150 151 152
    shader->parentDevice = (IDirect3DDevice9Ex *)device;
    IDirect3DDevice9Ex_AddRef(shader->parentDevice);

    return D3D_OK;
153 154
}

155
HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader) {
156
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
157
    IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
Henri Verbeet's avatar
Henri Verbeet committed
158 159

    TRACE("iface %p, shader %p.\n", iface, shader);
160

161
    wined3d_mutex_lock();
162
    IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
163 164
    wined3d_mutex_unlock();

165 166 167
    return D3D_OK;
}

168
HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader) {
169
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
170
    IWineD3DPixelShader *object;
Henri Verbeet's avatar
Henri Verbeet committed
171 172 173
    HRESULT hrc;

    TRACE("iface %p, shader %p.\n", iface, ppShader);
174

175
    if (ppShader == NULL) {
176 177 178 179
        TRACE("(%p) Invalid call\n", This);
        return D3DERR_INVALIDCALL;
    }

180
    wined3d_mutex_lock();
181
    hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    if (SUCCEEDED(hrc))
    {
        if (object)
        {
            hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)ppShader);
            IWineD3DPixelShader_Release(object);
        }
        else
        {
            *ppShader = NULL;
        }
    }
    else
    {
        WARN("(%p) : Call to IWineD3DDevice_GetPixelShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
197
    }
198
    wined3d_mutex_unlock();
199 200 201

    TRACE("(%p) : returning %p\n", This, *ppShader);
    return hrc;
202 203
}

204
HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
205
   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
206
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
207 208 209

    TRACE("iface %p, register %u, data %p, count %u.\n",
            iface, Register, pConstantData, Vector4fCount);
210

211
    wined3d_mutex_lock();
212
    hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
213 214
    wined3d_mutex_unlock();

215
    return hr;
216 217
}

218
HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
219
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
Henri Verbeet's avatar
Henri Verbeet committed
220 221
    HRESULT hr;

Henri Verbeet's avatar
Henri Verbeet committed
222 223
    TRACE("iface %p, register %u, data %p, count %u.\n",
            iface, Register, pConstantData, Vector4fCount);
Henri Verbeet's avatar
Henri Verbeet committed
224

225
    wined3d_mutex_lock();
Henri Verbeet's avatar
Henri Verbeet committed
226
    hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
227
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
228 229

    return hr;
230 231
}

232
HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
233
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
234
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
235 236 237

    TRACE("iface %p, register %u, data %p, count %u.\n",
            iface, Register, pConstantData, Vector4iCount);
238

239
    wined3d_mutex_lock();
240
    hr = IWineD3DDevice_SetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
241 242
    wined3d_mutex_unlock();

243
    return hr;
244 245
}

246
HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
247
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
248
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
249 250 251

    TRACE("iface %p, register %u, data %p, count %u.\n",
            iface, Register, pConstantData, Vector4iCount);
252

253
    wined3d_mutex_lock();
254
    hr = IWineD3DDevice_GetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
255 256
    wined3d_mutex_unlock();

257
    return hr;
258 259
}

260
HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
261
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
262
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
263 264 265

    TRACE("iface %p, register %u, data %p, count %u.\n",
            iface, Register, pConstantData, BoolCount);
266

267
    wined3d_mutex_lock();
268
    hr = IWineD3DDevice_SetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
269 270
    wined3d_mutex_unlock();

271
    return hr;
272 273
}

274
HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
275
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
276
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
277 278 279

    TRACE("iface %p, register %u, data %p, count %u.\n",
            iface, Register, pConstantData, BoolCount);
280

281
    wined3d_mutex_lock();
282
    hr = IWineD3DDevice_GetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
283 284
    wined3d_mutex_unlock();

285
    return hr;
286
}