diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp | 444 |
1 files changed, 222 insertions, 222 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp index 8220a7e..aeb5300 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CD3D9CgMaterialRenderer.cpp | |||
@@ -1,222 +1,222 @@ | |||
1 | // Copyright (C) 2012-2012 Patryk Nadrowski | 1 | // Copyright (C) 2012-2012 Patryk Nadrowski |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #include "IrrCompileConfig.h" | 5 | #include "IrrCompileConfig.h" |
6 | #if defined(_IRR_COMPILE_WITH_DIRECT3D_9_) && defined(_IRR_COMPILE_WITH_CG_) | 6 | #if defined(_IRR_COMPILE_WITH_DIRECT3D_9_) && defined(_IRR_COMPILE_WITH_CG_) |
7 | 7 | ||
8 | #include "CD3D9CgMaterialRenderer.h" | 8 | #include "CD3D9CgMaterialRenderer.h" |
9 | #include "CD3D9Driver.h" | 9 | #include "CD3D9Driver.h" |
10 | #include "CD3D9Texture.h" | 10 | #include "CD3D9Texture.h" |
11 | 11 | ||
12 | namespace irr | 12 | namespace irr |
13 | { | 13 | { |
14 | namespace video | 14 | namespace video |
15 | { | 15 | { |
16 | 16 | ||
17 | CD3D9CgUniformSampler2D::CD3D9CgUniformSampler2D(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) | 17 | CD3D9CgUniformSampler2D::CD3D9CgUniformSampler2D(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) |
18 | { | 18 | { |
19 | Type = CG_SAMPLER2D; | 19 | Type = CG_SAMPLER2D; |
20 | } | 20 | } |
21 | 21 | ||
22 | void CD3D9CgUniformSampler2D::update(const void* data, const SMaterial& material) const | 22 | void CD3D9CgUniformSampler2D::update(const void* data, const SMaterial& material) const |
23 | { | 23 | { |
24 | s32* Data = (s32*)data; | 24 | s32* Data = (s32*)data; |
25 | s32 LayerID = *Data; | 25 | s32 LayerID = *Data; |
26 | 26 | ||
27 | if (material.TextureLayer[LayerID].Texture) | 27 | if (material.TextureLayer[LayerID].Texture) |
28 | { | 28 | { |
29 | IDirect3DBaseTexture9* Texture = reinterpret_cast<irr::video::CD3D9Texture*>(material.TextureLayer[LayerID].Texture)->getDX9Texture(); | 29 | IDirect3DBaseTexture9* Texture = reinterpret_cast<irr::video::CD3D9Texture*>(material.TextureLayer[LayerID].Texture)->getDX9Texture(); |
30 | 30 | ||
31 | cgD3D9SetTextureParameter(Parameter, Texture); | 31 | cgD3D9SetTextureParameter(Parameter, Texture); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | CD3D9CgMaterialRenderer::CD3D9CgMaterialRenderer(CD3D9Driver* driver, s32& materialType, | 35 | CD3D9CgMaterialRenderer::CD3D9CgMaterialRenderer(CD3D9Driver* driver, s32& materialType, |
36 | const c8* vertexProgram, const c8* vertexEntry, E_VERTEX_SHADER_TYPE vertexProfile, | 36 | const c8* vertexProgram, const c8* vertexEntry, E_VERTEX_SHADER_TYPE vertexProfile, |
37 | const c8* fragmentProgram, const c8* fragmentEntry, E_PIXEL_SHADER_TYPE fragmentProfile, | 37 | const c8* fragmentProgram, const c8* fragmentEntry, E_PIXEL_SHADER_TYPE fragmentProfile, |
38 | const c8* geometryProgram, const c8* geometryEntry, E_GEOMETRY_SHADER_TYPE geometryProfile, | 38 | const c8* geometryProgram, const c8* geometryEntry, E_GEOMETRY_SHADER_TYPE geometryProfile, |
39 | scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, u32 vertices, | 39 | scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, u32 vertices, |
40 | IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData) : | 40 | IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData) : |
41 | Driver(driver), CCgMaterialRenderer(callback, baseMaterial, userData) | 41 | Driver(driver), CCgMaterialRenderer(callback, baseMaterial, userData) |
42 | { | 42 | { |
43 | #ifdef _DEBUG | 43 | #ifdef _DEBUG |
44 | setDebugName("CD3D9CgMaterialRenderer"); | 44 | setDebugName("CD3D9CgMaterialRenderer"); |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | init(materialType, vertexProgram, vertexEntry, vertexProfile, fragmentProgram, fragmentEntry, fragmentProfile, | 47 | init(materialType, vertexProgram, vertexEntry, vertexProfile, fragmentProgram, fragmentEntry, fragmentProfile, |
48 | geometryProgram, geometryEntry, geometryProfile, inType, outType, vertices); | 48 | geometryProgram, geometryEntry, geometryProfile, inType, outType, vertices); |
49 | } | 49 | } |
50 | 50 | ||
51 | CD3D9CgMaterialRenderer::~CD3D9CgMaterialRenderer() | 51 | CD3D9CgMaterialRenderer::~CD3D9CgMaterialRenderer() |
52 | { | 52 | { |
53 | if (VertexProgram) | 53 | if (VertexProgram) |
54 | { | 54 | { |
55 | cgD3D9UnloadProgram(VertexProgram); | 55 | cgD3D9UnloadProgram(VertexProgram); |
56 | cgDestroyProgram(VertexProgram); | 56 | cgDestroyProgram(VertexProgram); |
57 | } | 57 | } |
58 | if (FragmentProgram) | 58 | if (FragmentProgram) |
59 | { | 59 | { |
60 | cgD3D9UnloadProgram(FragmentProgram); | 60 | cgD3D9UnloadProgram(FragmentProgram); |
61 | cgDestroyProgram(FragmentProgram); | 61 | cgDestroyProgram(FragmentProgram); |
62 | } | 62 | } |
63 | /*if (GeometryProgram) | 63 | /*if (GeometryProgram) |
64 | { | 64 | { |
65 | cgD3D9UnloadProgram(GeometryProgram); | 65 | cgD3D9UnloadProgram(GeometryProgram); |
66 | cgDestroyProgram(GeometryProgram); | 66 | cgDestroyProgram(GeometryProgram); |
67 | }*/ | 67 | }*/ |
68 | } | 68 | } |
69 | 69 | ||
70 | void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) | 70 | void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) |
71 | { | 71 | { |
72 | Material = material; | 72 | Material = material; |
73 | 73 | ||
74 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 74 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
75 | { | 75 | { |
76 | if (VertexProgram) | 76 | if (VertexProgram) |
77 | cgD3D9BindProgram(VertexProgram); | 77 | cgD3D9BindProgram(VertexProgram); |
78 | 78 | ||
79 | if (FragmentProgram) | 79 | if (FragmentProgram) |
80 | cgD3D9BindProgram(FragmentProgram); | 80 | cgD3D9BindProgram(FragmentProgram); |
81 | 81 | ||
82 | /*if (GeometryProgram) | 82 | /*if (GeometryProgram) |
83 | cgD3D9BindProgram(GeometryProgram);*/ | 83 | cgD3D9BindProgram(GeometryProgram);*/ |
84 | 84 | ||
85 | if (BaseMaterial) | 85 | if (BaseMaterial) |
86 | BaseMaterial->OnSetMaterial(material, material, true, this); | 86 | BaseMaterial->OnSetMaterial(material, material, true, this); |
87 | } | 87 | } |
88 | 88 | ||
89 | if (CallBack) | 89 | if (CallBack) |
90 | CallBack->OnSetMaterial(material); | 90 | CallBack->OnSetMaterial(material); |
91 | 91 | ||
92 | Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 92 | Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
93 | } | 93 | } |
94 | 94 | ||
95 | bool CD3D9CgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) | 95 | bool CD3D9CgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) |
96 | { | 96 | { |
97 | if (CallBack && (VertexProgram || FragmentProgram || GeometryProgram)) | 97 | if (CallBack && (VertexProgram || FragmentProgram || GeometryProgram)) |
98 | CallBack->OnSetConstants(this, UserData); | 98 | CallBack->OnSetConstants(this, UserData); |
99 | 99 | ||
100 | return true; | 100 | return true; |
101 | } | 101 | } |
102 | 102 | ||
103 | void CD3D9CgMaterialRenderer::OnUnsetMaterial() | 103 | void CD3D9CgMaterialRenderer::OnUnsetMaterial() |
104 | { | 104 | { |
105 | if (VertexProgram) | 105 | if (VertexProgram) |
106 | cgD3D9UnbindProgram(VertexProgram); | 106 | cgD3D9UnbindProgram(VertexProgram); |
107 | if (FragmentProgram) | 107 | if (FragmentProgram) |
108 | cgD3D9UnbindProgram(FragmentProgram); | 108 | cgD3D9UnbindProgram(FragmentProgram); |
109 | /*if (GeometryProgram) | 109 | /*if (GeometryProgram) |
110 | cgD3D9UnbindProgram(GeometryProgram);*/ | 110 | cgD3D9UnbindProgram(GeometryProgram);*/ |
111 | 111 | ||
112 | if (BaseMaterial) | 112 | if (BaseMaterial) |
113 | BaseMaterial->OnUnsetMaterial(); | 113 | BaseMaterial->OnUnsetMaterial(); |
114 | 114 | ||
115 | Material = IdentityMaterial;; | 115 | Material = IdentityMaterial;; |
116 | } | 116 | } |
117 | 117 | ||
118 | void CD3D9CgMaterialRenderer::setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) | 118 | void CD3D9CgMaterialRenderer::setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) |
119 | { | 119 | { |
120 | Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 120 | Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
121 | } | 121 | } |
122 | 122 | ||
123 | IVideoDriver* CD3D9CgMaterialRenderer::getVideoDriver() | 123 | IVideoDriver* CD3D9CgMaterialRenderer::getVideoDriver() |
124 | { | 124 | { |
125 | return Driver; | 125 | return Driver; |
126 | } | 126 | } |
127 | 127 | ||
128 | void CD3D9CgMaterialRenderer::init(s32& materialType, | 128 | void CD3D9CgMaterialRenderer::init(s32& materialType, |
129 | const c8* vertexProgram, const c8* vertexEntry, E_VERTEX_SHADER_TYPE vertexProfile, | 129 | const c8* vertexProgram, const c8* vertexEntry, E_VERTEX_SHADER_TYPE vertexProfile, |
130 | const c8* fragmentProgram, const c8* fragmentEntry, E_PIXEL_SHADER_TYPE fragmentProfile, | 130 | const c8* fragmentProgram, const c8* fragmentEntry, E_PIXEL_SHADER_TYPE fragmentProfile, |
131 | const c8* geometryProgram, const c8* geometryEntry, E_GEOMETRY_SHADER_TYPE geometryProfile, | 131 | const c8* geometryProgram, const c8* geometryEntry, E_GEOMETRY_SHADER_TYPE geometryProfile, |
132 | scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, u32 vertices) | 132 | scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, u32 vertices) |
133 | { | 133 | { |
134 | bool Status = true; | 134 | bool Status = true; |
135 | CGerror Error = CG_NO_ERROR; | 135 | CGerror Error = CG_NO_ERROR; |
136 | materialType = -1; | 136 | materialType = -1; |
137 | 137 | ||
138 | // TODO: add profile selection | 138 | // TODO: add profile selection |
139 | 139 | ||
140 | if (vertexProgram) | 140 | if (vertexProgram) |
141 | { | 141 | { |
142 | VertexProfile = cgD3D9GetLatestVertexProfile(); | 142 | VertexProfile = cgD3D9GetLatestVertexProfile(); |
143 | 143 | ||
144 | if (VertexProfile) | 144 | if (VertexProfile) |
145 | VertexProgram = cgCreateProgram(Driver->getCgContext(), CG_SOURCE, vertexProgram, VertexProfile, vertexEntry, 0); | 145 | VertexProgram = cgCreateProgram(Driver->getCgContext(), CG_SOURCE, vertexProgram, VertexProfile, vertexEntry, 0); |
146 | 146 | ||
147 | if (!VertexProgram) | 147 | if (!VertexProgram) |
148 | { | 148 | { |
149 | Error = cgGetError(); | 149 | Error = cgGetError(); |
150 | os::Printer::log("Cg vertex program failed to compile:", ELL_ERROR); | 150 | os::Printer::log("Cg vertex program failed to compile:", ELL_ERROR); |
151 | os::Printer::log(cgGetLastListing(Driver->getCgContext()), ELL_ERROR); | 151 | os::Printer::log(cgGetLastListing(Driver->getCgContext()), ELL_ERROR); |
152 | 152 | ||
153 | Status = false; | 153 | Status = false; |
154 | } | 154 | } |
155 | else | 155 | else |
156 | cgD3D9LoadProgram(VertexProgram, 0, 0); | 156 | cgD3D9LoadProgram(VertexProgram, 0, 0); |
157 | } | 157 | } |
158 | 158 | ||
159 | if (fragmentProgram) | 159 | if (fragmentProgram) |
160 | { | 160 | { |
161 | FragmentProfile = cgD3D9GetLatestPixelProfile(); | 161 | FragmentProfile = cgD3D9GetLatestPixelProfile(); |
162 | 162 | ||
163 | if (FragmentProfile) | 163 | if (FragmentProfile) |
164 | FragmentProgram = cgCreateProgram(Driver->getCgContext(), CG_SOURCE, fragmentProgram, FragmentProfile, fragmentEntry, 0); | 164 | FragmentProgram = cgCreateProgram(Driver->getCgContext(), CG_SOURCE, fragmentProgram, FragmentProfile, fragmentEntry, 0); |
165 | 165 | ||
166 | if (!FragmentProgram) | 166 | if (!FragmentProgram) |
167 | { | 167 | { |
168 | Error = cgGetError(); | 168 | Error = cgGetError(); |
169 | os::Printer::log("Cg fragment program failed to compile:", ELL_ERROR); | 169 | os::Printer::log("Cg fragment program failed to compile:", ELL_ERROR); |
170 | os::Printer::log(cgGetLastListing(Driver->getCgContext()), ELL_ERROR); | 170 | os::Printer::log(cgGetLastListing(Driver->getCgContext()), ELL_ERROR); |
171 | 171 | ||
172 | Status = false; | 172 | Status = false; |
173 | } | 173 | } |
174 | else | 174 | else |
175 | cgD3D9LoadProgram(FragmentProgram, 0, 0); | 175 | cgD3D9LoadProgram(FragmentProgram, 0, 0); |
176 | } | 176 | } |
177 | 177 | ||
178 | /*if (geometryProgram) | 178 | /*if (geometryProgram) |
179 | { | 179 | { |
180 | GeometryProfile = cgD3D9GetLatestGeometryProfile(); | 180 | GeometryProfile = cgD3D9GetLatestGeometryProfile(); |
181 | 181 | ||
182 | if (GeometryProfile) | 182 | if (GeometryProfile) |
183 | GeometryProgram = cgCreateProgram(Driver->getCgContext(), CG_SOURCE, geometryProgram, GeometryProfile, geometryEntry, 0); | 183 | GeometryProgram = cgCreateProgram(Driver->getCgContext(), CG_SOURCE, geometryProgram, GeometryProfile, geometryEntry, 0); |
184 | 184 | ||
185 | if (!GeometryProgram) | 185 | if (!GeometryProgram) |
186 | { | 186 | { |
187 | Error = cgGetError(); | 187 | Error = cgGetError(); |
188 | os::Printer::log("Cg geometry program failed to compile:", ELL_ERROR); | 188 | os::Printer::log("Cg geometry program failed to compile:", ELL_ERROR); |
189 | os::Printer::log(cgGetLastListing(Driver->getCgContext()), ELL_ERROR); | 189 | os::Printer::log(cgGetLastListing(Driver->getCgContext()), ELL_ERROR); |
190 | 190 | ||
191 | Status = false; | 191 | Status = false; |
192 | } | 192 | } |
193 | else | 193 | else |
194 | cgD3D9LoadProgram(GeometryProgram, 0, 0); | 194 | cgD3D9LoadProgram(GeometryProgram, 0, 0); |
195 | }*/ | 195 | }*/ |
196 | 196 | ||
197 | getUniformList(); | 197 | getUniformList(); |
198 | 198 | ||
199 | // create D3D9 specifics sampler uniforms. | 199 | // create D3D9 specifics sampler uniforms. |
200 | for(unsigned int i = 0; i < UniformInfo.size(); ++i) | 200 | for(unsigned int i = 0; i < UniformInfo.size(); ++i) |
201 | { | 201 | { |
202 | if (UniformInfo[i]->getType() == CG_SAMPLER2D) | 202 | if (UniformInfo[i]->getType() == CG_SAMPLER2D) |
203 | { | 203 | { |
204 | bool IsGlobal = true; | 204 | bool IsGlobal = true; |
205 | 205 | ||
206 | if (UniformInfo[i]->getSpace() == CG_PROGRAM) | 206 | if (UniformInfo[i]->getSpace() == CG_PROGRAM) |
207 | IsGlobal = false; | 207 | IsGlobal = false; |
208 | 208 | ||
209 | CCgUniform* Uniform = new CD3D9CgUniformSampler2D(UniformInfo[i]->getParameter(), IsGlobal); | 209 | CCgUniform* Uniform = new CD3D9CgUniformSampler2D(UniformInfo[i]->getParameter(), IsGlobal); |
210 | delete UniformInfo[i]; | 210 | delete UniformInfo[i]; |
211 | UniformInfo[i] = Uniform; | 211 | UniformInfo[i] = Uniform; |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | if (Status) | 215 | if (Status) |
216 | materialType = Driver->addMaterialRenderer(this); | 216 | materialType = Driver->addMaterialRenderer(this); |
217 | } | 217 | } |
218 | 218 | ||
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | #endif | 222 | #endif |