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