3 #include "gldrv/gl_globals.h"
28 return GL_TRIANGLE_STRIP;
34 return GL_TRIANGLE_FAN;
52 #ifndef NO_VBO_SUPPORT
53 static void BindBuf(
unsigned int vbo_data )
55 (*glBindBufferARB_p)(GL_ARRAY_BUFFER_ARB, vbo_data);
57 static void BindInd(
unsigned int element_data )
59 (*glBindBufferARB_p)(GL_ELEMENT_ARRAY_BUFFER_ARB, element_data);
61 static void clear_gl_error()
65 static void print_gl_error(
const char *fmt)
68 if ((gl_error = glGetError()))
74 #ifndef NO_VBO_SUPPORT
76 if (glGenBuffersARB_p == 0 || glBindBufferARB_p == 0 || glBufferDataARB_p == 0 || glMapBufferARB_p == 0
77 || glUnmapBufferARB_p == 0) {
80 (*glGenBuffersARB_p)(1, (GLuint*) &
vbo_data);
87 (*glBufferDataARB_p)(GL_ARRAY_BUFFER_ARB,
numVertices
98 ?
sizeof (
unsigned short)
99 :
sizeof (
unsigned int) );
100 (*glBufferDataARB_p)(GL_ELEMENT_ARRAY_BUFFER_ARB, tot*indexsize, &
index.
b[0],
114 for (
int i = 0; i <
numlists; i++) {
117 for (a = 0; a <
offsets[i]; a++) {
120 glColor4fv( &vtx.
r );
121 glNormal3fv( &vtx.
i );
122 glVertex3fv( &vtx.
x );
125 for (a = 0; a <
offsets[i]; a++) {
128 glColor4fv( &vtx.
r );
129 glNormal3fv( &vtx.
i );
130 glVertex3fv( &vtx.
x );
137 for (
int i = 0; i <
numlists; i++) {
140 for (a = 0; a <
offsets[i]; a++) {
142 glNormal3fv( &vtx.
i );
144 glVertex3fv( &vtx.
x );
147 for (a = 0; a <
offsets[i]; a++) {
149 glNormal3fv( &vtx.
i );
151 glVertex3fv( &vtx.
x );
169 #ifndef NO_VBO_SUPPORT
174 print_gl_error(
"VBO18.5a Error %d\n");
178 print_gl_error(
"VBO18.5b Error %d\n");
182 if (gl_options.Multitexture)
183 glClientActiveTextureARB_p( GL_TEXTURE0 );
184 glInterleavedArrays( GL_T2F_C4F_N3F_V3F,
sizeof (
GFXColorVertex), 0 );
185 if (gl_options.Multitexture) {
186 glClientActiveTextureARB_p( GL_TEXTURE1 );
189 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
190 glClientActiveTextureARB_p( GL_TEXTURE2 );
193 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
194 glClientActiveTextureARB_p( GL_TEXTURE0 );
197 if (gl_options.Multitexture)
198 glClientActiveTextureARB_p( GL_TEXTURE0 );
199 glInterleavedArrays( GL_T2F_N3F_V3F,
sizeof (
GFXVertex), 0 );
200 if (gl_options.Multitexture) {
201 glClientActiveTextureARB_p( GL_TEXTURE1 );
202 glTexCoordPointer( 2, GL_FLOAT,
sizeof (
GFXVertex),
204 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
205 glClientActiveTextureARB_p( GL_TEXTURE2 );
206 glTexCoordPointer( 4, GL_FLOAT,
sizeof (
GFXVertex),
208 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
209 glClientActiveTextureARB_p( GL_TEXTURE0 );
216 if (gl_options.Multitexture)
217 glClientActiveTextureARB_p( GL_TEXTURE0 );
219 if (gl_options.Multitexture) {
220 glClientActiveTextureARB_p( GL_TEXTURE1 );
222 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
223 glClientActiveTextureARB_p( GL_TEXTURE2 );
225 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
226 glClientActiveTextureARB_p( GL_TEXTURE0 );
229 if (gl_options.Multitexture)
230 glClientActiveTextureARB_p( GL_TEXTURE0 );
232 if (gl_options.Multitexture) {
233 glClientActiveTextureARB_p( GL_TEXTURE1 );
235 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
236 glClientActiveTextureARB_p( GL_TEXTURE2 );
238 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
239 glClientActiveTextureARB_p( GL_TEXTURE0 );
242 #ifndef NO_COMPILEDVERTEXARRAY_SUPPORT
243 if (lock && glLockArraysEXT_p)
248 extern void GFXColor4f(
const float r,
const float g,
const float b,
const float a );
253 #ifndef NO_COMPILEDVERTEXARRAY_SUPPORT
255 (*glUnlockArraysEXT_p)();
268 Draw( &poly, index, 1, &numV );
276 Draw( &poly, tmp, 1, &numV );
285 Draw( &poly, tmp, 1, &numV );
294 Draw( &poly, tmp, 1, &numV );
319 bool blendchange =
false;
328 && gl_options.smooth_points ) || ( (*mode !=
GFXPOINT) && gl_options.smooth_lines ) ) {
349 ++gl_batches_this_frame;
360 use_vbo = use_vbo && memcmp( &index, &this->index,
sizeof (
INDEX) ) == 0;
362 #ifndef NO_VBO_SUPPORT
368 #ifndef NO_VBO_SUPPORT
373 if (glMultiDrawElements_p != NULL && numlists > 1) {
374 static std::vector< bool > drawn;
375 static std::vector< const GLvoid* >glindices;
376 static std::vector< GLsizei >glcounts;
379 drawn.resize( numlists,
false );
380 for (
int i = 0; i <
numlists; totoffset += offsets[i++])
385 for (
int j = i, offs = totoffset;
j <
numlists; offs += offsets[
j++]) {
386 totcount += offsets[
j];
387 if ( !drawn[
j] && (mode[
j] == mode[i]) ) {
388 glindices.push_back( use_vbo ? (GLvoid*) (stride*offs)
389 : (GLvoid*) &index.
b[stride*offs] );
390 glcounts.push_back( offsets[
j] );
394 if (glindices.size() == 1)
395 glDrawElements(
PolyLookup( mode[i] ), glcounts[0], indextype, glindices[0] );
399 mode[i] ), &glcounts[0], indextype, &glindices[0], glindices.size() );
400 ++gl_batches_this_frame;
401 gl_vertices_this_frame += totcount;
404 for (
int i = 0; i <
numlists; i++) {
405 glDrawElements(
PolyLookup( mode[i] ), offsets[i], indextype,
406 use_vbo ? (
void*) (stride*totoffset)
407 : &index.
b[stride*totoffset] );
408 totoffset += offsets[i];
409 ++gl_batches_this_frame;
410 gl_vertices_this_frame += offsets[i];
414 if (glMultiDrawArrays_p) {
415 static std::vector< bool > drawn;
416 static std::vector< GLint > gloffsets;
417 static std::vector< GLsizei >glcounts;
420 drawn.resize( numlists,
false );
421 for (
int i = 0; i <
numlists; totoffset += offsets[i++])
426 for (
int j = i, offs = totoffset;
j <
numlists; offs += offsets[
j++]) {
427 totcount += offsets[
j];
428 if ( !drawn[
j] && (mode[
j] == mode[i]) ) {
429 gloffsets.push_back( offs );
430 glcounts.push_back( offsets[
j] );
434 bool blendchange =
false;
442 && gl_options.smooth_points ) || ( (mode[i] !=
GFXPOINT) && gl_options.smooth_lines ) ) {
456 if (gloffsets.size() == 1)
457 glDrawArrays(
PolyLookup( mode[i] ), gloffsets[0], glcounts[0] );
460 glMultiDrawArrays_p(
PolyLookup( mode[i] ), &gloffsets[0], &glcounts[0], gloffsets.size() );
465 ++gl_batches_this_frame;
466 gl_vertices_this_frame += totcount;
469 for (
int i = 0; i <
numlists; i++) {
470 bool blendchange =
false;
478 && gl_options.smooth_points ) || ( (mode[i] !=
GFXPOINT) && gl_options.smooth_lines ) ) {
492 glDrawArrays(
PolyLookup( mode[i] ), totoffset, offsets[i] );
493 totoffset += offsets[i];
498 ++gl_batches_this_frame;
499 gl_vertices_this_frame += offsets[i];
508 #ifndef NO_VBO_SUPPORT
510 (*glDeleteBuffersARB_p)(1, (GLuint*) &
vbo_data);
531 #ifndef NO_VBO_SUPPORT
532 if (GFX_BUFFER_MAP_UNMAP)
537 (
unsigned char*) (*glMapBufferARB_p)(GL_ELEMENT_ARRAY_BUFFER_ARB,
538 read ? (write ? GL_READ_WRITE_ARB : GL_READ_ONLY_ARB)
539 : GL_WRITE_ONLY_ARB);
543 (*glMapBufferARB_p)(GL_ARRAY_BUFFER_ARB,
544 read ? (write ? GL_READ_WRITE_ARB : GL_READ_ONLY_ARB) : GL_WRITE_ONLY_ARB);
558 #ifndef NO_VBO_SUPPORT
559 if (GFX_BUFFER_MAP_UNMAP)
563 (*glUnmapBufferARB_p)(GL_ELEMENT_ARRAY_BUFFER_ARB);
566 (*glUnmapBufferARB_p)(GL_ARRAY_BUFFER_ARB);
577 return this->
Map(
false,
true );
632 pv->i = pv->i * factor;
633 pv->j = pv->j * factor;
634 pv->k = pv->k * factor;
642 for(
int i=0; i < ROWS; i++) {
647 int direction[ROWS/2];
649 int last_row_set[ROWS];
650 for(
int i=0; i < ROWS; i++) {
655 for(
int j=0;
j < ROWS;
j++)
656 if(row[
j] < numVertices/ROWS*(
j+1))
659 for(
int j=0;
j < ROWS/2;
j++)
662 for(
int j=0;
j < ROWS;
j+=2) {
663 if(direction[
j/2] > 2) {
667 last_row_set[
j] = -1;
674 for(
int j=1;
j < ROWS;
j+=2) {
675 if(direction[(
j-1)/2] > 2) {
679 last_row_set[
j] = -1;
684 for(
int j=0;
j < ROWS;
j++)
685 if(row[
j] < numVertices/ROWS*(
j+1))
688 for(
int j=0; j < ROWS; j++)