ReactOS 0.4.17-dev-966-gf06eace
shader.c
Go to the documentation of this file.
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#include "d3d8_private.h"
21
23
25{
27 d3d8_vertex_declaration_destroy(shader->vertex_declaration);
28 free(shader);
29}
30
32{
33 TRACE("shader %p.\n", shader);
34
35 if (shader->wined3d_shader)
36 {
38 wined3d_shader_decref(shader->wined3d_shader);
40 }
41 else
42 {
44 }
45}
46
48{
50};
51
53 const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
54{
56 HRESULT hr;
57
58 TRACE("device %p, declaration %p, shader_handle %#lx, decl_ptr %p.\n",
59 device, declaration, shader_handle, decl_ptr);
60
61 if (!(object = calloc(1, sizeof(*object))))
62 return E_OUTOFMEMORY;
63
65 if (FAILED(hr))
66 {
67 WARN("Failed to initialize vertex declaration, hr %#lx.\n", hr);
68 free(object);
69 return hr;
70 }
71
72 TRACE("Created vertex declaration %p.\n", object);
73 *decl_ptr = object;
74
75 return D3D_OK;
76}
77
79 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
80{
81 const DWORD *token = declaration;
82 HRESULT hr;
83
84 /* Test if the vertex declaration is valid. */
85 while (D3DVSD_END() != *token)
86 {
88
89 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
90 {
93
94 if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
95 {
96 WARN("Attempt to use a non-FLOAT3 normal with the fixed-function function\n");
97 return D3DERR_INVALIDCALL;
98 }
99 }
101 }
102
104 if (FAILED(hr))
105 {
106 WARN("Failed to create vertex declaration, hr %#lx.\n", hr);
107 return hr;
108 }
109
110 if (byte_code)
111 {
113
114 if (usage)
115 FIXME("Usage %#lx not implemented.\n", usage);
116
117 desc.byte_code = byte_code;
118 desc.byte_code_size = ~(size_t)0;
119
121 hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader,
124 if (FAILED(hr))
125 {
126 WARN("Failed to create wined3d vertex shader, hr %#lx.\n", hr);
127 d3d8_vertex_declaration_destroy(shader->vertex_declaration);
128 return hr;
129 }
130
131 load_local_constants(declaration, shader->wined3d_shader);
132 }
133
134 return D3D_OK;
135}
136
138{
139 free(parent);
140}
141
143{
144 TRACE("shader %p.\n", shader);
145
147 wined3d_shader_decref(shader->wined3d_shader);
149}
150
152{
154};
155
157 const DWORD *byte_code, DWORD shader_handle)
158{
160 HRESULT hr;
161
162 shader->handle = shader_handle;
163
164 desc.byte_code = byte_code;
165 desc.byte_code_size = ~(size_t)0;
166
168 hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader,
171 if (FAILED(hr))
172 {
173 WARN("Failed to create wined3d pixel shader, hr %#lx.\n", hr);
174 return hr;
175 }
176
177 return D3D_OK;
178}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define D3DERR_INVALIDCALL
Definition: d3d10_private.h:42
void d3d8_vertex_declaration_destroy(struct d3d8_vertex_declaration *declaration)
void load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader)
size_t parse_token(const DWORD *pToken)
HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration, struct d3d8_device *device, const DWORD *elements, DWORD shader_handle)
#define D3DVSD_VERTEXREGMASK
Definition: d3d8types.h:257
#define D3DVSD_END()
Definition: d3d8types.h:275
#define D3DVSD_DATATYPEMASK
Definition: d3d8types.h:259
@ D3DVSDE_NORMAL
Definition: d3d8types.h:201
#define D3DVSD_VERTEXREGSHIFT
Definition: d3d8types.h:243
#define D3DVSD_TOKENTYPEMASK
Definition: d3d8types.h:266
#define D3DVSD_DATATYPESHIFT
Definition: d3d8types.h:245
#define D3DVSD_TOKENTYPESHIFT
Definition: d3d8types.h:252
@ D3DVSD_TOKEN_STREAMDATA
Definition: d3d8types.h:167
enum _D3DVSD_TOKENTYPE D3DVSD_TOKENTYPE
@ D3DVSDT_FLOAT3
Definition: d3d8types.h:231
#define D3D_OK
Definition: d3d.h:106
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define free
Definition: debug_ros.c:5
HRESULT hr
Definition: delayimp.cpp:582
static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops
Definition: shader.c:151
HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_device *device, const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
Definition: shader.c:78
static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
Definition: shader.c:137
static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops
Definition: shader.c:47
void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader)
Definition: shader.c:31
static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
Definition: shader.c:24
HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_device *device, const DWORD *byte_code, DWORD shader_handle)
Definition: shader.c:156
void d3d8_pixel_shader_destroy(struct d3d8_pixel_shader *shader)
Definition: shader.c:142
static HRESULT d3d8_vertexshader_create_vertexdeclaration(struct d3d8_device *device, const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
Definition: shader.c:52
HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const struct wined3d_shader_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
Definition: shader.c:3318
HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const struct wined3d_shader_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
Definition: shader.c:3291
ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
Definition: shader.c:2588
unsigned int size_t
Definition: corecrt.h:203
r parent
Definition: btrfs.c:3010
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint shader
Definition: glext.h:6030
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
static int reg
Definition: i386-dis.c:1290
#define FAILED(hr)
Definition: intsafe.h:51
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
#define calloc
Definition: rosglue.h:14
#define TRACE(s)
Definition: solgame.cpp:4
Definition: devices.h:37
const DWORD * byte_code
Definition: wined3d.h:2105
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539