VirtualBox

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

Last change on this file since 30720 was 25949, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.36 and disable unnecessary fbo state poll

  • Property svn:eol-style set to native
File size: 6.6 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 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
41
42 if (IsEqualGUID(riid, &IID_IUnknown)
43 || IsEqualGUID(riid, &IID_IDirect3DVertexShader8)) {
44 IUnknown_AddRef(iface);
45 *ppobj = This;
46 return S_OK;
47 }
48
49 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
50 *ppobj = NULL;
51 return E_NOINTERFACE;
52}
53
54static ULONG WINAPI IDirect3DVertexShader8Impl_AddRef(IDirect3DVertexShader8 *iface) {
55 IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
56 ULONG ref = InterlockedIncrement(&This->ref);
57
58 TRACE("%p increasing refcount to %u.\n", iface, ref);
59
60 if (ref == 1 && This->wineD3DVertexShader)
61 {
62 wined3d_mutex_lock();
63 IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
64 wined3d_mutex_unlock();
65 }
66
67 return ref;
68}
69
70static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
71{
72 IDirect3DVertexShader8Impl *shader = parent;
73 IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
74 HeapFree(GetProcessHeap(), 0, shader);
75}
76
77static ULONG WINAPI IDirect3DVertexShader8Impl_Release(IDirect3DVertexShader8 *iface) {
78 IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
79 ULONG ref = InterlockedDecrement(&This->ref);
80
81 TRACE("%p decreasing refcount to %u.\n", iface, ref);
82
83 if (ref == 0) {
84 if (This->wineD3DVertexShader)
85 {
86 wined3d_mutex_lock();
87 IWineD3DVertexShader_Release(This->wineD3DVertexShader);
88 wined3d_mutex_unlock();
89 }
90 else
91 {
92 d3d8_vertexshader_wined3d_object_destroyed(This);
93 }
94 }
95 return ref;
96}
97
98static const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl =
99{
100 /* IUnknown */
101 IDirect3DVertexShader8Impl_QueryInterface,
102 IDirect3DVertexShader8Impl_AddRef,
103 IDirect3DVertexShader8Impl_Release,
104};
105
106static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
107{
108 d3d8_vertexshader_wined3d_object_destroyed,
109};
110
111static HRESULT vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *device,
112 const DWORD *declaration, DWORD shader_handle, IDirect3DVertexDeclaration8 **decl_ptr)
113{
114 IDirect3DVertexDeclaration8Impl *object;
115 HRESULT hr;
116
117 TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
118 device, declaration, shader_handle, decl_ptr);
119
120 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
121 if (!object) {
122 ERR("Memory allocation failed\n");
123 *decl_ptr = NULL;
124 return D3DERR_OUTOFVIDEOMEMORY;
125 }
126
127 hr = vertexdeclaration_init(object, device, declaration, shader_handle);
128 if (FAILED(hr))
129 {
130 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
131 HeapFree(GetProcessHeap(), 0, object);
132 return hr;
133 }
134
135 TRACE("Created vertex declaration %p.\n", object);
136 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
137
138 return D3D_OK;
139}
140
141HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
142 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
143{
144 const DWORD *token = declaration;
145 HRESULT hr;
146
147 /* Test if the vertex declaration is valid */
148 while (D3DVSD_END() != *token)
149 {
150 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
151
152 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
153 {
154 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
155 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
156
157 if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
158 {
159 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
160 return D3DERR_INVALIDCALL;
161 }
162 }
163 token += parse_token(token);
164 }
165
166 shader->ref = 1;
167 shader->lpVtbl = &Direct3DVertexShader8_Vtbl;
168
169 hr = vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
170 if (FAILED(hr))
171 {
172 WARN("Failed to create vertex declaration, hr %#x.\n", hr);
173 return hr;
174 }
175
176 if (byte_code)
177 {
178 if (usage) FIXME("Usage %#x not implemented.\n", usage);
179
180 wined3d_mutex_lock();
181 hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
182 NULL /* output signature */, &shader->wineD3DVertexShader,
183 (IUnknown *)shader, &d3d8_vertexshader_wined3d_parent_ops);
184 wined3d_mutex_unlock();
185 if (FAILED(hr))
186 {
187 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
188 IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
189 return hr;
190 }
191
192 load_local_constants(declaration, shader->wineD3DVertexShader);
193 }
194
195 return D3D_OK;
196}
Note: See TracBrowser for help on using the repository browser.

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