1 | /*
|
---|
2 | * shaders implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2003 Jason Edmeades
|
---|
5 | * Copyright 2002-2003 Raphael Junqueira
|
---|
6 | * Copyright 2004 Christian Costa
|
---|
7 | * Copyright 2005 Oliver Stieber
|
---|
8 | * Copyright 2006 Ivan Gyurdiev
|
---|
9 | * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
---|
10 | *
|
---|
11 | * This library is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU Lesser General Public
|
---|
13 | * License as published by the Free Software Foundation; either
|
---|
14 | * version 2.1 of the License, or (at your option) any later version.
|
---|
15 | *
|
---|
16 | * This library is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * Lesser General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU Lesser General Public
|
---|
22 | * License along with this library; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*
|
---|
27 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
28 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
29 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
30 | * a choice of LGPL license versions is made available with the language indicating
|
---|
31 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
32 | * of the LGPL is applied is otherwise unspecified.
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include "config.h"
|
---|
36 |
|
---|
37 | #include <math.h>
|
---|
38 | #include <stdio.h>
|
---|
39 |
|
---|
40 | #include "wined3d_private.h"
|
---|
41 |
|
---|
42 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
|
---|
43 |
|
---|
44 | #define GLINFO_LOCATION ((IWineD3DDeviceImpl *) This->baseShader.device)->adapter->gl_info
|
---|
45 |
|
---|
46 | static HRESULT WINAPI IWineD3DPixelShaderImpl_QueryInterface(IWineD3DPixelShader *iface, REFIID riid, LPVOID *ppobj) {
|
---|
47 | TRACE("iface %p, riid %s, ppobj %p\n", iface, debugstr_guid(riid), ppobj);
|
---|
48 |
|
---|
49 | if (IsEqualGUID(riid, &IID_IWineD3DPixelShader)
|
---|
50 | || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
|
---|
51 | || IsEqualGUID(riid, &IID_IWineD3DBase)
|
---|
52 | || IsEqualGUID(riid, &IID_IUnknown))
|
---|
53 | {
|
---|
54 | IUnknown_AddRef(iface);
|
---|
55 | *ppobj = iface;
|
---|
56 | return S_OK;
|
---|
57 | }
|
---|
58 |
|
---|
59 | WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
---|
60 |
|
---|
61 | *ppobj = NULL;
|
---|
62 | return E_NOINTERFACE;
|
---|
63 | }
|
---|
64 |
|
---|
65 | static ULONG WINAPI IWineD3DPixelShaderImpl_AddRef(IWineD3DPixelShader *iface) {
|
---|
66 | IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
---|
67 | ULONG refcount = InterlockedIncrement(&This->baseShader.ref);
|
---|
68 |
|
---|
69 | TRACE("%p increasing refcount to %u\n", This, refcount);
|
---|
70 |
|
---|
71 | return refcount;
|
---|
72 | }
|
---|
73 |
|
---|
74 | static ULONG WINAPI IWineD3DPixelShaderImpl_Release(IWineD3DPixelShader *iface) {
|
---|
75 | IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
---|
76 | ULONG refcount = InterlockedDecrement(&This->baseShader.ref);
|
---|
77 |
|
---|
78 | TRACE("%p decreasing refcount to %u\n", This, refcount);
|
---|
79 |
|
---|
80 | if (!refcount)
|
---|
81 | {
|
---|
82 | shader_cleanup((IWineD3DBaseShader *)iface);
|
---|
83 | HeapFree(GetProcessHeap(), 0, This);
|
---|
84 | }
|
---|
85 |
|
---|
86 | return refcount;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /* *******************************************
|
---|
90 | IWineD3DPixelShader IWineD3DPixelShader parts follow
|
---|
91 | ******************************************* */
|
---|
92 |
|
---|
93 | static HRESULT WINAPI IWineD3DPixelShaderImpl_GetParent(IWineD3DPixelShader *iface, IUnknown** parent){
|
---|
94 | IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
---|
95 |
|
---|
96 | *parent = This->parent;
|
---|
97 | IUnknown_AddRef(*parent);
|
---|
98 | TRACE("(%p) : returning %p\n", This, *parent);
|
---|
99 | return WINED3D_OK;
|
---|
100 | }
|
---|
101 |
|
---|
102 | static HRESULT WINAPI IWineD3DPixelShaderImpl_GetDevice(IWineD3DPixelShader* iface, IWineD3DDevice **pDevice){
|
---|
103 | IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
---|
104 | IWineD3DDevice_AddRef(This->baseShader.device);
|
---|
105 | *pDevice = This->baseShader.device;
|
---|
106 | TRACE("(%p) returning %p\n", This, *pDevice);
|
---|
107 | return WINED3D_OK;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | static HRESULT WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader* impl, VOID* pData, UINT* pSizeOfData) {
|
---|
112 | IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)impl;
|
---|
113 | TRACE("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
|
---|
114 |
|
---|
115 | if (NULL == pData) {
|
---|
116 | *pSizeOfData = This->baseShader.functionLength;
|
---|
117 | return WINED3D_OK;
|
---|
118 | }
|
---|
119 | if (*pSizeOfData < This->baseShader.functionLength) {
|
---|
120 | /* MSDN claims (for d3d8 at least) that if *pSizeOfData is smaller
|
---|
121 | * than the required size we should write the required size and
|
---|
122 | * return D3DERR_MOREDATA. That's not actually true. */
|
---|
123 | return WINED3DERR_INVALIDCALL;
|
---|
124 | }
|
---|
125 |
|
---|
126 | TRACE("(%p) : GetFunction copying to %p\n", This, pData);
|
---|
127 | memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
|
---|
128 |
|
---|
129 | return WINED3D_OK;
|
---|
130 | }
|
---|
131 |
|
---|
132 | static void pshader_set_limits(IWineD3DPixelShaderImpl *This)
|
---|
133 | {
|
---|
134 | DWORD shader_version = WINED3D_SHADER_VERSION(This->baseShader.reg_maps.shader_version.major,
|
---|
135 | This->baseShader.reg_maps.shader_version.minor);
|
---|
136 |
|
---|
137 | This->baseShader.limits.attributes = 0;
|
---|
138 | This->baseShader.limits.address = 0;
|
---|
139 | This->baseShader.limits.packed_output = 0;
|
---|
140 |
|
---|
141 | switch (shader_version)
|
---|
142 | {
|
---|
143 | case WINED3D_SHADER_VERSION(1,0):
|
---|
144 | case WINED3D_SHADER_VERSION(1,1):
|
---|
145 | case WINED3D_SHADER_VERSION(1,2):
|
---|
146 | case WINED3D_SHADER_VERSION(1,3):
|
---|
147 | This->baseShader.limits.temporary = 2;
|
---|
148 | This->baseShader.limits.constant_float = 8;
|
---|
149 | This->baseShader.limits.constant_int = 0;
|
---|
150 | This->baseShader.limits.constant_bool = 0;
|
---|
151 | This->baseShader.limits.texcoord = 4;
|
---|
152 | This->baseShader.limits.sampler = 4;
|
---|
153 | This->baseShader.limits.packed_input = 0;
|
---|
154 | This->baseShader.limits.label = 0;
|
---|
155 | break;
|
---|
156 |
|
---|
157 | case WINED3D_SHADER_VERSION(1,4):
|
---|
158 | This->baseShader.limits.temporary = 6;
|
---|
159 | This->baseShader.limits.constant_float = 8;
|
---|
160 | This->baseShader.limits.constant_int = 0;
|
---|
161 | This->baseShader.limits.constant_bool = 0;
|
---|
162 | This->baseShader.limits.texcoord = 6;
|
---|
163 | This->baseShader.limits.sampler = 6;
|
---|
164 | This->baseShader.limits.packed_input = 0;
|
---|
165 | This->baseShader.limits.label = 0;
|
---|
166 | break;
|
---|
167 |
|
---|
168 | /* FIXME: temporaries must match D3DPSHADERCAPS2_0.NumTemps */
|
---|
169 | case WINED3D_SHADER_VERSION(2,0):
|
---|
170 | This->baseShader.limits.temporary = 32;
|
---|
171 | This->baseShader.limits.constant_float = 32;
|
---|
172 | This->baseShader.limits.constant_int = 16;
|
---|
173 | This->baseShader.limits.constant_bool = 16;
|
---|
174 | This->baseShader.limits.texcoord = 8;
|
---|
175 | This->baseShader.limits.sampler = 16;
|
---|
176 | This->baseShader.limits.packed_input = 0;
|
---|
177 | break;
|
---|
178 |
|
---|
179 | case WINED3D_SHADER_VERSION(2,1):
|
---|
180 | This->baseShader.limits.temporary = 32;
|
---|
181 | This->baseShader.limits.constant_float = 32;
|
---|
182 | This->baseShader.limits.constant_int = 16;
|
---|
183 | This->baseShader.limits.constant_bool = 16;
|
---|
184 | This->baseShader.limits.texcoord = 8;
|
---|
185 | This->baseShader.limits.sampler = 16;
|
---|
186 | This->baseShader.limits.packed_input = 0;
|
---|
187 | This->baseShader.limits.label = 16;
|
---|
188 | break;
|
---|
189 |
|
---|
190 | case WINED3D_SHADER_VERSION(3,0):
|
---|
191 | This->baseShader.limits.temporary = 32;
|
---|
192 | This->baseShader.limits.constant_float = 224;
|
---|
193 | This->baseShader.limits.constant_int = 16;
|
---|
194 | This->baseShader.limits.constant_bool = 16;
|
---|
195 | This->baseShader.limits.texcoord = 0;
|
---|
196 | This->baseShader.limits.sampler = 16;
|
---|
197 | This->baseShader.limits.packed_input = 12;
|
---|
198 | This->baseShader.limits.label = 16; /* FIXME: 2048 */
|
---|
199 | break;
|
---|
200 |
|
---|
201 | default:
|
---|
202 | This->baseShader.limits.temporary = 32;
|
---|
203 | This->baseShader.limits.constant_float = 32;
|
---|
204 | This->baseShader.limits.constant_int = 16;
|
---|
205 | This->baseShader.limits.constant_bool = 16;
|
---|
206 | This->baseShader.limits.texcoord = 8;
|
---|
207 | This->baseShader.limits.sampler = 16;
|
---|
208 | This->baseShader.limits.packed_input = 0;
|
---|
209 | This->baseShader.limits.label = 0;
|
---|
210 | FIXME("Unrecognized pixel shader version %u.%u\n",
|
---|
211 | This->baseShader.reg_maps.shader_version.major,
|
---|
212 | This->baseShader.reg_maps.shader_version.minor);
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | static HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, CONST DWORD *pFunction) {
|
---|
217 |
|
---|
218 | IWineD3DPixelShaderImpl *This =(IWineD3DPixelShaderImpl *)iface;
|
---|
219 | unsigned int i, highest_reg_used = 0, num_regs_used = 0;
|
---|
220 | shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
|
---|
221 | const struct wined3d_shader_frontend *fe;
|
---|
222 | HRESULT hr;
|
---|
223 |
|
---|
224 | TRACE("(%p) : pFunction %p\n", iface, pFunction);
|
---|
225 |
|
---|
226 | fe = shader_select_frontend(*pFunction);
|
---|
227 | if (!fe)
|
---|
228 | {
|
---|
229 | FIXME("Unable to find frontend for shader.\n");
|
---|
230 | return WINED3DERR_INVALIDCALL;
|
---|
231 | }
|
---|
232 | This->baseShader.frontend = fe;
|
---|
233 | This->baseShader.frontend_data = fe->shader_init(pFunction);
|
---|
234 | if (!This->baseShader.frontend_data)
|
---|
235 | {
|
---|
236 | FIXME("Failed to initialize frontend.\n");
|
---|
237 | return WINED3DERR_INVALIDCALL;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /* First pass: trace shader */
|
---|
241 | if (TRACE_ON(d3d_shader)) shader_trace_init(fe, This->baseShader.frontend_data, pFunction);
|
---|
242 |
|
---|
243 | /* Initialize immediate constant lists */
|
---|
244 | list_init(&This->baseShader.constantsF);
|
---|
245 | list_init(&This->baseShader.constantsB);
|
---|
246 | list_init(&This->baseShader.constantsI);
|
---|
247 |
|
---|
248 | /* Second pass: figure out which registers are used, what the semantics are, etc.. */
|
---|
249 | hr = shader_get_registers_used((IWineD3DBaseShader *)This, fe, reg_maps, This->semantics_in, NULL, pFunction,
|
---|
250 | GL_LIMITS(pshader_constantsF));
|
---|
251 | if (FAILED(hr)) return hr;
|
---|
252 |
|
---|
253 | pshader_set_limits(This);
|
---|
254 |
|
---|
255 | for (i = 0; i < MAX_REG_INPUT; ++i)
|
---|
256 | {
|
---|
257 | if (This->input_reg_used[i])
|
---|
258 | {
|
---|
259 | ++num_regs_used;
|
---|
260 | highest_reg_used = i;
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | /* Don't do any register mapping magic if it is not needed, or if we can't
|
---|
265 | * achieve anything anyway */
|
---|
266 | if (highest_reg_used < (GL_LIMITS(glsl_varyings) / 4)
|
---|
267 | || num_regs_used > (GL_LIMITS(glsl_varyings) / 4))
|
---|
268 | {
|
---|
269 | if (num_regs_used > (GL_LIMITS(glsl_varyings) / 4))
|
---|
270 | {
|
---|
271 | /* This happens with relative addressing. The input mapper function
|
---|
272 | * warns about this if the higher registers are declared too, so
|
---|
273 | * don't write a FIXME here */
|
---|
274 | WARN("More varying registers used than supported\n");
|
---|
275 | }
|
---|
276 |
|
---|
277 | for (i = 0; i < MAX_REG_INPUT; ++i)
|
---|
278 | {
|
---|
279 | This->input_reg_map[i] = i;
|
---|
280 | }
|
---|
281 |
|
---|
282 | This->declared_in_count = highest_reg_used + 1;
|
---|
283 | }
|
---|
284 | else
|
---|
285 | {
|
---|
286 | This->declared_in_count = 0;
|
---|
287 | for (i = 0; i < MAX_REG_INPUT; ++i)
|
---|
288 | {
|
---|
289 | if (This->input_reg_used[i]) This->input_reg_map[i] = This->declared_in_count++;
|
---|
290 | else This->input_reg_map[i] = ~0U;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | This->baseShader.load_local_constsF = FALSE;
|
---|
295 |
|
---|
296 | TRACE("(%p) : Copying the function\n", This);
|
---|
297 |
|
---|
298 | This->baseShader.function = HeapAlloc(GetProcessHeap(), 0, This->baseShader.functionLength);
|
---|
299 | if (!This->baseShader.function) return E_OUTOFMEMORY;
|
---|
300 | memcpy(This->baseShader.function, pFunction, This->baseShader.functionLength);
|
---|
301 |
|
---|
302 | return WINED3D_OK;
|
---|
303 | }
|
---|
304 |
|
---|
305 | static void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures)
|
---|
306 | {
|
---|
307 | WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = reg_maps->sampler_type;
|
---|
308 | unsigned int i;
|
---|
309 |
|
---|
310 | if (reg_maps->shader_version.major != 1) return;
|
---|
311 |
|
---|
312 | for (i = 0; i < max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS); ++i)
|
---|
313 | {
|
---|
314 | /* We don't sample from this sampler */
|
---|
315 | if (!sampler_type[i]) continue;
|
---|
316 |
|
---|
317 | if (!textures[i])
|
---|
318 | {
|
---|
319 | ERR("No texture bound to sampler %u, using 2D\n", i);
|
---|
320 | sampler_type[i] = WINED3DSTT_2D;
|
---|
321 | continue;
|
---|
322 | }
|
---|
323 |
|
---|
324 | switch (IWineD3DBaseTexture_GetTextureDimensions(textures[i]))
|
---|
325 | {
|
---|
326 | case GL_TEXTURE_RECTANGLE_ARB:
|
---|
327 | case GL_TEXTURE_2D:
|
---|
328 | /* We have to select between texture rectangles and 2D textures later because 2.0 and
|
---|
329 | * 3.0 shaders only have WINED3DSTT_2D as well */
|
---|
330 | sampler_type[i] = WINED3DSTT_2D;
|
---|
331 | break;
|
---|
332 |
|
---|
333 | case GL_TEXTURE_3D:
|
---|
334 | sampler_type[i] = WINED3DSTT_VOLUME;
|
---|
335 | break;
|
---|
336 |
|
---|
337 | case GL_TEXTURE_CUBE_MAP_ARB:
|
---|
338 | sampler_type[i] = WINED3DSTT_CUBE;
|
---|
339 | break;
|
---|
340 |
|
---|
341 | default:
|
---|
342 | FIXME("Unrecognized texture type %#x, using 2D\n",
|
---|
343 | IWineD3DBaseTexture_GetTextureDimensions(textures[i]));
|
---|
344 | sampler_type[i] = WINED3DSTT_2D;
|
---|
345 | }
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 | static GLuint pixelshader_compile(IWineD3DPixelShaderImpl *This, const struct ps_compile_args *args)
|
---|
350 | {
|
---|
351 | CONST DWORD *function = This->baseShader.function;
|
---|
352 | GLuint retval;
|
---|
353 | SHADER_BUFFER buffer;
|
---|
354 | IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device;
|
---|
355 |
|
---|
356 | TRACE("(%p) : function %p\n", This, function);
|
---|
357 |
|
---|
358 | pixelshader_update_samplers(&This->baseShader.reg_maps,
|
---|
359 | ((IWineD3DDeviceImpl *)This->baseShader.device)->stateBlock->textures);
|
---|
360 |
|
---|
361 | /* Generate the HW shader */
|
---|
362 | TRACE("(%p) : Generating hardware program\n", This);
|
---|
363 | This->cur_args = args;
|
---|
364 | shader_buffer_init(&buffer);
|
---|
365 | retval = device->shader_backend->shader_generate_pshader((IWineD3DPixelShader *)This, &buffer, args);
|
---|
366 | shader_buffer_free(&buffer);
|
---|
367 | This->cur_args = NULL;
|
---|
368 |
|
---|
369 | return retval;
|
---|
370 | }
|
---|
371 |
|
---|
372 | const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
|
---|
373 | {
|
---|
374 | /*** IUnknown methods ***/
|
---|
375 | IWineD3DPixelShaderImpl_QueryInterface,
|
---|
376 | IWineD3DPixelShaderImpl_AddRef,
|
---|
377 | IWineD3DPixelShaderImpl_Release,
|
---|
378 | /*** IWineD3DBase methods ***/
|
---|
379 | IWineD3DPixelShaderImpl_GetParent,
|
---|
380 | /*** IWineD3DBaseShader methods ***/
|
---|
381 | IWineD3DPixelShaderImpl_SetFunction,
|
---|
382 | /*** IWineD3DPixelShader methods ***/
|
---|
383 | IWineD3DPixelShaderImpl_GetDevice,
|
---|
384 | IWineD3DPixelShaderImpl_GetFunction
|
---|
385 | };
|
---|
386 |
|
---|
387 | void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args) {
|
---|
388 | UINT i;
|
---|
389 | IWineD3DBaseTextureImpl *tex;
|
---|
390 |
|
---|
391 | memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set */
|
---|
392 | args->srgb_correction = stateblock->renderState[WINED3DRS_SRGBWRITEENABLE] ? 1 : 0;
|
---|
393 | args->np2_fixup = 0;
|
---|
394 |
|
---|
395 | for(i = 0; i < MAX_FRAGMENT_SAMPLERS; i++) {
|
---|
396 | if (!shader->baseShader.reg_maps.sampler_type[i]) continue;
|
---|
397 | tex = (IWineD3DBaseTextureImpl *) stateblock->textures[i];
|
---|
398 | if(!tex) {
|
---|
399 | args->color_fixup[i] = COLOR_FIXUP_IDENTITY;
|
---|
400 | continue;
|
---|
401 | }
|
---|
402 | args->color_fixup[i] = tex->resource.format_desc->color_fixup;
|
---|
403 |
|
---|
404 | /* Flag samplers that need NP2 texcoord fixup. */
|
---|
405 | if(!tex->baseTexture.pow2Matrix_identity) {
|
---|
406 | args->np2_fixup |= (1 << i);
|
---|
407 | }
|
---|
408 | }
|
---|
409 | if (shader->baseShader.reg_maps.shader_version.major >= 3)
|
---|
410 | {
|
---|
411 | if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed)
|
---|
412 | {
|
---|
413 | args->vp_mode = pretransformed;
|
---|
414 | }
|
---|
415 | else if (use_vs(stateblock))
|
---|
416 | {
|
---|
417 | args->vp_mode = vertexshader;
|
---|
418 | } else {
|
---|
419 | args->vp_mode = fixedfunction;
|
---|
420 | }
|
---|
421 | args->fog = FOG_OFF;
|
---|
422 | } else {
|
---|
423 | args->vp_mode = vertexshader;
|
---|
424 | if(stateblock->renderState[WINED3DRS_FOGENABLE]) {
|
---|
425 | switch(stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
|
---|
426 | case WINED3DFOG_NONE:
|
---|
427 | if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed
|
---|
428 | || use_vs(stateblock))
|
---|
429 | {
|
---|
430 | args->fog = FOG_LINEAR;
|
---|
431 | break;
|
---|
432 | }
|
---|
433 | switch(stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
|
---|
434 | case WINED3DFOG_NONE: /* Drop through */
|
---|
435 | case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
|
---|
436 | case WINED3DFOG_EXP: args->fog = FOG_EXP; break;
|
---|
437 | case WINED3DFOG_EXP2: args->fog = FOG_EXP2; break;
|
---|
438 | }
|
---|
439 | break;
|
---|
440 |
|
---|
441 | case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
|
---|
442 | case WINED3DFOG_EXP: args->fog = FOG_EXP; break;
|
---|
443 | case WINED3DFOG_EXP2: args->fog = FOG_EXP2; break;
|
---|
444 | }
|
---|
445 | } else {
|
---|
446 | args->fog = FOG_OFF;
|
---|
447 | }
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | GLuint find_gl_pshader(IWineD3DPixelShaderImpl *shader, const struct ps_compile_args *args)
|
---|
452 | {
|
---|
453 | UINT i;
|
---|
454 | DWORD new_size;
|
---|
455 | struct ps_compiled_shader *new_array;
|
---|
456 |
|
---|
457 | /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
|
---|
458 | * so a linear search is more performant than a hashmap or a binary search
|
---|
459 | * (cache coherency etc)
|
---|
460 | */
|
---|
461 | for(i = 0; i < shader->num_gl_shaders; i++) {
|
---|
462 | if(memcmp(&shader->gl_shaders[i].args, args, sizeof(*args)) == 0) {
|
---|
463 | return shader->gl_shaders[i].prgId;
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | TRACE("No matching GL shader found, compiling a new shader\n");
|
---|
468 | if(shader->shader_array_size == shader->num_gl_shaders) {
|
---|
469 | if (shader->num_gl_shaders)
|
---|
470 | {
|
---|
471 | new_size = shader->shader_array_size + max(1, shader->shader_array_size / 2);
|
---|
472 | new_array = HeapReAlloc(GetProcessHeap(), 0, shader->gl_shaders,
|
---|
473 | new_size * sizeof(*shader->gl_shaders));
|
---|
474 | } else {
|
---|
475 | new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*shader->gl_shaders));
|
---|
476 | new_size = 1;
|
---|
477 | }
|
---|
478 |
|
---|
479 | if(!new_array) {
|
---|
480 | ERR("Out of memory\n");
|
---|
481 | return 0;
|
---|
482 | }
|
---|
483 | shader->gl_shaders = new_array;
|
---|
484 | shader->shader_array_size = new_size;
|
---|
485 | }
|
---|
486 |
|
---|
487 | shader->gl_shaders[shader->num_gl_shaders].args = *args;
|
---|
488 | shader->gl_shaders[shader->num_gl_shaders].prgId = pixelshader_compile(shader, args);
|
---|
489 | return shader->gl_shaders[shader->num_gl_shaders++].prgId;
|
---|
490 | }
|
---|