wined3d: Tidy up pshader_hw_texreg2rgb and friends.
[wine] / dlls / d3dx8 / core.c
1 /*
2  *
3  * Copyright 2002 Raphael Junqueira
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include <stdarg.h>
21
22 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
28
29 #include "d3dx8_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
32
33 /* ID3DXBuffer IUnknown parts follow: */
34 static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(LPD3DXBUFFER iface, REFIID riid, LPVOID* ppobj) {
35   ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
36
37   if (IsEqualGUID(riid, &IID_IUnknown)
38       || IsEqualGUID(riid, &IID_ID3DXBuffer)) {
39     IUnknown_AddRef(iface);
40     *ppobj = This;
41     return D3D_OK;
42   }
43
44   WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
45   return E_NOINTERFACE;
46 }
47
48 static ULONG WINAPI ID3DXBufferImpl_AddRef(LPD3DXBUFFER iface) {
49   ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
50   ULONG ref = InterlockedIncrement(&This->ref);
51
52   TRACE("(%p) : AddRef from %d\n", This, ref - 1);
53
54   return ref;
55 }
56
57 static ULONG WINAPI ID3DXBufferImpl_Release(LPD3DXBUFFER iface) {
58   ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
59   ULONG ref = InterlockedDecrement(&This->ref);
60
61   TRACE("(%p) : ReleaseRef to %d\n", This, ref);
62
63   if (ref == 0) {
64     HeapFree(GetProcessHeap(), 0, This->buffer);
65     HeapFree(GetProcessHeap(), 0, This);
66   }
67   return ref;
68 }
69
70 /* ID3DXBuffer Interface follow: */
71 static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(LPD3DXBUFFER iface) {
72   ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
73   return This->buffer;
74 }
75
76 static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(LPD3DXBUFFER iface) {
77   ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
78   return This->bufferSize;
79 }
80
81 const ID3DXBufferVtbl D3DXBuffer_Vtbl =
82 {
83     ID3DXBufferImpl_QueryInterface,
84     ID3DXBufferImpl_AddRef,
85     ID3DXBufferImpl_Release,
86     ID3DXBufferImpl_GetBufferPointer,
87     ID3DXBufferImpl_GetBufferSize
88 };
89
90 HRESULT WINAPI D3DXCreateBuffer(DWORD NumBytes, LPD3DXBUFFER* ppBuffer) {
91   ID3DXBufferImpl *object;
92
93   object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXBufferImpl));
94   if (NULL == object) {
95     *ppBuffer = NULL;
96     return E_OUTOFMEMORY;
97   }
98   object->lpVtbl = &D3DXBuffer_Vtbl;
99   object->ref = 1;
100   object->bufferSize = NumBytes;
101   object->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, NumBytes);
102   if (NULL == object->buffer) {
103     HeapFree(GetProcessHeap(), 0, object);
104     *ppBuffer = NULL;
105     return E_OUTOFMEMORY;
106   }
107   *ppBuffer = (LPD3DXBUFFER)object;
108   return D3D_OK;
109 }
110
111 HRESULT WINAPI D3DXAssembleShader(LPCVOID pSrcData, UINT SrcDataLen, DWORD Flags,
112                            LPD3DXBUFFER* ppConstants,
113                            LPD3DXBUFFER* ppCompiledShader,
114                            LPD3DXBUFFER* ppCompilationErrors) {
115   FIXME("(void): stub\n");
116   return D3D_OK;
117 }
118
119 HRESULT WINAPI D3DXAssembleShaderFromFileA(LPCSTR pSrcFile, DWORD Flags,
120                                     LPD3DXBUFFER* ppConstants,
121                                     LPD3DXBUFFER* ppCompiledShader,
122                                     LPD3DXBUFFER* ppCompilationErrors) {
123   LPWSTR pSrcFileW = NULL;
124   DWORD len;
125   HRESULT ret;
126
127   if (!pSrcFile) return D3DXERR_INVALIDDATA;
128
129   len = MultiByteToWideChar( CP_ACP, 0, pSrcFile, -1, NULL, 0 );
130   pSrcFileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
131   MultiByteToWideChar( CP_ACP, 0, pSrcFile, -1, pSrcFileW, len );
132   ret=D3DXAssembleShaderFromFileW(pSrcFileW, Flags, ppConstants, ppCompiledShader, ppCompilationErrors);
133   HeapFree( GetProcessHeap(), 0, pSrcFileW );
134   return ret;
135 }
136
137 HRESULT WINAPI D3DXAssembleShaderFromFileW(LPCWSTR pSrcFile, DWORD Flags,
138                                     LPD3DXBUFFER* ppConstants,
139                                     LPD3DXBUFFER* ppCompiledShader,
140                                     LPD3DXBUFFER* ppCompilationErrors) {
141   FIXME("(void): stub\n");
142   return D3D_OK;
143 }
144
145 HRESULT WINAPI D3DXCreateFont(LPDIRECT3DDEVICE8 pDevice, HFONT hFont, LPD3DXFONT* ppFont) {
146   FIXME("(void): stub\n");
147   return D3D_OK;
148 }