ReactOS 0.4.15-dev-7906-g1b85a5f
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 "config.h"
21#include "d3d8_private.h"
22
24
26{
28 d3d8_vertex_declaration_destroy(shader->vertex_declaration);
30}
31
33{
34 TRACE("shader %p.\n", shader);
35
36 if (shader->wined3d_shader)
37 {
39 wined3d_shader_decref(shader->wined3d_shader);
41 }
42 else
43 {
45 }
46}
47
49{
51};
52
54 const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
55{
57 HRESULT hr;
58
59 TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
60 device, declaration, shader_handle, decl_ptr);
61
62 if (!(object = heap_alloc_zero(sizeof(*object))))
63 return E_OUTOFMEMORY;
64
66 if (FAILED(hr))
67 {
68 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
69 heap_free(object);
70 return hr;
71 }
72
73 TRACE("Created vertex declaration %p.\n", object);
74 *decl_ptr = object;
75
76 return D3D_OK;
77}
78
80 const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
81{
82 const DWORD *token = declaration;
83 HRESULT hr;
84
85 /* Test if the vertex declaration is valid. */
86 while (D3DVSD_END() != *token)
87 {
89
90 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
91 {
94
95 if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
96 {
97 WARN("Attempt to use a non-FLOAT3 normal with the fixed-function function\n");
98 return D3DERR_INVALIDCALL;
99 }
100 }
102 }
103
105 if (FAILED(hr))
106 {
107 WARN("Failed to create vertex declaration, hr %#x.\n", hr);
108 return hr;
109 }
110
111 if (byte_code)
112 {
114
115 if (usage)
116 FIXME("Usage %#x not implemented.\n", usage);
117
118 desc.byte_code = byte_code;
119 desc.byte_code_size = ~(size_t)0;
121 desc.input_signature.element_count = 0;
122 desc.output_signature.element_count = 0;
123 desc.patch_constant_signature.element_count = 0;
124 desc.max_version = 1;
125
127 hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader,
130 if (FAILED(hr))
131 {
132 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
133 d3d8_vertex_declaration_destroy(shader->vertex_declaration);
134 return hr;
135 }
136
137 load_local_constants(declaration, shader->wined3d_shader);
138 }
139
140 return D3D_OK;
141}
142
144{
146}
147
149{
150 TRACE("shader %p.\n", shader);
151
153 wined3d_shader_decref(shader->wined3d_shader);
155}
156
158{
160};
161
163 const DWORD *byte_code, DWORD shader_handle)
164{
166 HRESULT hr;
167
168 shader->handle = shader_handle;
169
170 desc.byte_code = byte_code;
171 desc.byte_code_size = ~(size_t)0;
173 desc.input_signature.element_count = 0;
174 desc.output_signature.element_count = 0;
175 desc.patch_constant_signature.element_count = 0;
176 desc.max_version = 1;
177
179 hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader,
182 if (FAILED(hr))
183 {
184 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
185 return hr;
186 }
187
188 return D3D_OK;
189}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define FIXME(fmt,...)
Definition: debug.h:111
#define WARN(fmt,...)
Definition: debug.h:112
size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN
void load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader) DECLSPEC_HIDDEN
HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration, struct d3d8_device *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN
void d3d8_vertex_declaration_destroy(struct d3d8_vertex_declaration *declaration) DECLSPEC_HIDDEN
#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 D3DERR_INVALIDCALL
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops
Definition: shader.c:157
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:79
static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
Definition: shader.c:143
static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops
Definition: shader.c:48
void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader)
Definition: shader.c:32
static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
Definition: shader.c:25
HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_device *device, const DWORD *byte_code, DWORD shader_handle)
Definition: shader.c:162
void d3d8_pixel_shader_destroy(struct d3d8_pixel_shader *shader)
Definition: shader.c:148
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:53
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:4230
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:4205
ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
Definition: shader.c:3364
r parent
Definition: btrfs.c:3010
__kernel_size_t size_t
Definition: linux.h:237
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
static const WCHAR desc[]
Definition: protectdata.c:36
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: devices.h:37
const DWORD * byte_code
Definition: wined3d.h:2051
@ WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
Definition: wined3d.h:848
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:373
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:368