aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/S4DVertex.h
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-01-13 19:47:58 +1000
committerDavid Walter Seikel2014-01-13 19:47:58 +1000
commitf9158592e1478b2013afc7041d9ed041cf2d2f4a (patch)
treeb16e389d7988700e21b4c9741044cefa536dcbae /libraries/irrlicht-1.8/source/Irrlicht/S4DVertex.h
parentLibraries readme updated with change markers and more of the Irrlicht changes. (diff)
downloadSledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.zip
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.gz
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.bz2
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.xz
Update Irrlicht to 1.8.1. Include actual change markers this time. lol
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/S4DVertex.h693
1 files changed, 0 insertions, 693 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/S4DVertex.h b/libraries/irrlicht-1.8/source/Irrlicht/S4DVertex.h
deleted file mode 100644
index 487b1cc..0000000
--- a/libraries/irrlicht-1.8/source/Irrlicht/S4DVertex.h
+++ /dev/null
@@ -1,693 +0,0 @@
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
6#ifndef __S_4D_VERTEX_H_INCLUDED__
7#define __S_4D_VERTEX_H_INCLUDED__
8
9#include "SoftwareDriver2_compile_config.h"
10#include "SoftwareDriver2_helper.h"
11#include "irrAllocator.h"
12
13namespace irr
14{
15
16namespace video
17{
18
19struct sVec2
20{
21 f32 x;
22 f32 y;
23
24 sVec2 () {}
25
26 sVec2 ( f32 s) : x ( s ), y ( s ) {}
27 sVec2 ( f32 _x, f32 _y )
28 : x ( _x ), y ( _y ) {}
29
30 void set ( f32 _x, f32 _y )
31 {
32 x = _x;
33 y = _y;
34 }
35
36 // f = a * t + b * ( 1 - t )
37 void interpolate(const sVec2& a, const sVec2& b, const f32 t)
38 {
39 x = b.x + ( ( a.x - b.x ) * t );
40 y = b.y + ( ( a.y - b.y ) * t );
41 }
42
43 sVec2 operator-(const sVec2& other) const
44 {
45 return sVec2(x - other.x, y - other.y);
46 }
47
48 sVec2 operator+(const sVec2& other) const
49 {
50 return sVec2(x + other.x, y + other.y);
51 }
52
53 void operator+=(const sVec2& other)
54 {
55 x += other.x;
56 y += other.y;
57 }
58
59 sVec2 operator*(const f32 s) const
60 {
61 return sVec2(x * s , y * s);
62 }
63
64 void operator*=( const f32 s)
65 {
66 x *= s;
67 y *= s;
68 }
69
70 void operator=(const sVec2& other)
71 {
72 x = other.x;
73 y = other.y;
74 }
75
76};
77
78// A8R8G8B8
79struct sVec4;
80struct sCompressedVec4
81{
82 u32 argb;
83
84 void setA8R8G8B8 ( u32 value )
85 {
86 argb = value;
87 }
88
89 void setColorf ( const video::SColorf & color )
90 {
91 argb = core::floor32 ( color.a * 255.f ) << 24 |
92 core::floor32 ( color.r * 255.f ) << 16 |
93 core::floor32 ( color.g * 255.f ) << 8 |
94 core::floor32 ( color.b * 255.f );
95 }
96
97 void setVec4 ( const sVec4 & v );
98
99 // f = a * t + b * ( 1 - t )
100 void interpolate(const sCompressedVec4& a, const sCompressedVec4& b, const f32 t)
101 {
102 argb = PixelBlend32 ( b.argb, a.argb, core::floor32 ( t * 256.f ) );
103 }
104
105
106};
107
108
109struct sVec4
110{
111 union
112 {
113 struct { f32 x, y, z, w; };
114 struct { f32 a, r, g, b; };
115// struct { sVec2 xy, zw; }; // sorry, this does not compile with gcc
116 };
117
118
119
120 sVec4 () {}
121
122 sVec4 ( f32 s) : x ( s ), y ( s ), z ( s ), w ( s ) {}
123
124 sVec4 ( f32 _x, f32 _y, f32 _z, f32 _w )
125 : x ( _x ), y ( _y ), z( _z ), w ( _w ){}
126
127 void set ( f32 _x, f32 _y, f32 _z, f32 _w )
128 {
129 x = _x;
130 y = _y;
131 z = _z;
132 w = _w;
133 }
134
135 void setA8R8G8B8 ( u32 argb )
136 {
137 x = ( ( argb & 0xFF000000 ) >> 24 ) * ( 1.f / 255.f );
138 y = ( ( argb & 0x00FF0000 ) >> 16 ) * ( 1.f / 255.f );
139 z = ( ( argb & 0x0000FF00 ) >> 8 ) * ( 1.f / 255.f );
140 w = ( ( argb & 0x000000FF ) ) * ( 1.f / 255.f );
141 }
142
143
144 void setColorf ( const video::SColorf & color )
145 {
146 x = color.a;
147 y = color.r;
148 z = color.g;
149 w = color.b;
150 }
151
152
153 // f = a * t + b * ( 1 - t )
154 void interpolate(const sVec4& a, const sVec4& b, const f32 t)
155 {
156 x = b.x + ( ( a.x - b.x ) * t );
157 y = b.y + ( ( a.y - b.y ) * t );
158 z = b.z + ( ( a.z - b.z ) * t );
159 w = b.w + ( ( a.w - b.w ) * t );
160 }
161
162
163 f32 dotProduct(const sVec4& other) const
164 {
165 return x*other.x + y*other.y + z*other.z + w*other.w;
166 }
167
168 f32 dot_xyz( const sVec4& other) const
169 {
170 return x*other.x + y*other.y + z*other.z;
171 }
172
173 f32 get_length_xyz_square () const
174 {
175 return x * x + y * y + z * z;
176 }
177
178 f32 get_length_xyz () const
179 {
180 return core::squareroot ( x * x + y * y + z * z );
181 }
182
183 void normalize_xyz ()
184 {
185 const f32 l = core::reciprocal_squareroot ( x * x + y * y + z * z );
186
187 x *= l;
188 y *= l;
189 z *= l;
190 }
191
192 void project_xyz ()
193 {
194 w = core::reciprocal ( w );
195 x *= w;
196 y *= w;
197 z *= w;
198 }
199
200 sVec4 operator-(const sVec4& other) const
201 {
202 return sVec4(x - other.x, y - other.y, z - other.z,w - other.w);
203 }
204
205 sVec4 operator+(const sVec4& other) const
206 {
207 return sVec4(x + other.x, y + other.y, z + other.z,w + other.w);
208 }
209
210 void operator+=(const sVec4& other)
211 {
212 x += other.x;
213 y += other.y;
214 z += other.z;
215 w += other.w;
216 }
217
218 sVec4 operator*(const f32 s) const
219 {
220 return sVec4(x * s , y * s, z * s,w * s);
221 }
222
223 sVec4 operator*(const sVec4 &other) const
224 {
225 return sVec4(x * other.x , y * other.y, z * other.z,w * other.w);
226 }
227
228 void mulReciprocal ( f32 s )
229 {
230 const f32 i = core::reciprocal ( s );
231 x = (f32) ( x * i );
232 y = (f32) ( y * i );
233 z = (f32) ( z * i );
234 w = (f32) ( w * i );
235 }
236
237 void mul ( const f32 s )
238 {
239 x *= s;
240 y *= s;
241 z *= s;
242 w *= s;
243 }
244
245/*
246 void operator*=(f32 s)
247 {
248 x *= s;
249 y *= s;
250 z *= s;
251 w *= s;
252 }
253*/
254 void operator*=(const sVec4 &other)
255 {
256 x *= other.x;
257 y *= other.y;
258 z *= other.z;
259 w *= other.w;
260 }
261
262 void operator=(const sVec4& other)
263 {
264 x = other.x;
265 y = other.y;
266 z = other.z;
267 w = other.w;
268 }
269};
270
271struct sVec3
272{
273 union
274 {
275 struct { f32 r, g, b; };
276 struct { f32 x, y, z; };
277 };
278
279
280 sVec3 () {}
281 sVec3 ( f32 _x, f32 _y, f32 _z )
282 : r ( _x ), g ( _y ), b( _z ) {}
283
284 sVec3 ( const sVec4 &v )
285 : r ( v.x ), g ( v.y ), b( v.z ) {}
286
287 void set ( f32 _r, f32 _g, f32 _b )
288 {
289 r = _r;
290 g = _g;
291 b = _b;
292 }
293
294 void setR8G8B8 ( u32 argb )
295 {
296 r = ( ( argb & 0x00FF0000 ) >> 16 ) * ( 1.f / 255.f );
297 g = ( ( argb & 0x0000FF00 ) >> 8 ) * ( 1.f / 255.f );
298 b = ( ( argb & 0x000000FF ) ) * ( 1.f / 255.f );
299 }
300
301 void setColorf ( const video::SColorf & color )
302 {
303 r = color.r;
304 g = color.g;
305 b = color.b;
306 }
307
308 void add (const sVec3& other)
309 {
310 r += other.r;
311 g += other.g;
312 b += other.b;
313 }
314
315 void mulAdd(const sVec3& other, const f32 v)
316 {
317 r += other.r * v;
318 g += other.g * v;
319 b += other.b * v;
320 }
321
322 void mulAdd(const sVec3& v0, const sVec3& v1)
323 {
324 r += v0.r * v1.r;
325 g += v0.g * v1.g;
326 b += v0.b * v1.b;
327 }
328
329 void saturate ( sVec4 &dest, u32 argb )
330 {
331 dest.x = ( ( argb & 0xFF000000 ) >> 24 ) * ( 1.f / 255.f );
332 dest.y = core::min_ ( r, 1.f );
333 dest.z = core::min_ ( g, 1.f );
334 dest.w = core::min_ ( b, 1.f );
335 }
336
337 // f = a * t + b * ( 1 - t )
338 void interpolate(const sVec3& v0, const sVec3& v1, const f32 t)
339 {
340 r = v1.r + ( ( v0.r - v1.r ) * t );
341 g = v1.g + ( ( v0.g - v1.g ) * t );
342 b = v1.b + ( ( v0.b - v1.b ) * t );
343 }
344
345 sVec3 operator-(const sVec3& other) const
346 {
347 return sVec3(r - other.r, b - other.b, g - other.g);
348 }
349
350 sVec3 operator+(const sVec3& other) const
351 {
352 return sVec3(r + other.r, g + other.g, b + other.b);
353 }
354
355 sVec3 operator*(const f32 s) const
356 {
357 return sVec3(r * s , g * s, b * s);
358 }
359
360 sVec3 operator/(const f32 s) const
361 {
362 f32 inv = 1.f / s;
363 return sVec3(r * inv , g * inv, b * inv);
364 }
365
366 sVec3 operator*(const sVec3 &other) const
367 {
368 return sVec3(r * other.r , b * other.b, g * other.g);
369 }
370
371 void operator+=(const sVec3& other)
372 {
373 r += other.r;
374 g += other.g;
375 b += other.b;
376 }
377
378 void setLength ( f32 len )
379 {
380 const f32 l = len * core::reciprocal_squareroot ( r * r + g * g + b * b );
381
382 r *= l;
383 g *= l;
384 b *= l;
385 }
386
387};
388
389
390
391inline void sCompressedVec4::setVec4 ( const sVec4 & v )
392{
393 argb = core::floor32 ( v.x * 255.f ) << 24 |
394 core::floor32 ( v.y * 255.f ) << 16 |
395 core::floor32 ( v.z * 255.f ) << 8 |
396 core::floor32 ( v.w * 255.f );
397}
398
399
400enum e4DVertexFlag
401{
402 VERTEX4D_INSIDE = 0x0000003F,
403 VERTEX4D_CLIPMASK = 0x0000003F,
404 VERTEX4D_PROJECTED = 0x00000100,
405
406 VERTEX4D_FORMAT_MASK = 0xFFFF0000,
407
408 VERTEX4D_FORMAT_MASK_TEXTURE = 0x000F0000,
409 VERTEX4D_FORMAT_TEXTURE_1 = 0x00010000,
410 VERTEX4D_FORMAT_TEXTURE_2 = 0x00020000,
411 VERTEX4D_FORMAT_TEXTURE_3 = 0x00030000,
412 VERTEX4D_FORMAT_TEXTURE_4 = 0x00040000,
413
414 VERTEX4D_FORMAT_MASK_COLOR = 0x00F00000,
415 VERTEX4D_FORMAT_COLOR_1 = 0x00100000,
416 VERTEX4D_FORMAT_COLOR_2 = 0x00200000,
417
418 VERTEX4D_FORMAT_MASK_BUMP = 0x0F000000,
419 VERTEX4D_FORMAT_BUMP_DOT3 = 0x01000000,
420
421};
422
423const u32 MATERIAL_MAX_COLORS = 1;
424const u32 BURNING_MATERIAL_MAX_TEXTURES = 2;
425const u32 BURNING_MATERIAL_MAX_TANGENT = 1;
426
427// dummy Vertex. used for calculation vertex memory size
428struct s4DVertex_proxy
429{
430 u32 flag;
431 sVec4 Pos;
432 sVec2 Tex[BURNING_MATERIAL_MAX_TEXTURES];
433
434#ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
435 sVec4 Color[MATERIAL_MAX_COLORS];
436#endif
437
438 sVec3 LightTangent[BURNING_MATERIAL_MAX_TANGENT];
439
440};
441
442#define SIZEOF_SVERTEX 64
443#define SIZEOF_SVERTEX_LOG2 6
444
445/*!
446 Internal BurningVideo Vertex
447*/
448struct s4DVertex
449{
450 u32 flag;
451
452 sVec4 Pos;
453 sVec2 Tex[ BURNING_MATERIAL_MAX_TEXTURES ];
454
455#ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
456 sVec4 Color[ MATERIAL_MAX_COLORS ];
457#endif
458
459 sVec3 LightTangent[BURNING_MATERIAL_MAX_TANGENT];
460
461 //u8 fill [ SIZEOF_SVERTEX - sizeof (s4DVertex_proxy) ];
462
463 // f = a * t + b * ( 1 - t )
464 void interpolate(const s4DVertex& b, const s4DVertex& a, const f32 t)
465 {
466 u32 i;
467 u32 size;
468
469 Pos.interpolate ( a.Pos, b.Pos, t );
470
471#ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
472 size = (flag & VERTEX4D_FORMAT_MASK_COLOR) >> 20;
473 for ( i = 0; i!= size; ++i )
474 {
475 Color[i].interpolate ( a.Color[i], b.Color[i], t );
476 }
477#endif
478
479 size = (flag & VERTEX4D_FORMAT_MASK_TEXTURE) >> 16;
480 for ( i = 0; i!= size; ++i )
481 {
482 Tex[i].interpolate ( a.Tex[i], b.Tex[i], t );
483 }
484
485 size = (flag & VERTEX4D_FORMAT_MASK_BUMP) >> 24;
486 for ( i = 0; i!= size; ++i )
487 {
488 LightTangent[i].interpolate ( a.LightTangent[i], b.LightTangent[i], t );
489 }
490
491 }
492};
493
494// ----------------- Vertex Cache ---------------------------
495
496struct SAlignedVertex
497{
498 SAlignedVertex ( u32 element, u32 aligned )
499 : ElementSize ( element )
500 {
501 u32 byteSize = (ElementSize << SIZEOF_SVERTEX_LOG2 ) + aligned;
502 mem = new u8 [ byteSize ];
503 data = (s4DVertex*) mem;
504 }
505
506 virtual ~SAlignedVertex ()
507 {
508 delete [] mem;
509 }
510
511 s4DVertex *data;
512 u8 *mem;
513 u32 ElementSize;
514};
515
516
517// hold info for different Vertex Types
518struct SVSize
519{
520 u32 Format;
521 u32 Pitch;
522 u32 TexSize;
523};
524
525
526// a cache info
527struct SCacheInfo
528{
529 u32 index;
530 u32 hit;
531};
532
533#define VERTEXCACHE_ELEMENT 16
534#define VERTEXCACHE_MISS 0xFFFFFFFF
535struct SVertexCache
536{
537 SVertexCache (): mem ( VERTEXCACHE_ELEMENT * 2, 128 ) {}
538
539 SCacheInfo info[VERTEXCACHE_ELEMENT];
540
541
542 // Transformed and lite, clipping state
543 // + Clipped, Projected
544 SAlignedVertex mem;
545
546 // source
547 const void* vertices;
548 u32 vertexCount;
549
550 const void* indices;
551 u32 indexCount;
552 u32 indicesIndex;
553
554 u32 indicesRun;
555
556 // primitives consist of x vertices
557 u32 primitivePitch;
558
559 u32 vType; //E_VERTEX_TYPE
560 u32 pType; //scene::E_PRIMITIVE_TYPE
561 u32 iType; //E_INDEX_TYPE iType
562
563};
564
565
566// swap 2 pointer
567REALINLINE void swapVertexPointer(const s4DVertex** v1, const s4DVertex** v2)
568{
569 const s4DVertex* b = *v1;
570 *v1 = *v2;
571 *v2 = b;
572}
573
574
575// ------------------------ Internal Scanline Rasterizer -----------------------------
576
577
578
579// internal scan convert
580struct sScanConvertData
581{
582 u8 left; // major edge left/right
583 u8 right; // !left
584
585 f32 invDeltaY[3]; // inverse edge delta y
586
587 f32 x[2]; // x coordinate
588 f32 slopeX[2]; // x slope along edges
589
590#if defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) || defined ( SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT )
591 f32 w[2]; // w coordinate
592 fp24 slopeW[2]; // w slope along edges
593#else
594 f32 z[2]; // z coordinate
595 f32 slopeZ[2]; // z slope along edges
596#endif
597
598 sVec4 c[MATERIAL_MAX_COLORS][2]; // color
599 sVec4 slopeC[MATERIAL_MAX_COLORS][2]; // color slope along edges
600
601 sVec2 t[BURNING_MATERIAL_MAX_TEXTURES][2]; // texture
602 sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES][2]; // texture slope along edges
603
604 sVec3 l[BURNING_MATERIAL_MAX_TANGENT][2]; // Light Tangent
605 sVec3 slopeL[BURNING_MATERIAL_MAX_TEXTURES][2]; // tanget slope along edges
606};
607
608// passed to scan Line
609struct sScanLineData
610{
611 s32 y; // y position of scanline
612 f32 x[2]; // x start, x end of scanline
613
614#if defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) || defined ( SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT )
615 f32 w[2]; // w start, w end of scanline
616#else
617 f32 z[2]; // z start, z end of scanline
618#endif
619
620#ifdef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
621 sVec4 c[MATERIAL_MAX_COLORS][2]; // color start, color end of scanline
622#endif
623
624 sVec2 t[BURNING_MATERIAL_MAX_TEXTURES][2]; // texture start, texture end of scanline
625 sVec3 l[BURNING_MATERIAL_MAX_TANGENT][2]; // Light Tangent start, end
626};
627
628// passed to pixel Shader
629struct sPixelShaderData
630{
631 tVideoSample *dst;
632 fp24 *z;
633
634 s32 xStart;
635 s32 xEnd;
636 s32 dx;
637 s32 i;
638};
639
640/*
641 load a color value
642*/
643inline void getTexel_plain2 ( tFixPoint &r, tFixPoint &g, tFixPoint &b,
644 const sVec4 &v
645 )
646{
647 r = tofix ( v.y );
648 g = tofix ( v.z );
649 b = tofix ( v.w );
650}
651
652/*
653 load a color value
654*/
655inline void getSample_color ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b,
656 const sVec4 &v
657 )
658{
659 a = tofix ( v.x );
660 r = tofix ( v.y, COLOR_MAX * FIX_POINT_F32_MUL);
661 g = tofix ( v.z, COLOR_MAX * FIX_POINT_F32_MUL);
662 b = tofix ( v.w, COLOR_MAX * FIX_POINT_F32_MUL);
663}
664
665/*
666 load a color value
667*/
668inline void getSample_color ( tFixPoint &r, tFixPoint &g, tFixPoint &b,const sVec4 &v )
669{
670 r = tofix ( v.y, COLOR_MAX * FIX_POINT_F32_MUL);
671 g = tofix ( v.z, COLOR_MAX * FIX_POINT_F32_MUL);
672 b = tofix ( v.w, COLOR_MAX * FIX_POINT_F32_MUL);
673}
674
675/*
676 load a color value
677*/
678inline void getSample_color ( tFixPoint &r, tFixPoint &g, tFixPoint &b,
679 const sVec4 &v, const f32 mulby )
680{
681 r = tofix ( v.y, mulby);
682 g = tofix ( v.z, mulby);
683 b = tofix ( v.w, mulby);
684}
685
686
687
688}
689
690}
691
692#endif
693