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
GFXQuadList Class Reference

#include <gfxlib_struct.h>

Public Member Functions

 GFXQuadList (GFXBOOL color=GFXFALSE)
 Creates an initial Quad List. More...
 
 ~GFXQuadList ()
 Trashes given quad list. More...
 
void Draw ()
 Draws all quads contained in quad list. More...
 
int AddQuad (const GFXVertex *vertices, const GFXColorVertex *colors=0)
 Adds quad to quad list, an integer indicating number that should be used to henceforth Mod it or delete it. More...
 
void DelQuad (int which)
 Removes quad from Quad list. More...
 
void ModQuad (int which, const GFXVertex *vertices, float alpha=-1)
 modifies quad in quad list to contain new vertices and color information More...
 
void ModQuad (int which, const GFXColorVertex *vertices)
 

Detailed Description

Meant to be a huge list of individual quads (like light maps) that need to be resizable, etc all to be drawn at once.... nice on GL :-)

Definition at line 451 of file gfxlib_struct.h.

Constructor & Destructor Documentation

GFXQuadList::GFXQuadList ( GFXBOOL  color = GFXFALSE)

Creates an initial Quad List.

Definition at line 29 of file gl_quad_list.cpp.

References GFXFALSE.

29  : numVertices( 0 )
30  , numQuads( 0 )
31 {
32  data.vertices = NULL;
33  Dirty = GFXFALSE;
34  isColor = color;
35 }
GFXQuadList::~GFXQuadList ( )

Trashes given quad list.

Definition at line 37 of file gl_quad_list.cpp.

38 {
39  if (isColor && data.colors)
40  free( data.colors );
41  else if (!isColor && data.vertices)
42  free( data.vertices );
43 }

Member Function Documentation

int GFXQuadList::AddQuad ( const GFXVertex vertices,
const GFXColorVertex colors = 0 
)

Adds quad to quad list, an integer indicating number that should be used to henceforth Mod it or delete it.

Definition at line 57 of file gl_quad_list.cpp.

References i, VsnetOSS::memcpy(), sizeof(), and VSFileSystem::vs_dprintf().

58 {
59  int cur = numQuads*4;
60  if (cur+3 >= numVertices) {
61  if (!numVertices) {
62  numVertices = 16;
63  if (!isColor)
64  data.vertices = (GFXVertex*) malloc( numVertices*sizeof (GFXVertex) );
65  else
66  data.colors = (GFXColorVertex*) malloc( numVertices*sizeof (GFXColorVertex) );
67  quadassignments = (int*) malloc( numVertices*sizeof (int)/4 );
68  for (int i = 0; i < numVertices/8; i++)
69  quadassignments[i] = -1;
70  } else {
71  numVertices *= 2;
72  if (!isColor)
73  data.vertices = (GFXVertex*) realloc( data.vertices, numVertices*sizeof (GFXVertex) );
74  else
75  data.colors = (GFXColorVertex*) realloc( data.colors, numVertices*sizeof (GFXColorVertex) );
76  quadassignments = (int*) realloc( quadassignments, numVertices*sizeof (int)/4 );
77  }
78  for (int i = numVertices/8; i < numVertices/4; i++)
79  quadassignments[i] = -1;
80  Dirty = numVertices/8;
81  quadassignments[numQuads] = numQuads;
82  numQuads++;
83  if (!isColor && vertices)
84  memcpy( data.vertices+cur, vertices, 4*sizeof (GFXVertex) );
85  if (isColor && color)
86  memcpy( data.colors+cur, color, 4*sizeof (GFXColorVertex) );
87  return numQuads-1;
88  }
89  for (int i = 0; i < numVertices/4; i++)
90  if (quadassignments[i] == -1) {
91  quadassignments[i] = numQuads;
92  if (!isColor && vertices)
93  memcpy( data.vertices+(quadassignments[i]*4), vertices, 4*sizeof (GFXVertex) );
94  if (isColor && color)
95  memcpy( data.colors+(quadassignments[i]*4), color, 4*sizeof (GFXColorVertex) );
96  numQuads++;
97  Dirty--;
98  return i;
99  }
100  VSFileSystem::vs_dprintf( 1, "Fatal Error adding quads" );
101  //should NOT get here!
102  return -1;
103 }
void GFXQuadList::DelQuad ( int  which)

Removes quad from Quad list.

Definition at line 104 of file gl_quad_list.cpp.

References i, VsnetOSS::memcpy(), sizeof(), and VSFileSystem::vs_dprintf().

105 {
106  if (quadassignments[which] >= numQuads) {
107  VSFileSystem::vs_dprintf( 1, "error del" );
108  return;
109  }
110  if (which < 0 || which >= numVertices/4 || quadassignments[which] == -1)
111  return;
112  Dirty++;
113  for (int i = 0; i < numVertices/4; i++)
114  if (quadassignments[i] == numQuads-1) {
115  if (isColor)
116  memcpy( data.colors+(quadassignments[which]*4), data.colors+( (numQuads-1)*4 ), 4*sizeof (GFXColorVertex) );
117  else
118  memcpy( data.vertices+(quadassignments[which]*4), data.vertices+( (numQuads-1)*4 ), 4*sizeof (GFXVertex) );
119  quadassignments[i] = quadassignments[which];
120  quadassignments[which] = -1;
121  numQuads--;
122  return;
123  }
124  VSFileSystem::vs_dprintf( 1, " error deleting engine flame\n" );
125 }
void GFXQuadList::Draw ( )

Draws all quads contained in quad list.

Definition at line 45 of file gl_quad_list.cpp.

46 {
47  if (!numQuads) return;
48  if (isColor)
49  glInterleavedArrays( GL_T2F_C4F_N3F_V3F, sizeof (GFXColorVertex), &data.colors[0] );
50  else
51  glInterleavedArrays( GL_T2F_N3F_V3F, sizeof (GFXVertex), &data.vertices[0] );
52  glDrawArrays( GL_QUADS, 0, numQuads*4 );
53  if (isColor)
54  GFXColor( 1, 1, 1, 1 );
55 }
void GFXQuadList::ModQuad ( int  which,
const GFXVertex vertices,
float  alpha = -1 
)

modifies quad in quad list to contain new vertices and color information

Definition at line 126 of file gl_quad_list.cpp.

References VsnetOSS::memcpy(), and sizeof().

127 {
128  if (which < 0 || which >= numVertices/4 || quadassignments[which] == -1)
129  return;
130  if (isColor) {
131  int w = quadassignments[which]*4;
132 
133  data.colors[w+0].SetVtx( vertices[0] );
134  data.colors[w+1].SetVtx( vertices[1] );
135  data.colors[w+2].SetVtx( vertices[2] );
136  data.colors[w+3].SetVtx( vertices[3] );
137  if (alpha != -1) {
138  if (alpha == 0)
139  alpha = .01;
140  float alp = (data.colors[w].r > data.colors[w].b)
141  ? ( (data.colors[w].r > data.colors[w].g) ? data.colors[w].r : data.colors[w].g )
142  : ( (data.colors[w].b > data.colors[w].g) ? data.colors[w].b : data.colors[w].g );
143  if (alp > .0001) {
144  float tmp[4] =
145  {alpha *data.colors[w+0].r/alp, alpha*data.colors[w+0].g/alp, alpha*data.colors[w+0].b/alp, alpha};
146  memcpy( &data.colors[w+0].r, tmp, sizeof (float)*4 );
147  memcpy( &data.colors[w+1].r, tmp, sizeof (float)*4 );
148  memcpy( &data.colors[w+2].r, tmp, sizeof (float)*4 );
149  memcpy( &data.colors[w+3].r, tmp, sizeof (float)*4 );
150  }
151  }
152  } else {
153  memcpy( data.vertices+(quadassignments[which]*4), vertices, 4*sizeof (GFXVertex) );
154  }
155 }
void GFXQuadList::ModQuad ( int  which,
const GFXColorVertex vertices 
)

Definition at line 157 of file gl_quad_list.cpp.

References i, j, k, VsnetOSS::memcpy(), sizeof(), Vector, x, y, and z.

158 {
159  if (which < 0 || which >= numVertices/4 || quadassignments[which] == -1)
160  return;
161  if (isColor) {
162  memcpy( data.vertices+(quadassignments[which]*4), vertices, 4*sizeof (GFXColorVertex) );
163  } else {
164  data.vertices[(quadassignments[which]*4)+0].SetTexCoord( vertices[0].s,
165  vertices[0].t ).SetNormal( Vector( vertices[0].i,
166  vertices[0].j,
167  vertices[0].k ) ).
168  SetVertex(
169  Vector( vertices[0].x,
170  vertices
171  [
172  0
173  ].y, vertices[0].z ) );
174  data.vertices[(quadassignments[which]*4)+1].SetTexCoord( vertices[1].s,
175  vertices[1].t ).SetNormal( Vector( vertices[1].i,
176  vertices[1].j,
177  vertices[1].k ) ).
178  SetVertex(
179  Vector( vertices[1].x,
180  vertices
181  [
182  1
183  ].y, vertices[1].z ) );
184  data.vertices[(quadassignments[which]*4)+2].SetTexCoord( vertices[2].s,
185  vertices[2].t ).SetNormal( Vector( vertices[2].i,
186  vertices[2].j,
187  vertices[2].k ) ).
188  SetVertex(
189  Vector( vertices[2].x,
190  vertices
191  [
192  2
193  ].y, vertices[2].z ) );
194  data.vertices[(quadassignments[which]*4)+3].SetTexCoord( vertices[3].s,
195  vertices[3].t ).SetNormal( Vector( vertices[3].i,
196  vertices[3].j,
197  vertices[3].k ) ).
198  SetVertex(
199  Vector( vertices[3].x,
200  vertices
201  [
202  3
203  ].y, vertices[3].z ) );
204  }
205 }

The documentation for this class was generated from the following files: