ddraw/tests: Rewrite StructSizeTest().
[wine.git] / dlls / d3d8 / d3d8_main.c
blob8ac704c364c32eb58b9f675a105732676f85293e
1 /*
2 * Direct3D 8
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "initguid.h"
24 #include "d3d8_private.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
29 HRESULT WINAPI D3D8GetSWInfo(void) {
30 FIXME("(void): stub\n");
31 return 0;
34 void WINAPI DebugSetMute(void) {
35 /* nothing to do */
38 IDirect3D8 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate8(UINT sdk_version)
40 struct d3d8 *object;
42 TRACE("sdk_version %#x.\n", sdk_version);
44 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
45 return NULL;
47 if (!d3d8_init(object))
49 WARN("Failed to initialize d3d8.\n");
50 HeapFree(GetProcessHeap(), 0, object);
51 return NULL;
54 TRACE("Created d3d8 object %p.\n", object);
56 return &object->IDirect3D8_iface;
59 /***********************************************************************
60 * ValidateVertexShader (D3D8.@)
62 * I've seen reserved1 and reserved2 always passed as 0's
63 * bool seems always passed as 0 or 1, but other values work as well...
64 * toto result?
66 HRESULT WINAPI ValidateVertexShader(DWORD* vertexshader, DWORD* reserved1, DWORD* reserved2, BOOL bool, DWORD* toto)
68 HRESULT ret;
69 static BOOL warned;
71 if (TRACE_ON(d3d8) || !warned) {
72 FIXME("(%p %p %p %d %p): stub\n", vertexshader, reserved1, reserved2, bool, toto);
73 warned = TRUE;
76 if (!vertexshader)
77 return E_FAIL;
79 if (reserved1 || reserved2)
80 return E_FAIL;
82 switch(*vertexshader) {
83 case 0xFFFE0101:
84 case 0xFFFE0100:
85 ret=S_OK;
86 break;
87 default:
88 WARN("Invalid shader version token %#x.\n", *vertexshader);
89 ret=E_FAIL;
92 return ret;
95 /***********************************************************************
96 * ValidatePixelShader (D3D8.@)
98 * PARAMS
99 * toto result?
101 HRESULT WINAPI ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, BOOL bool, DWORD* toto)
103 HRESULT ret;
104 static BOOL warned;
106 if (TRACE_ON(d3d8) || !warned) {
107 FIXME("(%p %p %d %p): stub\n", pixelshader, reserved1, bool, toto);
108 warned = TRUE;
111 if (!pixelshader)
112 return E_FAIL;
114 if (reserved1)
115 return E_FAIL;
117 switch(*pixelshader) {
118 case 0xFFFF0100:
119 case 0xFFFF0101:
120 case 0xFFFF0102:
121 case 0xFFFF0103:
122 case 0xFFFF0104:
123 ret=S_OK;
124 break;
125 default:
126 WARN("Invalid shader version token %#x.\n", *pixelshader);
127 ret=E_FAIL;
129 return ret;
132 void d3d8_resource_cleanup(struct d3d8_resource *resource)
134 wined3d_private_store_cleanup(&resource->private_store);
137 HRESULT d3d8_resource_free_private_data(struct d3d8_resource *resource, const GUID *guid)
139 struct wined3d_private_data *entry;
141 wined3d_mutex_lock();
142 entry = wined3d_private_store_get_private_data(&resource->private_store, guid);
143 if (!entry)
145 wined3d_mutex_unlock();
146 return D3DERR_NOTFOUND;
149 wined3d_private_store_free_private_data(&resource->private_store, entry);
150 wined3d_mutex_unlock();
152 return D3D_OK;
155 HRESULT d3d8_resource_get_private_data(struct d3d8_resource *resource, const GUID *guid,
156 void *data, DWORD *data_size)
158 const struct wined3d_private_data *stored_data;
159 DWORD size_in;
160 HRESULT hr;
162 wined3d_mutex_lock();
163 stored_data = wined3d_private_store_get_private_data(&resource->private_store, guid);
164 if (!stored_data)
166 hr = D3DERR_NOTFOUND;
167 goto done;
170 size_in = *data_size;
171 *data_size = stored_data->size;
172 if (!data)
174 hr = D3D_OK;
175 goto done;
177 if (size_in < stored_data->size)
179 hr = D3DERR_MOREDATA;
180 goto done;
183 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
184 IUnknown_AddRef(stored_data->content.object);
185 memcpy(data, stored_data->content.data, stored_data->size);
186 hr = D3D_OK;
188 done:
189 wined3d_mutex_unlock();
190 return hr;
193 void d3d8_resource_init(struct d3d8_resource *resource)
195 resource->refcount = 1;
196 wined3d_private_store_init(&resource->private_store);
199 HRESULT d3d8_resource_set_private_data(struct d3d8_resource *resource, const GUID *guid,
200 const void *data, DWORD data_size, DWORD flags)
202 HRESULT hr;
204 wined3d_mutex_lock();
205 hr = wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags);
206 wined3d_mutex_unlock();
207 return hr;