Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenshader.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2002-2003 Jason Edmeades 00003 * Raphael Junqueira 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00018 */ 00019 00020 #include "config.h" 00021 #include "d3d8_private.h" 00022 00023 WINE_DEFAULT_DEBUG_CHANNEL(d3d8); 00024 00025 static inline IDirect3DVertexShader8Impl *impl_from_IDirect3DVertexShader8(IDirect3DVertexShader8 *iface) 00026 { 00027 return CONTAINING_RECORD(iface, IDirect3DVertexShader8Impl, IDirect3DVertexShader8_iface); 00028 } 00029 00030 static HRESULT WINAPI d3d8_vertexshader_QueryInterface(IDirect3DVertexShader8 *iface, REFIID riid, void **object) 00031 { 00032 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); 00033 00034 if (IsEqualGUID(riid, &IID_IDirect3DVertexShader8) 00035 || IsEqualGUID(riid, &IID_IUnknown)) 00036 { 00037 IUnknown_AddRef(iface); 00038 *object = iface; 00039 return S_OK; 00040 } 00041 00042 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); 00043 00044 *object = NULL; 00045 return E_NOINTERFACE; 00046 } 00047 00048 static ULONG WINAPI d3d8_vertexshader_AddRef(IDirect3DVertexShader8 *iface) 00049 { 00050 IDirect3DVertexShader8Impl *shader = impl_from_IDirect3DVertexShader8(iface); 00051 ULONG refcount = InterlockedIncrement(&shader->ref); 00052 00053 TRACE("%p increasing refcount to %u.\n", iface, refcount); 00054 00055 if (refcount == 1 && shader->wined3d_shader) 00056 { 00057 wined3d_mutex_lock(); 00058 wined3d_shader_incref(shader->wined3d_shader); 00059 wined3d_mutex_unlock(); 00060 } 00061 00062 return refcount; 00063 } 00064 00065 static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent) 00066 { 00067 IDirect3DVertexShader8Impl *shader = parent; 00068 IDirect3DVertexDeclaration8_Release(shader->vertex_declaration); 00069 HeapFree(GetProcessHeap(), 0, shader); 00070 } 00071 00072 static ULONG WINAPI d3d8_vertexshader_Release(IDirect3DVertexShader8 *iface) 00073 { 00074 IDirect3DVertexShader8Impl *shader = impl_from_IDirect3DVertexShader8(iface); 00075 ULONG refcount = InterlockedDecrement(&shader->ref); 00076 00077 TRACE("%p decreasing refcount to %u.\n", iface, refcount); 00078 00079 if (!refcount) 00080 { 00081 if (shader->wined3d_shader) 00082 { 00083 wined3d_mutex_lock(); 00084 wined3d_shader_decref(shader->wined3d_shader); 00085 wined3d_mutex_unlock(); 00086 } 00087 else 00088 { 00089 d3d8_vertexshader_wined3d_object_destroyed(shader); 00090 } 00091 } 00092 00093 return refcount; 00094 } 00095 00096 static const IDirect3DVertexShader8Vtbl d3d8_vertexshader_vtbl = 00097 { 00098 /* IUnknown */ 00099 d3d8_vertexshader_QueryInterface, 00100 d3d8_vertexshader_AddRef, 00101 d3d8_vertexshader_Release, 00102 }; 00103 00104 static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops = 00105 { 00106 d3d8_vertexshader_wined3d_object_destroyed, 00107 }; 00108 00109 static HRESULT d3d8_vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *device, 00110 const DWORD *declaration, DWORD shader_handle, IDirect3DVertexDeclaration8 **decl_ptr) 00111 { 00112 IDirect3DVertexDeclaration8Impl *object; 00113 HRESULT hr; 00114 00115 TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n", 00116 device, declaration, shader_handle, decl_ptr); 00117 00118 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); 00119 if (!object) 00120 { 00121 ERR("Memory allocation failed.\n"); 00122 return E_OUTOFMEMORY; 00123 } 00124 00125 hr = vertexdeclaration_init(object, device, declaration, shader_handle); 00126 if (FAILED(hr)) 00127 { 00128 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr); 00129 HeapFree(GetProcessHeap(), 0, object); 00130 return hr; 00131 } 00132 00133 TRACE("Created vertex declaration %p.\n", object); 00134 *decl_ptr = (IDirect3DVertexDeclaration8 *)object; 00135 00136 return D3D_OK; 00137 } 00138 00139 HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device, 00140 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage) 00141 { 00142 const DWORD *token = declaration; 00143 HRESULT hr; 00144 00145 /* Test if the vertex declaration is valid. */ 00146 while (D3DVSD_END() != *token) 00147 { 00148 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT); 00149 00150 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) 00151 { 00152 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT); 00153 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT); 00154 00155 if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code) 00156 { 00157 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n"); 00158 return D3DERR_INVALIDCALL; 00159 } 00160 } 00161 token += parse_token(token); 00162 } 00163 00164 shader->ref = 1; 00165 shader->IDirect3DVertexShader8_iface.lpVtbl = &d3d8_vertexshader_vtbl; 00166 00167 hr = d3d8_vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration); 00168 if (FAILED(hr)) 00169 { 00170 WARN("Failed to create vertex declaration, hr %#x.\n", hr); 00171 return hr; 00172 } 00173 00174 if (byte_code) 00175 { 00176 if (usage) FIXME("Usage %#x not implemented.\n", usage); 00177 00178 wined3d_mutex_lock(); 00179 hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL /* output signature */, 00180 shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 1); 00181 wined3d_mutex_unlock(); 00182 if (FAILED(hr)) 00183 { 00184 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr); 00185 IDirect3DVertexDeclaration8_Release(shader->vertex_declaration); 00186 return hr; 00187 } 00188 00189 load_local_constants(declaration, shader->wined3d_shader); 00190 } 00191 00192 return D3D_OK; 00193 } 00194 00195 static inline IDirect3DPixelShader8Impl *impl_from_IDirect3DPixelShader8(IDirect3DPixelShader8 *iface) 00196 { 00197 return CONTAINING_RECORD(iface, IDirect3DPixelShader8Impl, IDirect3DPixelShader8_iface); 00198 } 00199 00200 static HRESULT WINAPI d3d8_pixelshader_QueryInterface(IDirect3DPixelShader8 *iface, REFIID riid, void **object) 00201 { 00202 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); 00203 00204 if (IsEqualGUID(riid, &IID_IDirect3DPixelShader8) 00205 || IsEqualGUID(riid, &IID_IUnknown)) 00206 { 00207 IUnknown_AddRef(iface); 00208 *object = iface; 00209 return S_OK; 00210 } 00211 00212 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); 00213 00214 *object = NULL; 00215 return E_NOINTERFACE; 00216 } 00217 00218 static ULONG WINAPI d3d8_pixelshader_AddRef(IDirect3DPixelShader8 *iface) 00219 { 00220 IDirect3DPixelShader8Impl *shader = impl_from_IDirect3DPixelShader8(iface); 00221 ULONG refcount = InterlockedIncrement(&shader->ref); 00222 00223 TRACE("%p increasing refcount to %u.\n", iface, refcount); 00224 00225 if (refcount == 1) 00226 { 00227 wined3d_mutex_lock(); 00228 wined3d_shader_incref(shader->wined3d_shader); 00229 wined3d_mutex_unlock(); 00230 } 00231 00232 return refcount; 00233 } 00234 00235 static ULONG WINAPI d3d8_pixelshader_Release(IDirect3DPixelShader8 *iface) 00236 { 00237 IDirect3DPixelShader8Impl *shader = impl_from_IDirect3DPixelShader8(iface); 00238 ULONG refcount = InterlockedDecrement(&shader->ref); 00239 00240 TRACE("%p decreasing refcount to %u.\n", iface, refcount); 00241 00242 if (!refcount) 00243 { 00244 wined3d_mutex_lock(); 00245 wined3d_shader_decref(shader->wined3d_shader); 00246 wined3d_mutex_unlock(); 00247 } 00248 00249 return refcount; 00250 } 00251 00252 static const IDirect3DPixelShader8Vtbl d3d8_pixelshader_vtbl = 00253 { 00254 /* IUnknown */ 00255 d3d8_pixelshader_QueryInterface, 00256 d3d8_pixelshader_AddRef, 00257 d3d8_pixelshader_Release, 00258 }; 00259 00260 static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent) 00261 { 00262 HeapFree(GetProcessHeap(), 0, parent); 00263 } 00264 00265 static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops = 00266 { 00267 d3d8_pixelshader_wined3d_object_destroyed, 00268 }; 00269 00270 HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device, 00271 const DWORD *byte_code, DWORD shader_handle) 00272 { 00273 HRESULT hr; 00274 00275 shader->ref = 1; 00276 shader->IDirect3DPixelShader8_iface.lpVtbl = &d3d8_pixelshader_vtbl; 00277 shader->handle = shader_handle; 00278 00279 wined3d_mutex_lock(); 00280 hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader, 00281 &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 1); 00282 wined3d_mutex_unlock(); 00283 if (FAILED(hr)) 00284 { 00285 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr); 00286 return hr; 00287 } 00288 00289 return D3D_OK; 00290 } Generated on Fri May 25 2012 04:19:53 for ReactOS by
1.7.6.1
|