Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gfxlib_struct.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 #ifndef _GFXLIB_STRUCT
22 #define _GFXLIB_STRUCT
23 #include "gfx/vec.h"
24 #include "endianness.h"
25 
26 #ifndef GFXBOOL
27 #define GFXBOOL unsigned char
28 #endif
29 #define GFXTRUE 1
30 #define GFXFALSE 0
31 
32 const int INDEX_BYTE = sizeof (unsigned char);
33 const int INDEX_SHORT = sizeof (unsigned short);
34 const int INDEX_INT = sizeof (unsigned int);
35 const int CHANGE_MUTABLE = (sizeof (unsigned int)*2);
36 const int CHANGE_CHANGE = (sizeof (unsigned int)*4);
37 const int HAS_COLOR = (sizeof (unsigned int)*8);
38 #define USE_DISPLAY_LISTS
39 const int HAS_INDEX = sizeof (unsigned char)|sizeof (unsigned short)|sizeof (unsigned int);
40 
42 extern int /*GFXDRVAPI*/ GFXCreateList();
44 extern GFXBOOL /*GFXDRVAPI*/ GFXEndList();
46 extern void /*GFXDRVAPI*/ GFXDeleteList( int list );
47 
49 struct GFXVertex
50 {
51  //Texcoord
52  float s;
53  float t;
54 
55  //Normal
56  float i;
57  float j;
58  float k;
59 
60  //Position
61  float x;
62  float y;
63  float z;
64 
65  //Tangent
66  float tx;
67  float ty;
68  float tz;
69  float tw;
70 
71  GFXVertex() {}
72  GFXVertex( const QVector &vert, const Vector &norm, float s, float t )
73  {
74  SetVertex( vert.Cast() );
75  SetNormal( norm );
76  SetTexCoord( s, t );
77  }
78  GFXVertex( const Vector &vert, const Vector &norm, float s, float t )
79  {
80  SetVertex( vert );
81  SetNormal( norm );
82  SetTexCoord( s, t );
83  }
84  GFXVertex( float x, float y, float z, float i, float j, float k, float s, float t )
85  {
86  this->x = x;
87  this->y = y;
88  this->z = z;
89  this->i = i;
90  this->j = j;
91  this->k = k;
92  this->s = s;
93  this->t = t;
94  }
95  GFXVertex& SetTexCoord( float s, float t )
96  {
97  this->s = s;
98  this->t = t;
99  return *this;
100  }
101  GFXVertex& SetNormal( const Vector &norm )
102  {
103  i = norm.i;
104  j = norm.j;
105  k = norm.k;
106  return *this;
107  }
109  {
110  x = vert.i;
111  y = vert.j;
112  z = vert.k;
113  return *this;
114  }
115  GFXVertex& SetTangent( const Vector &tgt, float parity = 1.f )
116  {
117  tx = tgt.x;
118  ty = tgt.y;
119  tz = tgt.z;
120  tw = parity;
121  return *this;
122  }
124  {
125  return Vector( x, y, z );
126  }
127  const Vector& GetConstVertex() const
128  {
129  return *( (Vector*) &x );
130  }
132  {
133  return Vector( i, j, k );
134  }
136  {
137  return Vector( x, y, z );
138  }
140  {
141  return Vector( tx, ty, tz );
142  }
143  float GetTangentParity() const
144  {
145  return tw;
146  }
147 };
148 
149 //Stores a color (or any 4 valued vector)
150 struct GFXColor
151 {
152  float r;
153  float g;
154  float b;
155  float a;
156  GFXColor() {}
157  GFXColor( const Vector &v, float a = 1.0 )
158  {
159  this->r = v.i;
160  this->g = v.j;
161  this->b = v.k;
162  this->a = a;
163  }
164  GFXColor( float r, float g, float b )
165  {
166  this->r = r;
167  this->g = g;
168  this->b = b;
169  this->a = 1.0;
170  }
171 
172  GFXColor( float r, float g, float b, float a )
173  {
174  this->r = r;
175  this->g = g;
176  this->b = b;
177  this->a = a;
178  }
179  void netswap()
180  {
181  this->r = VSSwapHostFloatToLittle( this->r );
182  this->g = VSSwapHostFloatToLittle( this->g );
183  this->b = VSSwapHostFloatToLittle( this->b );
184  this->a = VSSwapHostFloatToLittle( this->a );
185  }
186 
187  GFXColor clamp() const
188  {
189  return GFXColor( ( (r < 0) ? 0 : ( (r > 1) ? 1 : r ) ), ( (g < 0) ? 0 : ( (g > 1) ? 1 : g ) ),
190  ( (b < 0) ? 0 : ( (b > 1) ? 1 : b ) ), ( (a < 0) ? 0 : ( (a > 1) ? 1 : a ) ) );
191  }
192 };
193 
194 inline GFXColor operator*( float s, const GFXColor &c )
195 {
196  return GFXColor( s*c.r, s*c.g, s*c.b, s*c.a );
197 }
198 inline GFXColor operator*( const GFXColor &c, float s )
199 {
200  return GFXColor( s*c.r, s*c.g, s*c.b, s*c.a );
201 }
202 inline GFXColor operator+( const GFXColor &c0, const GFXColor &c1 )
203 {
204  return GFXColor( c0.r+c1.r, c0.g+c1.g, c0.b+c1.b, c0.a+c1.a );
205 }
206 inline GFXColor operator-( const GFXColor &c0, const GFXColor &c1 )
207 {
208  return GFXColor( c0.r-c1.r, c0.g-c1.g, c0.b-c1.b, c0.a-c1.a );
209 }
210 
213 {
214  //Texcoord
215  float s;
216  float t;
217 
218  //Color
219  float r;
220  float g;
221  float b;
222  float a;
223 
224  //Normal
225  float i;
226  float j;
227  float k;
228 
229  //Position
230  float x;
231  float y;
232  float z;
233 
234  //Tangent
235  float tx;
236  float ty;
237  float tz;
238  float tw;
239 
241  GFXColorVertex( const Vector &vert, const Vector &norm, const GFXColor &rgba, float s, float t )
242  {
243  SetVertex( vert );
244  SetNormal( norm );
245  SetColor( rgba );
246  SetTexCoord( s, t );
247  }
248  GFXColorVertex( float x, float y, float z, float i, float j, float k, float r, float g, float b, float a, float s, float t )
249  {
250  this->x = x;
251  this->y = y;
252  this->z = z;
253  this->i = i;
254  this->j = j;
255  this->k = k;
256  this->r = r;
257  this->g = g;
258  this->b = b;
259  this->a = a;
260  this->s = s;
261  this->t = t;
262  }
263  GFXColorVertex& SetTexCoord( float s, float t )
264  {
265  this->s = s;
266  this->t = t;
267  return *this;
268  }
270  {
271  i = norm.i;
272  j = norm.j;
273  k = norm.k;
274  return *this;
275  }
277  {
278  x = vert.i;
279  y = vert.j;
280  z = vert.k;
281  return *this;
282  }
284  {
285  r = col.r;
286  g = col.g;
287  b = col.b;
288  a = col.a;
289  return *this;
290  }
291  GFXColorVertex& SetTangent( const Vector &tgt, float parity = 1.f )
292  {
293  tx = tgt.x;
294  ty = tgt.y;
295  tz = tgt.z;
296  tw = parity;
297  return *this;
298  }
300  {
301  return Vector( i, j, k );
302  }
304  {
305  return Vector( x, y, z );
306  }
307  void SetVtx( const GFXVertex &vv )
308  {
309  s = vv.s;
310  t = vv.t;
311  i = vv.i;
312  j = vv.j;
313  k = vv.k;
314  x = vv.x;
315  y = vv.y;
316  z = vv.z;
317  }
318 
320  {
321  return Vector( tx, ty, tz );
322  }
323  float GetTangentParity() const
324  {
325  return tw;
326  }
327 };
328 
331 {
336  POSITION =16,
338 };
339 
341 class GFXLight
342 {
343 public:
345  int target;
347  float vect[3];
348  int options;
349  float diffuse[4];
350  float specular[4];
351  float ambient[4];
352  float attenuate[3];
353  float direction[3];
354  float exp;
355  float cutoff;
356  float size;
357 
358 public:
360  {
361  //vect[0]=vect[1]=vect[2]=vect[3]=0;
362  vect[0] = vect[1] = vect[2] = 0;
363  attenuate[0] = 1;
364  attenuate[1] = attenuate[2] = 0;
365  diffuse[0] = diffuse[1] = diffuse[2] = 0; //openGL defaults
366  specular[0] = specular[1] = specular[2] = 0; //openGL defaults
367  ambient[0] = ambient[1] = ambient[2] = options = 0;
368  diffuse[3] = specular[3] = ambient[3] = 1;
369  target = -1; //physical GL light its saved in
370 
371  direction[0] = direction[1] = direction[2] = 0.0;
372  exp = 0.0f;
373  cutoff = 180.0f;
374  size = 0.0f;
375  }
376 
377  GFXLight( const bool enabled, const GFXColor &vect,
378  const GFXColor &diffuse = GFXColor( 0, 0, 0, 1 ),
379  const GFXColor &specular = GFXColor( 0, 0, 0, 1 ),
380  const GFXColor &ambient = GFXColor( 0, 0, 0, 1 ),
381  const GFXColor &attenuate = GFXColor( 1, 0, 0 ),
382  const GFXColor &direction = GFXColor( 0, 0, 0 ),
383  float exp = 0.0f,
384  float cutoff = 180.0f,
385  float size = 0.0f );
386 
387  void SetProperties( enum LIGHT_TARGET, const GFXColor &color );
388  GFXColor GetProperties( enum LIGHT_TARGET ) const;
389 
390  void setSize(float size_) { size = size_; }
391  float getSize() const { return size; }
392 
393  Vector getPosition() const { return Vector(vect[0], vect[1], vect[2]); }
394 
395  void disable();
396  void enable();
397  bool attenuated() const;
398  void apply_attenuate( bool attenuated );
399 };
401 struct GFXTVertex //transformed vertex
402 {
403  float x;
404  float y;
405  float z;
407  float rhw;
408  int diffuse;
409  int specular;
410  float s, t;
411  float u, v;
412 };
413 
415 {
417  bool islocal;
418 };
419 
421 {
431 };
432 
434 {
438 };
439 
441 {
445 };
446 
451 class /*GFXDRVAPI*/ GFXQuadList
452 {
454  int numVertices;
456  int numQuads;
458  int *quadassignments;
460  union VCDAT
461  {
462  GFXVertex *vertices;
464  }
465  data;
467  GFXBOOL isColor;
469  int Dirty;
470 public:
472  GFXQuadList( GFXBOOL color = GFXFALSE );
474  ~GFXQuadList();
476  void Draw();
478  int AddQuad( const GFXVertex *vertices, const GFXColorVertex *colors = 0 );
480  void DelQuad( int which );
482  void ModQuad( int which, const GFXVertex *vertices, float alpha = -1 );
483  void ModQuad( int which, const GFXColorVertex *vertices );
484 };
485 
491 class /*GFXDRVAPI*/ GFXVertexList
492 {
493  friend class GFXSphereVertexList;
494 protected:
496  const GFXVertex * GetVertex( int index ) const;
497  const GFXColorVertex * GetColorVertex( int index ) const;
500  union VDAT
501  {
506  VDAT() : vertices(0) {};
507  }
508  data;
509  union INDEX
510  {
511  unsigned char *b; //stride 1
512  unsigned short *s; //stride 2
513  unsigned int *i; //stride 4
514  INDEX() : i(0) {};
515  }
516  index;
518  enum POLYTYPE *mode;
519  bool unique_mode; //See Draw()
521  int display_list; //doubles as vbo_elements
522  int vbo_data;
524  int numlists;
529  int *offsets;
531  char changed;
533  static void VtxCopy( GFXVertexList *thus, GFXVertex *dst, int offset, int howmany );
535  static void ColVtxCopy( GFXVertexList *thus, GFXVertex *dst, int offset, int howmany );
537  static void ColIndVtxCopy( GFXVertexList *thus, GFXVertex *dst, int offset, int howmany );
539  static void IndVtxCopy( GFXVertexList *thus, GFXVertex *dst, int offset, int howmany );
541  void Init( enum POLYTYPE *poly,
542  int numVertices,
543  const GFXVertex *vert,
544  const GFXColorVertex *colors,
545  int numlists,
546  int *offsets,
547  bool Mutable,
548  unsigned int *indices );
550 public:
551  void RefreshDisplayList();
552 protected:
553  virtual void Draw( enum POLYTYPE *poly, const INDEX index, const int numLists, const int *offsets );
554  void RenormalizeNormals();
555  GFXVertexList();
556 public:
558  inline GFXVertexList( enum POLYTYPE poly,
559  int numVertices,
560  const GFXVertex *vertices,
561  int numindices,
562  bool Mutable = false,
563  unsigned int *index = 0 )
564  {
565  Init( &poly, numVertices, vertices, 0, 1, &numindices, Mutable, index );
566  }
568  inline GFXVertexList( enum POLYTYPE *poly,
569  int numVertices,
570  const GFXVertex *vertices,
571  int numlists,
572  int *offsets,
573  bool Mutable = false,
574  unsigned int *index = 0 )
575  {
576  Init( poly, numVertices, vertices, 0, numlists, offsets, Mutable, index );
577  }
579  inline GFXVertexList( enum POLYTYPE poly,
580  int numVertices,
581  const GFXColorVertex *colors,
582  int numindices,
583  bool Mutable = false,
584  unsigned int *index = 0 )
585  {
586  Init( &poly, numVertices, 0, colors, 1, &numindices, Mutable, index );
587  }
589  inline GFXVertexList( enum POLYTYPE *poly,
590  int numVertices,
591  const GFXColorVertex *colors,
592  int numlists,
593  int *offsets,
594  bool Mutable = false,
595  unsigned int *index = 0 )
596  {
597  Init( poly, numVertices, 0, colors, numlists, offsets, Mutable, index );
598  }
599  virtual ~GFXVertexList();
601  virtual int numTris() const;
603  virtual int numQuads() const;
605  unsigned int GetIndex( int offset ) const;
606  POLYTYPE *GetPolyType() const;
607  int *GetOffsets() const;
608  int GetNumLists() const;
609  bool hasColor() const;
610 
611  int GetNumVertices() const
612  {
613  return numVertices;
614  }
615  virtual VDAT * Map( bool read, bool write );
616  void UnMap();
618  virtual VDAT * BeginMutate( int offset );
620  virtual void EndMutate( int newsize = 0 );
622  void LoadDrawState();
624  virtual void BeginDrawState( GFXBOOL lock = GFXTRUE );
626  virtual void Draw();
627  void Draw( enum POLYTYPE poly, int numV );
628  void Draw( enum POLYTYPE poly, int numV, unsigned char *index );
629  void Draw( enum POLYTYPE poly, int numV, unsigned short *index );
630  void Draw( enum POLYTYPE poly, int numV, unsigned int *index );
632  void DrawOnce();
633  virtual void EndDrawState( GFXBOOL lock = GFXTRUE );
635  virtual void GetPolys( GFXVertex **vert, int *numPolys, int *numTris );
636 };
637 
638 class /*GFXDRVAPI*/ GFXSphereVertexList : public GFXVertexList
639 {
641 protected:
642  float radius;
644  virtual void Draw( enum POLYTYPE *poly, const INDEX index, const int numLists, const int *offsets );
645 public:
647  GFXSphereVertexList( float radius, int detail, bool insideout, bool reverse_normals );
649 
651  virtual VDAT * BeginMutate( int offset );
653  virtual void EndMutate( int newsize = 0 );
656  virtual void BeginDrawState( GFXBOOL lock = GFXTRUE );
658  virtual void Draw();
659  virtual void EndDrawState( GFXBOOL lock = GFXTRUE );
661  virtual void GetPolys( GFXVertex **vert, int *numPolys, int *numTris );
663  virtual void ProceduralModification();
664 };
665 
675 {
677  float ar;
678  float ag;
679  float ab;
680  float aa;
682  float dr;
683  float dg;
684  float db;
685  float da;
687  float sr;
688  float sg;
689  float sb;
690  float sa;
692  float er;
693  float eg;
694  float eb;
695  float ea;
697  float power;
698 };
699 //Textures may only be cube maps, Texture1d, Texture2d or Texture3d
701 {
707 };
710 {
721 };
722 
729 {
733 };
734 
736 {
737  DUMMY=0,
739  RGB16 =2,
740  RGBA16 =3,
741  RGB24 =4,
742  RGBA32 =5,
743  RGB32 =6,
744  DXT1 =7,
746  DXT3 =9,
747  DXT5 =10,
749  PNGRGB24 =12,
751 };
757 enum STATE
758 {
768 };
769 
771 {
775 };
776 
781 {
787 };
788 
790 {
795 };
800 {
801  ZERO=1,
802  ONE=2,
816 };
817 
822 enum FILTER
823 {
824  NEAREST =0x0,
825  BILINEAR =0x1,
826  MIPMAP =0x2,
828 };
829 
834 {
836 };
837 
842 {
844 };
845 
847 struct PickData
848 {
849  int name;
850  int zmin;
851  int zmax;
852 
853  PickData( int name, int zmin, int zmax ) : name( name )
854  , zmin( zmin )
855  , zmax( zmax ) {}
856 };
857 
858 #endif
859