1 | /*
|
---|
2 | * Copyright 2002-2003 Jason Edmeades
|
---|
3 | * Raphael Junqueira
|
---|
4 | *
|
---|
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.
|
---|
9 | *
|
---|
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.
|
---|
14 | *
|
---|
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
|
---|
18 | */
|
---|
19 |
|
---|
20 | /*
|
---|
21 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
22 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
23 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
24 | * a choice of LGPL license versions is made available with the language indicating
|
---|
25 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
26 | * of the LGPL is applied is otherwise unspecified.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "config.h"
|
---|
30 | #include "d3d8_private.h"
|
---|
31 |
|
---|
32 | WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
---|
33 |
|
---|
34 | static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
|
---|
35 | {
|
---|
36 | struct d3d8_vertex_shader *shader = parent;
|
---|
37 | d3d8_vertex_declaration_destroy(shader->vertex_declaration);
|
---|
38 | HeapFree(GetProcessHeap(), 0, shader);
|
---|
39 | }
|
---|
40 |
|
---|
41 | void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader)
|
---|
42 | {
|
---|
43 | TRACE("shader %p.\n", shader);
|
---|
44 |
|
---|
45 | if (shader->wined3d_shader)
|
---|
46 | {
|
---|
47 | wined3d_mutex_lock();
|
---|
48 | wined3d_shader_decref(shader->wined3d_shader);
|
---|
49 | wined3d_mutex_unlock();
|
---|
50 | }
|
---|
51 | else
|
---|
52 | {
|
---|
53 | d3d8_vertexshader_wined3d_object_destroyed(shader);
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
|
---|
58 | {
|
---|
59 | d3d8_vertexshader_wined3d_object_destroyed,
|
---|
60 | };
|
---|
61 |
|
---|
62 | static HRESULT d3d8_vertexshader_create_vertexdeclaration(struct d3d8_device *device,
|
---|
63 | const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
|
---|
64 | {
|
---|
65 | struct d3d8_vertex_declaration *object;
|
---|
66 | HRESULT hr;
|
---|
67 |
|
---|
68 | TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
|
---|
69 | device, declaration, shader_handle, decl_ptr);
|
---|
70 |
|
---|
71 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
72 | if (!object)
|
---|
73 | return E_OUTOFMEMORY;
|
---|
74 |
|
---|
75 | hr = d3d8_vertex_declaration_init(object, device, declaration, shader_handle);
|
---|
76 | if (FAILED(hr))
|
---|
77 | {
|
---|
78 | WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
|
---|
79 | HeapFree(GetProcessHeap(), 0, object);
|
---|
80 | return hr;
|
---|
81 | }
|
---|
82 |
|
---|
83 | TRACE("Created vertex declaration %p.\n", object);
|
---|
84 | *decl_ptr = object;
|
---|
85 |
|
---|
86 | return D3D_OK;
|
---|
87 | }
|
---|
88 |
|
---|
89 | HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_device *device,
|
---|
90 | const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
|
---|
91 | {
|
---|
92 | const DWORD *token = declaration;
|
---|
93 | HRESULT hr;
|
---|
94 |
|
---|
95 | /* Test if the vertex declaration is valid. */
|
---|
96 | while (D3DVSD_END() != *token)
|
---|
97 | {
|
---|
98 | D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
|
---|
99 |
|
---|
100 | if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
|
---|
101 | {
|
---|
102 | DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
103 | DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
104 |
|
---|
105 | if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
|
---|
106 | {
|
---|
107 | WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
|
---|
108 | return D3DERR_INVALIDCALL;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | token += parse_token(token);
|
---|
112 | }
|
---|
113 |
|
---|
114 | hr = d3d8_vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
|
---|
115 | if (FAILED(hr))
|
---|
116 | {
|
---|
117 | WARN("Failed to create vertex declaration, hr %#x.\n", hr);
|
---|
118 | return hr;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (byte_code)
|
---|
122 | {
|
---|
123 | if (usage) FIXME("Usage %#x not implemented.\n", usage);
|
---|
124 |
|
---|
125 | wined3d_mutex_lock();
|
---|
126 | hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL /* output signature */,
|
---|
127 | shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
|
---|
128 | wined3d_mutex_unlock();
|
---|
129 | if (FAILED(hr))
|
---|
130 | {
|
---|
131 | WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
|
---|
132 | d3d8_vertex_declaration_destroy(shader->vertex_declaration);
|
---|
133 | return hr;
|
---|
134 | }
|
---|
135 |
|
---|
136 | load_local_constants(declaration, shader->wined3d_shader);
|
---|
137 | }
|
---|
138 |
|
---|
139 | return D3D_OK;
|
---|
140 | }
|
---|
141 |
|
---|
142 | static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
|
---|
143 | {
|
---|
144 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
145 | }
|
---|
146 |
|
---|
147 | void d3d8_pixel_shader_destroy(struct d3d8_pixel_shader *shader)
|
---|
148 | {
|
---|
149 | TRACE("shader %p.\n", shader);
|
---|
150 |
|
---|
151 | wined3d_mutex_lock();
|
---|
152 | wined3d_shader_decref(shader->wined3d_shader);
|
---|
153 | wined3d_mutex_unlock();
|
---|
154 | }
|
---|
155 |
|
---|
156 | static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops =
|
---|
157 | {
|
---|
158 | d3d8_pixelshader_wined3d_object_destroyed,
|
---|
159 | };
|
---|
160 |
|
---|
161 | HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_device *device,
|
---|
162 | const DWORD *byte_code, DWORD shader_handle)
|
---|
163 | {
|
---|
164 | HRESULT hr;
|
---|
165 |
|
---|
166 | shader->handle = shader_handle;
|
---|
167 |
|
---|
168 | wined3d_mutex_lock();
|
---|
169 | hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
|
---|
170 | &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
|
---|
171 | wined3d_mutex_unlock();
|
---|
172 | if (FAILED(hr))
|
---|
173 | {
|
---|
174 | WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
|
---|
175 | return hr;
|
---|
176 | }
|
---|
177 |
|
---|
178 | return D3D_OK;
|
---|
179 | }
|
---|