1 // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #include "IrrCompileConfig.h"
6 #include "IBurningShader.h"
7 
8 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
9 
10 
11 namespace irr
12 {
13 
14 namespace video
15 {
16 
17 	/*! Render states define set-up states for all kinds of vertex and pixel processing.
18 		Some render states set up vertex processing, and some set up pixel processing (see Render States).
19 		Render states can be saved and restored using stateblocks (see State Blocks Save and Restore State).
20 	*/
21 	enum BD3DRENDERSTATETYPE
22 	{
23 		/*!	BD3DRS_ZENABLE
24 			Depth-buffering state as one member of the BD3DZBUFFERTYPE enumerated type.
25 			Set this state to D3DZB_TRUE to enable z-buffering,
26 			D3DZB_USEW to enable w-buffering, or D3DZB_FALSE to disable depth buffering.
27 			The default value for this render state is D3DZB_TRUE if a depth stencil was created
28 			along with the swap chain by setting the EnableAutoDepthStencil member of the
29 			D3DPRESENT_PARAMETERS structure to TRUE, and D3DZB_FALSE otherwise.
30 		*/
31 		BD3DRS_ZENABLE,
32 
33 		/*!	BD3DRS_FILLMODE
34 			One or more members of the D3DFILLMODE enumerated type. The default value is D3DFILL_SOLID.
35 		*/
36 		BD3DRS_FILLMODE,
37 
38 		/*!	BD3DRS_SHADEMODE
39 			One or more members of the D3DSHADEMODE enumerated type. The default value is D3DSHADE_GOURAUD.
40 		*/
41 		BD3DRS_SHADEMODE,
42 
43 		/*!	BD3DRS_ZWRITEENABLE
44 			TRUE to enable the application to write to the depth buffer. The default value is TRUE.
45 			This member enables an application to prevent the system from updating the depth buffer with
46 			new depth values. If FALSE, depth comparisons are still made according to the render state
47 			D3DRS_ZFUNC, assuming that depth buffering is taking place, but depth values are not written
48 			to the buffer.
49 		*/
50 		BD3DRS_ZWRITEENABLE,
51 
52 		/*!	BD3DRS_ALPHATESTENABLE
53 			TRUE to enable per pixel alpha testing. If the test passes, the pixel is processed by the frame
54 			buffer. Otherwise, all frame-buffer processing is skipped for the pixel. The test is done by
55 			comparing the incoming alpha value with the reference alpha value, using the comparison function
56 			provided by the D3DRS_ALPHAFUNC render state. The reference alpha value is determined by the value
57 			set for D3DRS_ALPHAREF. For more information, see Alpha Testing State.
58 			The default value of this parameter is FALSE.
59 		*/
60 		BD3DRS_ALPHATESTENABLE,
61 
62 		/*!	BD3DRS_SRCBLEND
63 			One member of the BD3DBLEND enumerated type. The default value is BD3DBLEND_ONE.
64 		*/
65 		BD3DRS_SRCBLEND,
66 
67 		/*!	BD3DRS_DESTBLEND
68 			One member of the BD3DBLEND enumerated type. The default value is BD3DBLEND_ZERO.
69 		*/
70 		BD3DRS_DESTBLEND,
71 
72 		/*!	BD3DRS_CULLMODE
73 			Specifies how back-facing triangles are culled, if at all. This can be set to one
74 			member of the BD3DCULL enumerated type. The default value is BD3DCULL_CCW.
75 		*/
76 		BD3DRS_CULLMODE,
77 
78 		/*!	BD3DRS_ZFUNC
79 			One member of the BD3DCMPFUNC enumerated type. The default value is BD3DCMP_LESSEQUAL.
80 			This member enables an application to accept or reject a pixel, based on its distance from
81 			the camera. The depth value of the pixel is compared with the depth-buffer value. If the depth
82 			value of the pixel passes the comparison function, the pixel is written.
83 
84 			The depth value is written to the depth buffer only if the render state is TRUE.
85 			Software rasterizers and many hardware accelerators work faster if the depth test fails,
86 			because there is no need to filter and modulate the texture if the pixel is not going to be
87 			rendered.
88 		*/
89 		BD3DRS_ZFUNC,
90 
91 		/*!	BD3DRS_ALPHAREF
92 			Value that specifies a reference alpha value against which pixels are tested when alpha testing
93 			is enabled. This is an 8-bit value placed in the low 8 bits of the DWORD render-state value.
94 			Values can range from 0x00000000 through 0x000000FF. The default value is 0.
95 		*/
96 		BD3DRS_ALPHAREF,
97 
98 		/*!	BD3DRS_ALPHAFUNC
99 			One member of the BD3DCMPFUNC enumerated type. The default value is BD3DCMP_ALWAYS.
100 			This member enables an application to accept or reject a pixel, based on its alpha value.
101 		*/
102 		BD3DRS_ALPHAFUNC,
103 
104 		/*!	BD3DRS_DITHERENABLE
105 			TRUE to enable dithering. The default value is FALSE.
106 		*/
107 		BD3DRS_DITHERENABLE,
108 
109 		/*!	BD3DRS_ALPHABLENDENABLE
110 			TRUE to enable alpha-blended transparency. The default value is FALSE.
111 			The type of alpha blending is determined by the BD3DRS_SRCBLEND and BD3DRS_DESTBLEND render states.
112 		*/
113 		BD3DRS_ALPHABLENDENABLE,
114 
115 		/*! BD3DRS_FOGENABLE
116 			TRUE to enable fog blending. The default value is FALSE. For more information about using fog
117 			blending, see Fog.
118 		*/
119 		BD3DRS_FOGENABLE,
120 
121 		/*!	BD3DRS_SPECULARENABLE
122 			TRUE to enable specular highlights. The default value is FALSE.
123 			Specular highlights are calculated as though every vertex in the object being lit is at the
124 			object's origin. This gives the expected results as long as the object is modeled around the
125 			origin and the distance from the light to the object is relatively large. In other cases, the
126 			results as undefined.
127 			When this member is set to TRUE, the specular color is added to the base color after the
128 			texture cascade but before alpha blending.
129 		*/
130 		BD3DRS_SPECULARENABLE,
131 
132 		/*! BD3DRS_FOGCOLOR
133 			Value whose type is D3DCOLOR. The default value is 0. For more information about fog color,
134 			see Fog Color.
135 		*/
136 		BD3DRS_FOGCOLOR,
137 
138 		/*!	BD3DRS_FOGTABLEMODE
139 			The fog formula to be used for pixel fog. Set to one of the members of the D3DFOGMODE
140 			enumerated type. The default value is D3DFOG_NONE. For more information about pixel fog,
141 			see Pixel Fog.
142 		*/
143 		BD3DRS_FOGTABLEMODE,
144 
145 		/*! BD3DRS_FOGSTART
146 			Depth at which pixel or vertex fog effects begin for linear fog mode. The default value is 0.0f.
147 			Depth is specified in world space for vertex fog and either device space [0.0, 1.0] or world
148 			space for pixel fog. For pixel fog, these values are in device space when the system uses z for
149 			fog calculations and world-world space when the system is using eye-relative fog (w-fog). For
150 			more information, see Fog Parameters and Eye-Relative vs. Z-based Depth.
151 			Values for the this render state are floating-point values.
152 			Because the IDirect3DDevice9::SetRenderState method accepts DWORD values, your
153 			application must cast a variable that contains the value, as shown in the following code example.
154 			pDevice9->SetRenderState( BD3DRS_FOGSTART, *((DWORD*) (&fFogStart)));
155 		*/
156 		BD3DRS_FOGSTART,
157 
158 		/*! BD3DRS_FOGEND
159 			Depth at which pixel or vertex fog effects end for linear fog mode. The default value is 1.0f.
160 			Depth is specified in world space for vertex fog and either device space [0.0, 1.0] or world space
161 			for pixel fog. For pixel fog, these values are in device space when the system uses z for fog
162 			calculations and in world space when the system is using eye-relative fog (w-fog). For more
163 			information, see Fog Parameters and Eye-Relative vs. Z-based Depth.
164 			Values for this render state are floating-point values.
165 		*/
166 		BD3DRS_FOGEND,
167 
168 		/*! BD3DRS_FOGDENSITY
169 			Fog density for pixel or vertex fog used in the exponential fog modes (D3DFOG_EXP and D3DFOG_EXP2).
170 			Valid density values range from 0.0 through 1.0. The default value is 1.0. For more information,
171 			see Fog Parameters.
172 			Values for this render state are floating-point values.
173 		*/
174 		BD3DRS_FOGDENSITY,
175 
176 
177 		/*! BD3DRS_RANGEFOGENABLE
178 			TRUE to enable range-based vertex fog. The default value is FALSE, in which case the system
179 			uses depth-based fog. In range-based fog, the distance of an object from the viewer is used
180 			to compute fog effects, not the depth of the object (that is, the z-coordinate) in the scene.
181 			In range-based fog, all fog methods work as usual, except that they use range instead of depth
182 			in the computations.
183 			Range is the correct factor to use for fog computations, but depth is commonly used instead
184 			because range is time-consuming to compute and depth is generally already available. Using depth
185 			to calculate fog has the undesirable effect of having the fogginess of peripheral objects change
186 			as the viewer's eye moves - in this case, the depth changes and the range remains constant.
187 
188 			Because no hardware currently supports per-pixel range-based fog, range correction is offered
189 			only for vertex fog.
190 			For more information, see Vertex Fog.
191 		*/
192 		BD3DRS_RANGEFOGENABLE = 48,
193 
194 		/*! BD3DRS_STENCILENABLE
195 			TRUE to enable stenciling, or FALSE to disable stenciling. The default value is FALSE.
196 			For more information, see Stencil Buffer Techniques.
197 		*/
198 		BD3DRS_STENCILENABLE = 52,
199 
200 		/*!	BD3DRS_STENCILFAIL
201 			Stencil operation to perform if the stencil test fails. Values are from the D3DSTENCILOP
202 			enumerated type. The default value is D3DSTENCILOP_KEEP.
203 		*/
204 		BD3DRS_STENCILFAIL = 53,
205 
206 		/*!	BD3DRS_STENCILZFAIL
207 			Stencil operation to perform if the stencil test passes and the depth test (z-test) fails.
208 			Values are from the D3DSTENCILOP enumerated type. The default value is D3DSTENCILOP_KEEP.
209 		*/
210 		BD3DRS_STENCILZFAIL = 54,
211 
212 		/*!	BD3DRS_STENCILPASS
213 			Stencil operation to perform if both the stencil and the depth (z) tests pass. Values are
214 			from the D3DSTENCILOP enumerated type. The default value is D3DSTENCILOP_KEEP.
215 		*/
216 		BD3DRS_STENCILPASS = 55,
217 
218 		/*!	BD3DRS_STENCILFUNC
219 			Comparison function for the stencil test. Values are from the D3DCMPFUNC enumerated type.
220 			The default value is D3DCMP_ALWAYS.
221 			The comparison function is used to compare the reference value to a stencil buffer entry.
222 			This comparison applies only to the bits in the reference value and stencil buffer entry that
223 			are set in the stencil mask (set by the D3DRS_STENCILMASK render state). If TRUE, the stencil
224 			test passes.
225 		*/
226 		BD3DRS_STENCILFUNC = 56,
227 
228 		/*! BD3DRS_STENCILREF
229 			An int reference value for the stencil test. The default value is 0.
230 		*/
231 		BD3DRS_STENCILREF = 57,
232 
233 		/*! BD3DRS_STENCILMASK
234 			Mask applied to the reference value and each stencil buffer entry to determine the significant
235 			bits for the stencil test. The default mask is 0xFFFFFFFF.
236 		*/
237 		BD3DRS_STENCILMASK = 58,
238 
239 		/*! BD3DRS_STENCILWRITEMASK
240 			Write mask applied to values written into the stencil buffer. The default mask is 0xFFFFFFFF.
241 		*/
242 		BD3DRS_STENCILWRITEMASK = 59,
243 
244 		/*!	BD3DRS_TEXTUREFACTOR
245 			Color used for multiple-texture blending with the D3DTA_TFACTOR texture-blending argument or the
246 			D3DTOP_BLENDFACTORALPHA texture-blending operation. The associated value is a D3DCOLOR variable.
247 			The default value is opaque white (0xFFFFFFFF).
248 		*/
249 		BD3DRS_TEXTUREFACTOR = 60,
250 
251 		/*! BD3DRS_WRAP0
252 			Texture-wrapping behavior for multiple sets of texture coordinates. Valid values for this
253 			render state can be any combination of the D3DWRAPCOORD_0 (or D3DWRAP_U), D3DWRAPCOORD_1
254 			(or D3DWRAP_V), D3DWRAPCOORD_2 (or D3DWRAP_W), and D3DWRAPCOORD_3 flags. These cause the system
255 			to wrap in the direction of the first, second, third, and fourth dimensions, sometimes referred
256 			to as the s, t, r, and q directions, for a given texture. The default value for this render state
257 			is 0 (wrapping disabled in all directions).
258 		*/
259 		BD3DRS_WRAP0 = 128,
260 		BD3DRS_WRAP1 = 129,
261 		BD3DRS_WRAP2 = 130,
262 		BD3DRS_WRAP3 = 131,
263 		BD3DRS_WRAP4 = 132,
264 		BD3DRS_WRAP5 = 133,
265 		BD3DRS_WRAP6 = 134,
266 		BD3DRS_WRAP7 = 135,
267 
268 		/*! BD3DRS_CLIPPING
269 			TRUE to enable primitive clipping by Direct3D, or FALSE to disable it. The default value is TRUE.
270 		*/
271 		BD3DRS_CLIPPING = 136,
272 
273 		/*! BD3DRS_LIGHTING
274 			TRUE to enable Direct3D lighting, or FALSE to disable it. The default value is TRUE. Only
275 			vertices that include a vertex normal are properly lit; vertices that do not contain a normal
276 			employ a dot product of 0 in all lighting calculations.
277 		*/
278 		BD3DRS_LIGHTING = 137,
279 
280 		/*! D3DRS_AMBIENT
281 			Ambient light color. This value is of type D3DCOLOR. The default value is 0.
282 		*/
283 		BD3DRS_AMBIENT = 139,
284 
285 		/*! BD3DRS_FOGVERTEXMODE
286 			Fog formula to be used for vertex fog. Set to one member of the BD3DFOGMODE enumerated type.
287 			The default value is D3DFOG_NONE.
288 		*/
289 		BD3DRS_FOGVERTEXMODE = 140,
290 
291 		/*! BD3DRS_COLORVERTEX
292 			TRUE to enable per-vertex color or FALSE to disable it. The default value is TRUE. Enabling
293 			per-vertex color allows the system to include the color defined for individual vertices in its
294 			lighting calculations.
295 			For more information, see the following render states:
296 				BD3DRS_DIFFUSEMATERIALSOURCE
297 				BD3DRS_SPECULARMATERIALSOURCE
298 				BD3DRS_AMBIENTMATERIALSOURCE
299 				BD3DRS_EMISSIVEMATERIALSOURCE
300 		*/
301 		BD3DRS_COLORVERTEX = 141,
302 
303 		/*! BD3DRS_LOCALVIEWER
304 			TRUE to enable camera-relative specular highlights, or FALSE to use orthogonal specular
305 			highlights. The default value is TRUE. Applications that use orthogonal projection should
306 			specify false.
307 		*/
308 		BD3DRS_LOCALVIEWER = 142,
309 
310 		/*! BD3DRS_NORMALIZENORMALS
311 			TRUE to enable automatic normalization of vertex normals, or FALSE to disable it. The default
312 			value is FALSE. Enabling this feature causes the system to normalize the vertex normals for
313 			vertices after transforming them to camera space, which can be computationally time-consuming.
314 		*/
315 		BD3DRS_NORMALIZENORMALS = 143,
316 
317 		/*! BD3DRS_DIFFUSEMATERIALSOURCE
318 			Diffuse color source for lighting calculations. Valid values are members of the
319 			D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_COLOR1. The value for this
320 			render state is used only if the D3DRS_COLORVERTEX render state is set to TRUE.
321 		*/
322 		BD3DRS_DIFFUSEMATERIALSOURCE = 145,
323 
324 		/*! BD3DRS_SPECULARMATERIALSOURCE
325 			Specular color source for lighting calculations. Valid values are members of the
326 			D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_COLOR2.
327 		*/
328 		BD3DRS_SPECULARMATERIALSOURCE = 146,
329 
330 		/*! D3DRS_AMBIENTMATERIALSOURCE
331 			Ambient color source for lighting calculations. Valid values are members of the
332 			D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_MATERIAL.
333 		*/
334 		BD3DRS_AMBIENTMATERIALSOURCE = 147,
335 
336 		/*! D3DRS_EMISSIVEMATERIALSOURCE
337 			Emissive color source for lighting calculations. Valid values are members of the
338 			D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_MATERIAL.
339 		*/
340 		BD3DRS_EMISSIVEMATERIALSOURCE = 148,
341 
342 		/*! D3DRS_VERTEXBLEND
343 			Number of matrices to use to perform geometry blending, if any. Valid values are members
344 			of the D3DVERTEXBLENDFLAGS enumerated type. The default value is D3DVBF_DISABLE.
345 		*/
346 		BD3DRS_VERTEXBLEND = 151,
347 
348 		/* D3DRS_CLIPPLANEENABLE
349 			Enables or disables user-defined clipping planes. Valid values are any DWORD in which the
350 			status of each bit (set or not set) toggles the activation state of a corresponding user-defined
351 			clipping plane. The least significant bit (bit 0) controls the first clipping plane at index 0,
352 			and subsequent bits control the activation of clipping planes at higher indexes. If a bit is set,
353 			the system applies the appropriate clipping plane during scene rendering. The default value is 0.
354 			The D3DCLIPPLANEn macros are defined to provide a convenient way to enable clipping planes.
355 		*/
356 		BD3DRS_CLIPPLANEENABLE = 152,
357 		BD3DRS_POINTSIZE = 154,
358 		BD3DRS_POINTSIZE_MIN = 155,
359 		BD3DRS_POINTSPRITEENABLE = 156,
360 		BD3DRS_POINTSCALEENABLE = 157,
361 		BD3DRS_POINTSCALE_A = 158,
362 		BD3DRS_POINTSCALE_B = 159,
363 		BD3DRS_POINTSCALE_C = 160,
364 		BD3DRS_MULTISAMPLEANTIALIAS = 161,
365 		BD3DRS_MULTISAMPLEMASK = 162,
366 		BD3DRS_PATCHEDGESTYLE = 163,
367 		BD3DRS_DEBUGMONITORTOKEN = 165,
368 		BD3DRS_POINTSIZE_MAX = 166,
369 		BD3DRS_INDEXEDVERTEXBLENDENABLE = 167,
370 		BD3DRS_COLORWRITEENABLE = 168,
371 		BD3DRS_TWEENFACTOR = 170,
372 		BD3DRS_BLENDOP = 171,
373 		BD3DRS_POSITIONDEGREE = 172,
374 		BD3DRS_NORMALDEGREE = 173,
375 		BD3DRS_SCISSORTESTENABLE = 174,
376 		BD3DRS_SLOPESCALEDEPTHBIAS = 175,
377 		BD3DRS_ANTIALIASEDLINEENABLE = 176,
378 		BD3DRS_MINTESSELLATIONLEVEL = 178,
379 		BD3DRS_MAXTESSELLATIONLEVEL = 179,
380 		BD3DRS_ADAPTIVETESS_X = 180,
381 		BD3DRS_ADAPTIVETESS_Y = 181,
382 		BD3DRS_ADAPTIVETESS_Z = 182,
383 		BD3DRS_ADAPTIVETESS_W = 183,
384 		BD3DRS_ENABLEADAPTIVETESSELLATION = 184,
385 		BD3DRS_TWOSIDEDSTENCILMODE = 185,
386 		BD3DRS_CCW_STENCILFAIL = 186,
387 		BD3DRS_CCW_STENCILZFAIL = 187,
388 		BD3DRS_CCW_STENCILPASS = 188,
389 		BD3DRS_CCW_STENCILFUNC = 189,
390 		BD3DRS_COLORWRITEENABLE1 = 190,
391 		BD3DRS_COLORWRITEENABLE2 = 191,
392 		BD3DRS_COLORWRITEENABLE3 = 192,
393 		BD3DRS_BLENDFACTOR = 193,
394 		BD3DRS_SRGBWRITEENABLE = 194,
395 		BD3DRS_DEPTHBIAS = 195,
396 		BD3DRS_WRAP8 = 198,
397 		BD3DRS_WRAP9 = 199,
398 		BD3DRS_WRAP10 = 200,
399 		BD3DRS_WRAP11 = 201,
400 		BD3DRS_WRAP12 = 202,
401 		BD3DRS_WRAP13 = 203,
402 		BD3DRS_WRAP14 = 204,
403 		BD3DRS_WRAP15 = 205,
404 		BD3DRS_SEPARATEALPHABLENDENABLE = 206,
405 		BD3DRS_SRCBLENDALPHA = 207,
406 		BD3DRS_DESTBLENDALPHA = 208,
407 		BD3DRS_BLENDOPALPHA = 209,
408 
409 		BD3DRS_MAX_TYPE
410 	};
411 
412 
413 
414 	/*! Defines constants that describe depth-buffer formats
415 		Members of this enumerated type are used with the D3DRS_ZENABLE render state.
416 	*/
417 	enum BD3DZBUFFERTYPE
418 	{
419 		BD3DZB_FALSE                 = 0,	// Disable depth buffering
420 		BD3DZB_TRUE                  = 1,	// Enable z-buffering
421 		BD3DZB_USEW                  = 2	//Enable w-buffering.
422 	};
423 
424 	//! Defines the supported compare functions.
425 	enum BD3DCMPFUNC
426 	{
427 		BD3DCMP_NEVER	= 1,// Always fail the test.
428 		BD3DCMP_LESS,		// Accept the new pixel if its value is less than the value of the current pixel.
429 		BD3DCMP_EQUAL,		// Accept the new pixel if its value equals the value of the current pixel.
430 		BD3DCMP_LESSEQUAL,	// Accept the new pixel if its value is less than or equal to the value of the current pixel.
431 		BD3DCMP_GREATER,		// Accept the new pixel if its value is greater than the value of the current pixel.
432 		BD3DCMP_NOTEQUAL,	// Accept the new pixel if its value does not equal the value of the current pixel.
433 		BD3DCMP_GREATEREQUAL,// Accept the new pixel if its value is greater than or equal to the value of the current pixel.
434 		BD3DCMP_ALWAYS		// Always pass the test.
435 	};
436 
437 	enum BD3DMATERIALCOLORSOURCE
438 	{
439 		BD3DMCS_MATERIAL = 0,	// Use the color from the current material.
440 		BD3DMCS_COLOR1 = 1,		// Use the diffuse vertex color.
441 		BD3DMCS_COLOR2 = 2		// Use the specular vertex color.
442 	};
443 
444 
445 	//! Defines constants that describe the supported shading modes.
446 	enum BD3DSHADEMODE
447 	{
448 		/*!	BD3DSHADE_FLAT
449 			Flat shading mode. The color and specular component of the first vertex in the triangle
450 			are used to determine the color and specular component of the face. These colors remain
451 			constant across the triangle; that is, they are not interpolated. The specular alpha is
452 			interpolated.
453 		*/
454 		BD3DSHADE_FLAT = 1,
455 
456 		/*!	BD3DSHADE_GOURAUD
457 			Gouraud shading mode. The color and specular components of the face are determined by a
458 			linear interpolation between all three of the triangle's vertices.
459 		*/
460 		BD3DSHADE_GOURAUD = 2,
461 
462 		/*!	BD3DSHADE_PHONG
463 			Not supported.
464 		*/
465 		BD3DSHADE_PHONG = 3
466 	};
467 
468 	/*!	Defines constants describing the fill mode
469 		The values in this enumerated type are used by the BD3DRS_FILLMODE render state
470 	*/
471 	enum BD3DFILLMODE
472 	{
473 		BD3DFILL_POINT = 1,		// Fill points.
474 		BD3DFILL_WIREFRAME = 2,	// Fill wireframes.
475 		BD3DFILL_SOLID = 3		// Fill solids.
476 	};
477 
478 
479 
480 	/*! Defines the supported culling modes.
481 		The values in this enumerated type are used by the B3DRS_CULLMODE render state.
482 		The culling modes define how back faces are culled when rendering a geometry.
483 	*/
484 	enum BD3DCULL
485 	{
486 		BD3DCULL_NONE = 1,	// Do not cull back faces.
487 		BD3DCULL_CW = 2,	// Cull back faces with clockwise vertices.
488 		BD3DCULL_CCW = 3	// Cull back faces with counterclockwise vertices.
489 	};
490 
491 	struct SShaderParam
492 	{
493 		u32 ColorUnits;
494 		u32 TextureUnits;
495 
496 		u32 RenderState [ BD3DRS_MAX_TYPE ];
497 		void SetRenderState ( BD3DRENDERSTATETYPE state, u32 value );
498 	};
499 
SetRenderState(BD3DRENDERSTATETYPE state,u32 value)500 	void SShaderParam::SetRenderState ( BD3DRENDERSTATETYPE state, u32 value )
501 	{
502 		RenderState [ state ] = value;
503 	}
504 
505 
506 
507 class CBurningShader_Raster_Reference : public IBurningShader
508 {
509 public:
510 
511 	//! constructor
512 	CBurningShader_Raster_Reference(CBurningVideoDriver* driver);
513 
514 	//! draws an indexed triangle list
515 	virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c );
516 
517 	virtual void setMaterial ( const SBurningShaderMaterial &material );
518 
519 
520 private:
521 	void scanline ();
522 	void scanline2 ();
523 
524 	sScanLineData line;
525 	sPixelShaderData pShader;
526 
527 	void pShader_1 ();
528 	void pShader_EMT_LIGHTMAP_M4 ();
529 
530 	SShaderParam ShaderParam;
531 
532 	REALINLINE u32 depthFunc ();
533 	REALINLINE void depthWrite ();
534 
535 
536 };
537 
538 //! constructor
CBurningShader_Raster_Reference(CBurningVideoDriver * driver)539 CBurningShader_Raster_Reference::CBurningShader_Raster_Reference(CBurningVideoDriver* driver)
540 : IBurningShader(driver)
541 {
542 	#ifdef _DEBUG
543 	setDebugName("CBurningShader_Raster_Reference");
544 	#endif
545 }
546 
547 
548 /*!
549 */
pShader_EMT_LIGHTMAP_M4()550 void CBurningShader_Raster_Reference::pShader_EMT_LIGHTMAP_M4 ()
551 {
552 	tFixPoint r0, g0, b0;
553 	tFixPoint r1, g1, b1;
554 
555 	f32 inversew = fix_inverse32 ( line.w[0] );
556 
557 	getSample_texture ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) );
558 	getSample_texture ( r1, g1, b1, &IT[1], tofix ( line.t[1][0].x,inversew), tofix ( line.t[1][0].y,inversew) );
559 
560 
561 	pShader.dst[pShader.i] = fix_to_color ( clampfix_maxcolor ( imulFix_tex2 ( r0, r1 ) ),
562 							clampfix_maxcolor ( imulFix_tex2 ( g0, g1 ) ),
563 							clampfix_maxcolor ( imulFix_tex2 ( b0, b1 ) )
564 						);
565 
566 }
567 
568 /*!
569 */
pShader_1()570 void CBurningShader_Raster_Reference::pShader_1 ()
571 {
572 	tFixPoint r0, g0, b0;
573 	tFixPoint tx0, ty0;
574 
575 	const f32 inversew = fix_inverse32 ( line.w[0] );
576 
577 	tx0 = tofix ( line.t[0][0].x, inversew );
578 	ty0 = tofix ( line.t[0][0].y, inversew );
579 
580 	getSample_texture ( r0, g0, b0, &IT[0], tx0, ty0 );
581 	pShader.dst[pShader.i] = fix_to_color ( r0, g0, b0 );
582 
583 }
584 
585 
586 /*!
587 */
setMaterial(const SBurningShaderMaterial & material)588 void CBurningShader_Raster_Reference::setMaterial ( const SBurningShaderMaterial &material )
589 {
590 	const video::SMaterial &m = material.org;
591 
592 	u32 i;
593 	u32 enable;
594 
595 	ShaderParam.ColorUnits = 0;
596 	ShaderParam.TextureUnits = 0;
597 	for ( i = 0; i != BURNING_MATERIAL_MAX_TEXTURES; ++i )
598 	{
599 		if ( m.getTexture( i ) )
600 			ShaderParam.TextureUnits = i;
601 	}
602 
603 	// shademode
604 	ShaderParam.SetRenderState( BD3DRS_SHADEMODE,
605 		m.GouraudShading ? BD3DSHADE_GOURAUD : BD3DSHADE_FLAT
606 	);
607 
608 	// fillmode
609 	ShaderParam.SetRenderState( BD3DRS_FILLMODE,
610 		m.Wireframe ? BD3DFILL_WIREFRAME : m.PointCloud ? BD3DFILL_POINT : BD3DFILL_SOLID
611 	);
612 
613 	// back face culling
614 	ShaderParam.SetRenderState( BD3DRS_CULLMODE,
615 		m.BackfaceCulling ? BD3DCULL_CCW : BD3DCULL_NONE
616 	);
617 
618 	// lighting
619 	ShaderParam.SetRenderState( BD3DRS_LIGHTING, m.Lighting );
620 
621 	// specular highlights
622 	enable = F32_LOWER_EQUAL_0 ( m.Shininess );
623 	ShaderParam.SetRenderState( BD3DRS_SPECULARENABLE, enable);
624 	ShaderParam.SetRenderState( BD3DRS_NORMALIZENORMALS, enable);
625 	ShaderParam.SetRenderState( BD3DRS_SPECULARMATERIALSOURCE, (m.ColorMaterial==ECM_SPECULAR)?BD3DMCS_COLOR1:BD3DMCS_MATERIAL);
626 
627 	// depth buffer enable and compare
628 	ShaderParam.SetRenderState( BD3DRS_ZENABLE, (material.org.ZBuffer==video::ECFN_NEVER) ? BD3DZB_FALSE : BD3DZB_USEW);
629 	switch (material.org.ZBuffer)
630 	{
631 	case ECFN_NEVER:
632 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_NEVER);
633 		break;
634 	case ECFN_LESSEQUAL:
635 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_LESSEQUAL);
636 		break;
637 	case ECFN_EQUAL:
638 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_EQUAL);
639 		break;
640 	case ECFN_LESS:
641 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_LESSEQUAL);
642 		break;
643 	case ECFN_NOTEQUAL:
644 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_NOTEQUAL);
645 		break;
646 	case ECFN_GREATEREQUAL:
647 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_GREATEREQUAL);
648 		break;
649 	case ECFN_GREATER:
650 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_GREATER);
651 		break;
652 	case ECFN_ALWAYS:
653 		ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_ALWAYS);
654 		break;
655 	}
656 
657 	// depth buffer write
658 	ShaderParam.SetRenderState( BD3DRS_ZWRITEENABLE, m.ZWriteEnable );
659 }
660 
661 /*!
662 */
depthFunc()663 REALINLINE u32 CBurningShader_Raster_Reference::depthFunc ()
664 {
665 	if ( ShaderParam.RenderState [ BD3DRS_ZENABLE ] )
666 	{
667 		switch ( ShaderParam.RenderState [ BD3DRS_ZFUNC ] )
668 		{
669 			case BD3DCMP_LESSEQUAL:
670 				return line.w[0] >= pShader.z[ pShader.i];
671 			case BD3DCMP_EQUAL:
672 				return line.w[0] == pShader.z[ pShader.i];
673 		}
674 	}
675 	return 1;
676 }
677 
678 /*!
679 */
depthWrite()680 REALINLINE void CBurningShader_Raster_Reference::depthWrite ()
681 {
682 	if ( ShaderParam.RenderState [ BD3DRS_ZWRITEENABLE ] )
683 	{
684 		pShader.z[pShader.i] = line.w[0];
685 	}
686 }
687 
688 /*!
689 */
scanline2()690 REALINLINE void CBurningShader_Raster_Reference::scanline2()
691 {
692 	// apply top-left fill-convention, left
693 	pShader.xStart = core::ceil32( line.x[0] );
694 	pShader.xEnd = core::ceil32( line.x[1] ) - 1;
695 
696 	pShader.dx = pShader.xEnd - pShader.xStart;
697 	if ( pShader.dx < 0 )
698 		return;
699 
700 	// slopes
701 	const f32 invDeltaX = core::reciprocal ( line.x[1] - line.x[0] );
702 	const f32 subPixel = ( (f32) pShader.xStart ) - line.x[0];
703 
704 	// store slopes in endpoint, and correct first pixel
705 
706 	line.w[0] += (line.w[1] = (line.w[1] - line.w[0]) * invDeltaX) * subPixel;
707 
708 	u32 i;
709 
710 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
711 	for ( i = 0; i != ShaderParam.ColorUnits; ++i )
712 	{
713 		line.c[i][1] = (line.c[i][1] - line.c[i][0]) * invDeltaX;
714 		line.c[i][0] += line.c[i][1] * subPixel;
715 	}
716 #endif
717 
718 	for ( i = 0; i != ShaderParam.TextureUnits; ++i )
719 	{
720 		line.t[i][1] = (line.t[i][1] - line.t[i][0]) * invDeltaX;
721 		line.t[i][0] += line.t[i][1] * subPixel;
722 	}
723 
724 	pShader.dst = (tVideoSample*) ( (u8*) RenderTarget->lock() + ( line.y * RenderTarget->getPitch() ) + ( pShader.xStart << VIDEO_SAMPLE_GRANULARITY ) );
725 	pShader.z = (fp24*) ( (u8*) DepthBuffer->lock() + ( line.y * DepthBuffer->getPitch() ) + ( pShader.xStart << VIDEO_SAMPLE_GRANULARITY ) );
726 
727 	for ( pShader.i = 0; pShader.i <= pShader.dx; ++pShader.i )
728 	{
729 		if ( depthFunc() )
730 		{
731 			depthWrite ();
732 		}
733 
734 		// advance next pixel
735 		line.w[0] += line.w[1];
736 
737 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
738 		for ( i = 0; i != ShaderParam.ColorUnits; ++i )
739 		{
740 			line.c[i][0] += line.c[i][1];
741 		}
742 #endif
743 		for ( i = 0; i != ShaderParam.TextureUnits; ++i )
744 		{
745 			line.t[i][0] += line.t[i][1];
746 		}
747 	}
748 }
749 
750 
751 /*!
752 */
scanline()753 REALINLINE void CBurningShader_Raster_Reference::scanline ()
754 {
755 	u32 i;
756 
757 	// apply top-left fill-convention, left
758 	pShader.xStart = core::ceil32( line.x[0] );
759 	pShader.xEnd = core::ceil32( line.x[1] ) - 1;
760 
761 	pShader.dx = pShader.xEnd - pShader.xStart;
762 	if ( pShader.dx < 0 )
763 		return;
764 
765 	// slopes
766 	const f32 invDeltaX = core::reciprocal ( line.x[1] - line.x[0] );
767 
768 	// search z-buffer for first not occulled pixel
769 	pShader.z = (fp24*) ( (u8*) DepthBuffer->lock() + ( line.y * DepthBuffer->getPitch() ) + ( pShader.xStart << VIDEO_SAMPLE_GRANULARITY ) );
770 
771 	// subTexel
772 	const f32 subPixel = ( (f32) pShader.xStart ) - line.x[0];
773 
774 	const f32 b = (line.w[1] - line.w[0]) * invDeltaX;
775 	f32 a = line.w[0] + ( b * subPixel );
776 
777 	pShader.i = 0;
778 
779 	if ( ShaderParam.RenderState [ BD3DRS_ZENABLE ] )
780 	{
781 		u32 condition;
782 		switch ( ShaderParam.RenderState [ BD3DRS_ZFUNC ] )
783 		{
784 			case BD3DCMP_LESSEQUAL:
785 				condition = a < pShader.z[pShader.i];
786 				break;
787 			case BD3DCMP_EQUAL:
788 				condition = a != pShader.z[pShader.i];
789 				break;
790 		}
791 		while ( a < pShader.z[pShader.i] )
792 		{
793 			a += b;
794 
795 			pShader.i += 1;
796 			if ( pShader.i > pShader.dx )
797 				return;
798 
799 		}
800 	}
801 
802 	// lazy setup rest of scanline
803 
804 	line.w[0] = a;
805 	line.w[1] = b;
806 
807 	pShader.dst = (tVideoSample*) ( (u8*) RenderTarget->lock() + ( line.y * RenderTarget->getPitch() ) + ( pShader.xStart << VIDEO_SAMPLE_GRANULARITY ) );
808 
809 	a = (f32) pShader.i + subPixel;
810 
811 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
812 	for ( i = 0; i != ShaderParam.ColorUnits; ++i )
813 	{
814 		line.c[i][1] = (line.c[i][1] - line.c[i][0]) * invDeltaX;
815 		line.c[i][0] += line.c[i][1] * a;
816 	}
817 #endif
818 
819 	for ( i = 0; i != ShaderParam.TextureUnits; ++i )
820 	{
821 		line.t[i][1] = (line.t[i][1] - line.t[i][0]) * invDeltaX;
822 		line.t[i][0] += line.t[i][1] * a;
823 	}
824 
825 	for ( ; pShader.i <= pShader.dx; ++pShader.i )
826 	{
827 		if ( line.w[0] >= pShader.z[pShader.i] )
828 		{
829 			pShader.z[pShader.i] = line.w[0];
830 
831 			pShader_EMT_LIGHTMAP_M4 ();
832 		}
833 
834 		line.w[0] += line.w[1];
835 
836 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
837 		for ( i = 0; i != ShaderParam.ColorUnits; ++i )
838 		{
839 			line.c[i][0] += line.c[i][1];
840 		}
841 #endif
842 		for ( i = 0; i != ShaderParam.TextureUnits; ++i )
843 		{
844 			line.t[i][0] += line.t[i][1];
845 		}
846 	}
847 
848 }
849 
850 
851 
drawTriangle(const s4DVertex * a,const s4DVertex * b,const s4DVertex * c)852 void CBurningShader_Raster_Reference::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c )
853 {
854 	sScanConvertData scan;
855 	u32 i;
856 
857 	// sort on height, y
858 	if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);
859 	if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c);
860 	if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);
861 
862 
863 	// calculate delta y of the edges
864 	scan.invDeltaY[0] = core::reciprocal ( c->Pos.y - a->Pos.y );
865 	scan.invDeltaY[1] = core::reciprocal ( b->Pos.y - a->Pos.y );
866 	scan.invDeltaY[2] = core::reciprocal ( c->Pos.y - b->Pos.y );
867 
868 	if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] )  )
869 		return;
870 
871 
872 	// find if the major edge is left or right aligned
873 	f32 temp[4];
874 
875 	temp[0] = a->Pos.x - c->Pos.x;
876 	temp[1] = a->Pos.y - c->Pos.y;
877 	temp[2] = b->Pos.x - a->Pos.x;
878 	temp[3] = b->Pos.y - a->Pos.y;
879 
880 	scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > (f32) 0.0 ? 0 : 1;
881 	scan.right = 1 - scan.left;
882 
883 	// calculate slopes for the major edge
884 	scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0];
885 	scan.x[0] = a->Pos.x;
886 
887 	scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0];
888 	scan.w[0] = a->Pos.w;
889 
890 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
891 	for ( i = 0; i != ShaderParam.ColorUnits; ++i )
892 	{
893 		scan.c[i][0] = a->Color[i];
894 		scan.slopeC[i][0] = (c->Color[i] - a->Color[i]) * scan.invDeltaY[0];
895 	}
896 #endif
897 
898 	for ( i = 0; i != ShaderParam.TextureUnits; ++i )
899 	{
900 		scan.t[i][0] = a->Tex[i];
901 		scan.slopeT[i][0] = (c->Tex[i] - a->Tex[i]) * scan.invDeltaY[0];
902 	}
903 
904 	// top left fill convention y run
905 	s32 yStart;
906 	s32 yEnd;
907 
908 	f32 subPixel;
909 
910 	// rasterize upper sub-triangle
911 	if ( F32_GREATER_0 ( scan.invDeltaY[1] ) )
912 	{
913 		// calculate slopes for top edge
914 		scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1];
915 		scan.x[1] = a->Pos.x;
916 
917 		scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1];
918 		scan.w[1] = a->Pos.w;
919 
920 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
921 		for ( i = 0; i != ShaderParam.ColorUnits; ++i )
922 		{
923 			scan.c[i][1] = a->Color[i];
924 			scan.slopeC[i][1] = (b->Color[i] - a->Color[i]) * scan.invDeltaY[1];
925 		}
926 #endif
927 		for ( i = 0; i != ShaderParam.TextureUnits; ++i )
928 		{
929 			scan.t[i][1] = a->Tex[i];
930 			scan.slopeT[i][1] = (b->Tex[i] - a->Tex[i]) * scan.invDeltaY[1];
931 		}
932 
933 		// apply top-left fill convention, top part
934 		yStart = core::ceil32( a->Pos.y );
935 		yEnd = core::ceil32( b->Pos.y ) - 1;
936 
937 		subPixel = ( (f32) yStart ) - a->Pos.y;
938 
939 		// correct to pixel center
940 		scan.x[0] += scan.slopeX[0] * subPixel;
941 		scan.x[1] += scan.slopeX[1] * subPixel;
942 
943 		scan.w[0] += scan.slopeW[0] * subPixel;
944 		scan.w[1] += scan.slopeW[1] * subPixel;
945 
946 		for ( i = 0; i != ShaderParam.ColorUnits; ++i )
947 		{
948 			scan.c[i][0] += scan.slopeC[i][0] * subPixel;
949 			scan.c[i][1] += scan.slopeC[i][1] * subPixel;
950 		}
951 
952 		for ( i = 0; i != ShaderParam.TextureUnits; ++i )
953 		{
954 			scan.t[i][0] += scan.slopeT[i][0] * subPixel;
955 			scan.t[i][1] += scan.slopeT[i][1] * subPixel;
956 		}
957 
958 		// rasterize the edge scanlines
959 		for( line.y = yStart; line.y <= yEnd; ++line.y)
960 		{
961 			line.x[scan.left] = scan.x[0];
962 			line.w[scan.left] = scan.w[0];
963 
964 			line.x[scan.right] = scan.x[1];
965 			line.w[scan.right] = scan.w[1];
966 
967 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
968 			for ( i = 0; i != ShaderParam.ColorUnits; ++i )
969 			{
970 				line.c[i][scan.left] = scan.c[i][0];
971 				line.c[i][scan.right] = scan.c[i][1];
972 			}
973 #endif
974 			for ( i = 0; i != ShaderParam.TextureUnits; ++i )
975 			{
976 				line.t[i][scan.left] = scan.t[i][0];
977 				line.t[i][scan.right] = scan.t[i][1];
978 			}
979 
980 			// render a scanline
981 			scanline ();
982 
983 			scan.x[0] += scan.slopeX[0];
984 			scan.x[1] += scan.slopeX[1];
985 
986 			scan.w[0] += scan.slopeW[0];
987 			scan.w[1] += scan.slopeW[1];
988 
989 			for ( i = 0; i != ShaderParam.ColorUnits; ++i )
990 			{
991 				scan.c[i][0] += scan.slopeC[i][0];
992 				scan.c[i][1] += scan.slopeC[i][1];
993 			}
994 
995 			for ( i = 0; i != ShaderParam.TextureUnits; ++i )
996 			{
997 				scan.t[i][0] += scan.slopeT[i][0];
998 				scan.t[i][1] += scan.slopeT[i][1];
999 			}
1000 
1001 		}
1002 	}
1003 
1004 	// rasterize lower sub-triangle
1005 	if ( F32_GREATER_0 ( scan.invDeltaY[2] ) )
1006 	{
1007 		// advance to middle point
1008 		if ( F32_GREATER_0 ( scan.invDeltaY[1] )  )
1009 		{
1010 			temp[0] = b->Pos.y - a->Pos.y;	// dy
1011 
1012 			scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0];
1013 			scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0];
1014 
1015 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
1016 			for ( i = 0; i != ShaderParam.ColorUnits; ++i )
1017 			{
1018 				scan.c[i][0] = a->Color[i] + scan.slopeC[i][0] * temp[0];
1019 			}
1020 #endif
1021 			for ( i = 0; i != ShaderParam.TextureUnits; ++i )
1022 			{
1023 				scan.t[i][0] = a->Tex[i] + scan.slopeT[i][0] * temp[0];
1024 			}
1025 		}
1026 
1027 		// calculate slopes for bottom edge
1028 		scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2];
1029 		scan.x[1] = b->Pos.x;
1030 
1031 		scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2];
1032 		scan.w[1] = b->Pos.w;
1033 
1034 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
1035 		for ( i = 0; i != ShaderParam.ColorUnits; ++i )
1036 		{
1037 			scan.c[i][1] = b->Color[i];
1038 			scan.slopeC[i][1] = (c->Color[i] - b->Color[i]) * scan.invDeltaY[2];
1039 		}
1040 #endif
1041 		for ( i = 0; i != ShaderParam.TextureUnits; ++i )
1042 		{
1043 			scan.t[i][1] = b->Tex[i];
1044 			scan.slopeT[i][1] = (c->Tex[i] - b->Tex[i]) * scan.invDeltaY[2];
1045 		}
1046 
1047 		// apply top-left fill convention, top part
1048 		yStart = core::ceil32( b->Pos.y );
1049 		yEnd = core::ceil32( c->Pos.y ) - 1;
1050 
1051 
1052 		subPixel = ( (f32) yStart ) - b->Pos.y;
1053 
1054 		// correct to pixel center
1055 		scan.x[0] += scan.slopeX[0] * subPixel;
1056 		scan.x[1] += scan.slopeX[1] * subPixel;
1057 
1058 		scan.w[0] += scan.slopeW[0] * subPixel;
1059 		scan.w[1] += scan.slopeW[1] * subPixel;
1060 
1061 		for ( i = 0; i != ShaderParam.ColorUnits; ++i )
1062 		{
1063 			scan.c[i][0] += scan.slopeC[i][0] * subPixel;
1064 			scan.c[i][1] += scan.slopeC[i][1] * subPixel;
1065 		}
1066 
1067 		for ( i = 0; i != ShaderParam.TextureUnits; ++i )
1068 		{
1069 			scan.t[i][0] += scan.slopeT[i][0] * subPixel;
1070 			scan.t[i][1] += scan.slopeT[i][1] * subPixel;
1071 		}
1072 
1073 		// rasterize the edge scanlines
1074 		for( line.y = yStart; line.y <= yEnd; ++line.y)
1075 		{
1076 			line.x[scan.left] = scan.x[0];
1077 			line.w[scan.left] = scan.w[0];
1078 
1079 			line.x[scan.right] = scan.x[1];
1080 			line.w[scan.right] = scan.w[1];
1081 
1082 #ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
1083 			for ( i = 0; i != ShaderParam.ColorUnits; ++i )
1084 			{
1085 				line.c[i][scan.left] = scan.c[i][0];
1086 				line.c[i][scan.right] = scan.c[i][1];
1087 			}
1088 #endif
1089 			for ( i = 0; i != ShaderParam.TextureUnits; ++i )
1090 			{
1091 				line.t[i][scan.left] = scan.t[i][0];
1092 				line.t[i][scan.right] = scan.t[i][1];
1093 			}
1094 
1095 			// render a scanline
1096 			scanline ();
1097 
1098 			scan.x[0] += scan.slopeX[0];
1099 			scan.x[1] += scan.slopeX[1];
1100 
1101 			scan.w[0] += scan.slopeW[0];
1102 			scan.w[1] += scan.slopeW[1];
1103 
1104 			for ( i = 0; i != ShaderParam.TextureUnits; ++i )
1105 			{
1106 				scan.c[i][0] += scan.slopeC[i][0];
1107 				scan.c[i][1] += scan.slopeC[i][1];
1108 			}
1109 
1110 			for ( i = 0; i != ShaderParam.TextureUnits; ++i )
1111 			{
1112 				scan.t[i][0] += scan.slopeT[i][0];
1113 				scan.t[i][1] += scan.slopeT[i][1];
1114 			}
1115 		}
1116 	}
1117 }
1118 
1119 
1120 } // end namespace video
1121 } // end namespace irr
1122 
1123 
1124 namespace irr
1125 {
1126 namespace video
1127 {
1128 
1129 
1130 
1131 //! creates a flat triangle renderer
createTriangleRendererReference(CBurningVideoDriver * driver)1132 IBurningShader* createTriangleRendererReference(CBurningVideoDriver* driver)
1133 {
1134 	return new CBurningShader_Raster_Reference(driver);
1135 }
1136 
1137 
1138 } // end namespace video
1139 } // end namespace irr
1140 
1141 #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
1142 
1143 
1144