msvcp90: Remove MSVCP_bool type.
[wine.git] / dlls / d3d8 / shader.c
blobd88f4b9a9ab5763f99c8c4710c3414d66f1d0265
1 /*
2 * Copyright 2002-2003 Jason Edmeades
3 * Raphael Junqueira
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.
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.
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
20 #include "d3d8_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
24 static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
26 struct d3d8_vertex_shader *shader = parent;
27 d3d8_vertex_declaration_destroy(shader->vertex_declaration);
28 heap_free(shader);
31 void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader)
33 TRACE("shader %p.\n", shader);
35 if (shader->wined3d_shader)
37 wined3d_mutex_lock();
38 wined3d_shader_decref(shader->wined3d_shader);
39 wined3d_mutex_unlock();
41 else
43 d3d8_vertexshader_wined3d_object_destroyed(shader);
47 static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
49 d3d8_vertexshader_wined3d_object_destroyed,
52 static HRESULT d3d8_vertexshader_create_vertexdeclaration(struct d3d8_device *device,
53 const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
55 struct d3d8_vertex_declaration *object;
56 HRESULT hr;
58 TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
59 device, declaration, shader_handle, decl_ptr);
61 if (!(object = heap_alloc_zero(sizeof(*object))))
62 return E_OUTOFMEMORY;
64 hr = d3d8_vertex_declaration_init(object, device, declaration, shader_handle);
65 if (FAILED(hr))
67 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
68 heap_free(object);
69 return hr;
72 TRACE("Created vertex declaration %p.\n", object);
73 *decl_ptr = object;
75 return D3D_OK;
78 HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_device *device,
79 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
81 const DWORD *token = declaration;
82 HRESULT hr;
84 /* Test if the vertex declaration is valid. */
85 while (D3DVSD_END() != *token)
87 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
89 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
91 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
92 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
94 if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
96 WARN("Attempt to use a non-FLOAT3 normal with the fixed-function function\n");
97 return D3DERR_INVALIDCALL;
100 token += parse_token(token);
103 hr = d3d8_vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
104 if (FAILED(hr))
106 WARN("Failed to create vertex declaration, hr %#x.\n", hr);
107 return hr;
110 if (byte_code)
112 struct wined3d_shader_desc desc;
114 if (usage)
115 FIXME("Usage %#x not implemented.\n", usage);
117 desc.byte_code = byte_code;
118 desc.byte_code_size = ~(size_t)0;
120 wined3d_mutex_lock();
121 hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader,
122 &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader);
123 wined3d_mutex_unlock();
124 if (FAILED(hr))
126 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
127 d3d8_vertex_declaration_destroy(shader->vertex_declaration);
128 return hr;
131 load_local_constants(declaration, shader->wined3d_shader);
134 return D3D_OK;
137 static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
139 heap_free(parent);
142 void d3d8_pixel_shader_destroy(struct d3d8_pixel_shader *shader)
144 TRACE("shader %p.\n", shader);
146 wined3d_mutex_lock();
147 wined3d_shader_decref(shader->wined3d_shader);
148 wined3d_mutex_unlock();
151 static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops =
153 d3d8_pixelshader_wined3d_object_destroyed,
156 HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_device *device,
157 const DWORD *byte_code, DWORD shader_handle)
159 struct wined3d_shader_desc desc;
160 HRESULT hr;
162 shader->handle = shader_handle;
164 desc.byte_code = byte_code;
165 desc.byte_code_size = ~(size_t)0;
167 wined3d_mutex_lock();
168 hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader,
169 &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader);
170 wined3d_mutex_unlock();
171 if (FAILED(hr))
173 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
174 return hr;
177 return D3D_OK;