VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c@ 23793

Last change on this file since 23793 was 23571, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.30

  • Property svn:eol-style set to native
File size: 6.5 KB
Line 
1/*
2 * IDirect3DVertexShader8 implementation
3 *
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * 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 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30
31#include "config.h"
32#include "d3d8_private.h"
33
34WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
35
36/* IDirect3DVertexShader8 IUnknown parts follow: */
37static HRESULT WINAPI IDirect3DVertexShader8Impl_QueryInterface(IDirect3DVertexShader8 *iface, REFIID riid, LPVOID* ppobj) {
38 IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
39
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DVertexShader8)) {
42 IUnknown_AddRef(iface);
43 *ppobj = This;
44 return S_OK;
45 }
46
47 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
48 *ppobj = NULL;
49 return E_NOINTERFACE;
50}
51
52static ULONG WINAPI IDirect3DVertexShader8Impl_AddRef(IDirect3DVertexShader8 *iface) {
53 IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
54 ULONG ref = InterlockedIncrement(&This->ref);
55
56 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
57
58 if (ref == 1 && This->wineD3DVertexShader)
59 {
60 wined3d_mutex_lock();
61 IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
62 wined3d_mutex_unlock();
63 }
64
65 return ref;
66}
67
68static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
69{
70 IDirect3DVertexShader8Impl *shader = parent;
71 IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
72 HeapFree(GetProcessHeap(), 0, shader);
73}
74
75static ULONG WINAPI IDirect3DVertexShader8Impl_Release(IDirect3DVertexShader8 *iface) {
76 IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
77 ULONG ref = InterlockedDecrement(&This->ref);
78
79 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
80
81 if (ref == 0) {
82 if (This->wineD3DVertexShader)
83 {
84 wined3d_mutex_lock();
85 IWineD3DVertexShader_Release(This->wineD3DVertexShader);
86 wined3d_mutex_unlock();
87 }
88 else
89 {
90 d3d8_vertexshader_wined3d_object_destroyed(This);
91 }
92 }
93 return ref;
94}
95
96static const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl =
97{
98 /* IUnknown */
99 IDirect3DVertexShader8Impl_QueryInterface,
100 IDirect3DVertexShader8Impl_AddRef,
101 IDirect3DVertexShader8Impl_Release,
102};
103
104static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
105{
106 d3d8_vertexshader_wined3d_object_destroyed,
107};
108
109static HRESULT vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *device,
110 const DWORD *declaration, DWORD shader_handle, IDirect3DVertexDeclaration8 **decl_ptr)
111{
112 IDirect3DVertexDeclaration8Impl *object;
113 HRESULT hr;
114
115 TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
116 device, declaration, shader_handle, decl_ptr);
117
118 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
119 if (!object) {
120 ERR("Memory allocation failed\n");
121 *decl_ptr = NULL;
122 return D3DERR_OUTOFVIDEOMEMORY;
123 }
124
125 hr = vertexdeclaration_init(object, device, declaration, shader_handle);
126 if (FAILED(hr))
127 {
128 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
129 HeapFree(GetProcessHeap(), 0, object);
130 return hr;
131 }
132
133 TRACE("Created vertex declaration %p.\n", object);
134 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
135
136 return D3D_OK;
137}
138
139HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
140 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
141{
142 const DWORD *token = declaration;
143 HRESULT hr;
144
145 /* Test if the vertex declaration is valid */
146 while (D3DVSD_END() != *token)
147 {
148 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
149
150 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
151 {
152 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
153 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
154
155 if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
156 {
157 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
158 return D3DERR_INVALIDCALL;
159 }
160 }
161 token += parse_token(token);
162 }
163
164 shader->ref = 1;
165 shader->lpVtbl = &Direct3DVertexShader8_Vtbl;
166
167 hr = vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
168 if (FAILED(hr))
169 {
170 WARN("Failed to create vertex declaration, hr %#x.\n", hr);
171 return hr;
172 }
173
174 if (byte_code)
175 {
176 if (usage) FIXME("Usage %#x not implemented.\n", usage);
177
178 wined3d_mutex_lock();
179 hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
180 NULL /* output signature */, &shader->wineD3DVertexShader,
181 (IUnknown *)shader, &d3d8_vertexshader_wined3d_parent_ops);
182 wined3d_mutex_unlock();
183 if (FAILED(hr))
184 {
185 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
186 IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
187 return hr;
188 }
189
190 load_local_constants(declaration, shader->wineD3DVertexShader);
191 }
192
193 return D3D_OK;
194}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette