2010-09-01 18:41:03 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Raphael Junqueira
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "d3d8_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
|
|
|
|
2012-01-24 21:47:47 +01:00
|
|
|
static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
2012-01-24 21:47:47 +01:00
|
|
|
struct d3d8_vertex_shader *shader = parent;
|
|
|
|
d3d8_vertex_declaration_destroy(shader->vertex_declaration);
|
|
|
|
HeapFree(GetProcessHeap(), 0, shader);
|
2010-09-01 18:41:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 21:47:47 +01:00
|
|
|
void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader)
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
2012-01-24 21:47:47 +01:00
|
|
|
TRACE("shader %p.\n", shader);
|
2010-09-01 18:41:03 +02:00
|
|
|
|
2012-01-24 21:47:47 +01:00
|
|
|
if (shader->wined3d_shader)
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
|
|
|
wined3d_mutex_lock();
|
2012-01-24 21:47:47 +01:00
|
|
|
wined3d_shader_decref(shader->wined3d_shader);
|
2010-09-01 18:41:03 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
2012-01-24 21:47:47 +01:00
|
|
|
else
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
2012-01-24 21:47:47 +01:00
|
|
|
d3d8_vertexshader_wined3d_object_destroyed(shader);
|
2010-09-01 18:41:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
d3d8_vertexshader_wined3d_object_destroyed,
|
|
|
|
};
|
|
|
|
|
2012-05-21 20:48:36 +02:00
|
|
|
static HRESULT d3d8_vertexshader_create_vertexdeclaration(struct d3d8_device *device,
|
2012-01-24 21:47:46 +01:00
|
|
|
const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
2012-01-24 21:47:46 +01:00
|
|
|
struct d3d8_vertex_declaration *object;
|
2010-09-01 18:41:03 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
|
|
|
|
device, declaration, shader_handle, decl_ptr);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-01-24 21:47:46 +01:00
|
|
|
hr = d3d8_vertex_declaration_init(object, device, declaration, shader_handle);
|
2010-09-01 18:41:03 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created vertex declaration %p.\n", object);
|
2012-01-24 21:47:46 +01:00
|
|
|
*decl_ptr = object;
|
2010-09-01 18:41:03 +02:00
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-21 20:48:36 +02:00
|
|
|
HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_device *device,
|
2010-09-01 18:41:03 +02:00
|
|
|
const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
|
|
|
|
{
|
|
|
|
const DWORD *token = declaration;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* Test if the vertex declaration is valid. */
|
|
|
|
while (D3DVSD_END() != *token)
|
|
|
|
{
|
|
|
|
D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
|
|
|
|
|
|
|
|
if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
|
|
|
|
{
|
|
|
|
DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
|
|
|
DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
|
|
|
|
|
|
|
if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
|
|
|
|
{
|
|
|
|
WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
token += parse_token(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = d3d8_vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create vertex declaration, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (byte_code)
|
|
|
|
{
|
|
|
|
if (usage) FIXME("Usage %#x not implemented.\n", usage);
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL /* output signature */,
|
2011-09-23 17:03:19 +02:00
|
|
|
shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
|
2010-09-01 18:41:03 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
|
2012-01-24 21:47:46 +01:00
|
|
|
d3d8_vertex_declaration_destroy(shader->vertex_declaration);
|
2010-09-01 18:41:03 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:47 +02:00
|
|
|
load_local_constants(declaration, shader->wined3d_shader);
|
2010-09-01 18:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-24 21:47:48 +01:00
|
|
|
static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
2012-01-24 21:47:48 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, parent);
|
2010-09-01 18:41:03 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 21:47:48 +01:00
|
|
|
void d3d8_pixel_shader_destroy(struct d3d8_pixel_shader *shader)
|
2010-09-01 18:41:03 +02:00
|
|
|
{
|
2012-01-24 21:47:48 +01:00
|
|
|
TRACE("shader %p.\n", shader);
|
2010-09-01 18:41:03 +02:00
|
|
|
|
2012-01-24 21:47:48 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_shader_decref(shader->wined3d_shader);
|
|
|
|
wined3d_mutex_unlock();
|
2010-09-01 18:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
d3d8_pixelshader_wined3d_object_destroyed,
|
|
|
|
};
|
|
|
|
|
2012-05-21 20:48:36 +02:00
|
|
|
HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_device *device,
|
2010-09-01 18:41:03 +02:00
|
|
|
const DWORD *byte_code, DWORD shader_handle)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
shader->handle = shader_handle;
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
|
2011-09-23 17:03:19 +02:00
|
|
|
&d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
|
2010-09-01 18:41:03 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|