1 import "OpenGLDisplayDriver"
13 #if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
15 //# include "gl_core_3_3.h"
16 # include "gl_compat_4_4.h" // FIXME: no glPushAttrib() in core profile
18 # include "gl_compat_4_4.h"
24 #undef glEnableClientState
25 #undef glDisableClientState
26 #undef GL_VERTEX_ARRAY
27 #undef GL_NORMAL_ARRAY
28 #undef GL_TEXTURE_COORD_ARRAY
30 #undef glVertexPointer
31 #undef glTexCoordPointer
34 #define glEnableClientState glEnableVertexAttribArray
35 #define glDisableClientState glDisableVertexAttribArray
36 #define GL_VERTEX_ARRAY GLBufferContents::vertex
37 #define GL_NORMAL_ARRAY GLBufferContents::normal
38 #define GL_TEXTURE_COORD_ARRAY GLBufferContents::texCoord
39 #define GL_COLOR_ARRAY GLBufferContents::color
40 #define glVertexPointer(n, t, s, p) glVertexAttribPointer(GLBufferContents::vertex, n, t, GL_FALSE, s, p)
41 #define glTexCoordPointer(n, t, s, p) glVertexAttribPointer(GLBufferContents::texCoord, n, t, GL_FALSE, s, p)
42 #define glColorPointer(n, t, s, p) glVertexAttribPointer(GLBufferContents::color, n, t, GL_FALSE, s, p)
46 #if defined(ES1_1) || defined(ES2) || defined(SHADERS)
82 #undef glColorMaterial
85 #define glRecti glimtkRecti
86 #define glBegin glimtkBegin
87 #define glTexCoord2i glimtkTexCoord2i
88 #define glVertex2i glimtkVertex2i
89 #define glTexCoord2d glimtkTexCoord2d
90 #define glVertex2d glimtkVertex2d
91 #define glTexCoord2f glimtkTexCoord2f
92 #define glVertex2f glimtkVertex2f
93 #define glEnd glimtkEnd
94 #define glColor3f glimtkColor3f
95 #define glColor4ub glimtkColor4ub
96 #define glColor4fv glimtkColor4fv
97 #define glNormal3fv glimtkNormal3fv
98 #define glNormal3f glimtkNormal3f
99 #define glTexCoord2fv glimtkTexCoord2fv
100 #define glVertex3d glimtkVertex3d
101 #define glVertex3dv glimtkVertex3dv
102 #define glVertex3f glimtkVertex3f
103 #define glVertex3fv glimtkVertex3fv
105 #define glLoadMatrixd glmsLoadMatrixd
106 #define glMultMatrixd glmsMultMatrixd
107 #define glFrustum glmsFrustum
108 #define glOrtho glmsOrtho
109 #define glScaled glmsScaled
110 #define glScalef glmsScaled
111 #define glTranslated glmsTranslated
112 #define glRotated glmsRotated
113 #define glMatrixMode glmsMatrixMode
114 #define glLoadIdentity glmsLoadIdentity
115 #define glPushMatrix glmsPushMatrix
116 #define glPopMatrix glmsPopMatrix
118 #define glLineStipple glesLineStipple
119 #define glColorMaterial glesColorMaterial
120 #define glLightModeli glesLightModeli
126 #define OFFSET(s, m) ((uint)(uintptr) (&((s *) 0)->m))
128 import "textureManager"
131 #define DM_ENABLE_IMAGE_ROTATION (1)
132 #define DM_ENABLE_EXT_COLOR (1)
136 static struct DMDrawVertexFlat
141 #if DM_ENABLE_EXT_COLOR
144 } __attribute__((aligned(16)));
146 static struct DMDrawVertex
151 #if DM_ENABLE_EXT_COLOR
154 } __attribute__((aligned(16)));
165 class DMProgramFlags : uint { bool valid:1; }
171 GLuint fragmentShader;
177 #if DM_ENABLE_EXT_COLOR
181 DMProgramFlags flags;
182 int64 lastUpdateCount;
185 class DMImageFlags : uint16
187 bool empty:1; // Image is empty, do not draw
188 bool blending:1; // Must draw image with blending
191 public struct DMImage
200 // Computed order for sorted rendering, in defineImage()
206 this = { flags = { empty = true } };
209 void defineImage( Texture texture, int offsetx, int offsety, int sizex, int sizey, bool blending, int programIndex, int layerindex )
211 int ordx = offsetx >> 6;
212 int ordy = offsety >> 6;
213 uint32 orderimage = ccMortonNumber32( ordx, ordy ) & ( ( 1 << DM_IMAGE_ORDER_BITS ) - 1 );
217 srcx = (short)offsetx;
218 srcy = (short)offsety;
219 sizex = (short)sizex;
220 sizey = (short)sizey;
221 programIndex = (short)programIndex;
222 flags = { blending = blending };
223 orderMask = (orderimage << DM_IMAGE_ORDER_SHIFT) |
224 (( blending == true ) << DM_BLEND_ORDER_SHIFT) |
225 (programIndex << DM_PROGRAM_ORDER_SHIFT) |
227 (layerindex << DM_LAYER_ORDER_SHIFT);
239 #if DM_ENABLE_IMAGE_ROTATION
243 #if DM_ENABLE_EXT_COLOR
254 define DM_IMAGE_ORDER_BITS = 8;
255 define DM_BLEND_ORDER_BITS = 1;
256 define DM_PROGRAM_ORDER_BITS = 4;
257 define DM_TEXTURE_ORDER_BITS = 10;
258 define DM_LAYER_ORDER_BITS = 4;
259 define DM_BARRIER_ORDER_BITS = 5;
261 define DM_IMAGE_ORDER_SHIFT = 0;
262 define DM_BLEND_ORDER_SHIFT = DM_IMAGE_ORDER_BITS;
263 define DM_PROGRAM_ORDER_SHIFT = DM_IMAGE_ORDER_BITS+DM_BLEND_ORDER_BITS;
264 define DM_TEXTURE_ORDER_SHIFT = DM_IMAGE_ORDER_BITS+DM_BLEND_ORDER_BITS+DM_PROGRAM_ORDER_BITS;
265 define DM_LAYER_ORDER_SHIFT = DM_IMAGE_ORDER_BITS+DM_BLEND_ORDER_BITS+DM_PROGRAM_ORDER_BITS+DM_TEXTURE_ORDER_BITS;
266 define DM_BARRIER_ORDER_SHIFT = DM_IMAGE_ORDER_BITS+DM_BLEND_ORDER_BITS+DM_PROGRAM_ORDER_BITS+DM_TEXTURE_ORDER_BITS+DM_LAYER_ORDER_BITS;
268 define DM_LAYER_COUNT = 1<<DM_LAYER_ORDER_BITS;
269 define DM_PROGRAM_COUNT = 1<<DM_PROGRAM_ORDER_BITS;
271 define DM_CONTEXT_DRAW_BUFFER_COUNT = 64;
272 define DM_CONTEXT_DRAW_BUFFER_VERTEX_ALLOC = 1024;
275 /* Range is from zero to DM_LAYER_COUNT */
296 define DM_LAYER_BOTTOM = DMLayer::DM_LAYER_0_BOTTOM;
297 define DM_LAYER_BELOW = DMLayer::DM_LAYER_3_BELOW;
298 define DM_LAYER_NORMAL = DMLayer::DM_LAYER_6_NORMAL;
299 define DM_LAYER_ABOVE = DMLayer::DM_LAYER_9_ABOVE;
300 define DM_LAYER_TOP = DMLayer::DM_LAYER_15_TOP;
302 define DM_PROGRAM_NORMAL = 0;
303 define DM_PROGRAM_ALPHABLEND = 1;
304 define DM_PROGRAM_ALPHABLEND_INTENSITY = 2;
305 define DM_PROGRAM_ALPHABLEND_INTENSITY_EXTCOLOR = 3;
308 static inline void OpenGLErrorCheck( const char *file, int line )
310 int error = glGetError();
311 if( error != GL_NO_ERROR )
312 printf( "ERROR %d at %s:%d\n", error, file, line );
315 #define ERRORCHECK() OpenGLErrorCheck(__FILE__,__LINE__)
320 #define DM_IMAGE_ROTATION_NORMFACTOR (32767.0f)
322 #define DM_VERTEX_NORMSHIFT (2)
323 #define DM_VERTEX_NORMFACTOR (4.0f)
325 #define DM_TEXCOORD_NORMSHIFT (13)
326 #define DM_TEXCOORD_NORMFACTOR (8192.0f)
328 static GLuint dmCreateShader( GLenum type, const char *shadersource, const char *optionstring )
334 const GLchar *sourcearray[2];
336 shader = glCreateShader( type );
340 if( !( optionstring ) )
342 sourcearray[0] = optionstring;
343 sourcearray[1] = shadersource;
344 glShaderSource( shader, 2, sourcearray, NULL );
345 glCompileShader( shader );
346 glGetShaderiv( shader, GL_COMPILE_STATUS, &status );
347 if( status != GL_TRUE )
349 fprintf( stderr, "ERROR: Failed to compile shader\n" );
350 glGetShaderInfoLog( shader, 8192, &loglength,infolog );
351 fprintf( stderr, "ERROR: \n%s\n\n", infolog );
352 glDeleteShader( shader );
359 static bool dmCreateProgram( DMProgram program, const char *vertexsource, const char *fragmentsource, char *optionstring )
365 program.glProgram = 0;
366 program.vertexShader = 0;
367 program.fragmentShader = 0;
369 program.vertexShader = dmCreateShader( GL_VERTEX_SHADER, vertexsource, optionstring );
370 if( !( program.vertexShader ) )
372 fprintf(stderr, "ERROR: Unable to load vertex shader\n");
375 program.fragmentShader = dmCreateShader( GL_FRAGMENT_SHADER, fragmentsource, optionstring );
376 if( !( program.fragmentShader ) )
378 fprintf(stderr, "ERROR: Unable to load fragment shader\n");
381 program.glProgram = glCreateProgram();
382 if( !( program.glProgram ) )
384 fprintf(stderr, "ERROR: Unable to create program\n");
388 glAttachShader( program.glProgram, program.vertexShader );
389 glAttachShader( program.glProgram, program.fragmentShader );
391 glBindAttribLocation(program.glProgram, GLBufferContents::vertex, "vertex");
392 glBindAttribLocation(program.glProgram, GLBufferContents::texCoord, "texCoord");
393 glBindAttribLocation(program.glProgram, GLBufferContents::color, "color");
394 glBindAttribLocation(program.glProgram, GLBufferContents::normal, "normal");
396 glLinkProgram( program.glProgram );
397 glGetProgramiv( program.glProgram, GL_LINK_STATUS, &status );
398 if( status != GL_TRUE )
400 fprintf( stderr, "ERROR, failed to link shader program\n" );
401 glGetProgramInfoLog( program.glProgram, 8192, &loglength, infolog );
402 fprintf( stderr, "ERROR: \n%s\n\n", infolog );
406 // glUseProgram( program.glProgram );
408 program.matrixloc = glGetUniformLocation( program.glProgram, "uniMatrix" );
409 program.vertexloc = glGetAttribLocation( program.glProgram, "inVertex" );
410 program.texcoord0loc = glGetAttribLocation( program.glProgram, "inTexcoord0" );
411 program.texcoord1loc = glGetAttribLocation( program.glProgram, "inTexcoord1" );
412 program.colorloc = glGetAttribLocation( program.glProgram, "inColor" );
413 #if DM_ENABLE_EXT_COLOR
414 program.extcolorloc = glGetAttribLocation( program.glProgram, "inExtColor" );
416 program.texbaseloc = glGetUniformLocation( program.glProgram, "texBase" );
417 program.flags.valid = true;
422 if( program.fragmentShader )
423 glDeleteShader( program.fragmentShader );
424 if( program.vertexShader )
425 glDeleteShader( program.vertexShader );
426 if( program.glProgram )
427 glDeleteProgram( program.glProgram );
435 const char *dmVertexShaderNormal =
437 "uniform mat4 uniMatrix;\n"
438 "in vec2 inVertex;\n"
439 "in vec2 inTexcoord0;\n"
441 "out vec2 varTexcoord0;\n"
442 "out vec4 varColor;\n"
446 " varTexcoord0 = inTexcoord0 * (1.0/" CC_STRINGIFY(DM_TEXCOORD_NORMFACTOR) ");\n"
447 " varColor = inColor;\n"
448 " gl_Position = uniMatrix * vec4( inVertex, 0.0, 1.0 );\n"
454 const char *dmFragmentShaderNormal =
456 "uniform sampler2D texBase;\n"
457 "in vec2 varTexcoord0;\n"
458 "in vec4 varColor;\n"
461 " gl_FragColor = varColor * texture2D( texBase, varTexcoord0 );\n"
467 const char *dmVertexShaderAlpha =
469 "uniform mat4 uniMatrix;\n"
470 "in vec2 inVertex;\n"
471 "in vec2 inTexcoord0;\n"
473 "out vec2 varTexcoord0;\n"
474 "out vec4 varColor;\n"
478 " varTexcoord0 = inTexcoord0 * (1.0/" CC_STRINGIFY(DM_TEXCOORD_NORMFACTOR) ");\n"
479 " varColor = inColor;\n"
480 " gl_Position = uniMatrix * vec4( inVertex, 0.0, 1.0 );\n"
486 const char *dmFragmentShaderAlpha =
488 "uniform sampler2D texBase;\n"
489 "in vec2 varTexcoord0;\n"
490 "in vec4 varColor;\n"
493 " gl_FragColor = vec4( varColor.rgb, varColor.a * texture2D( texBase, varTexcoord0 ).r );\n"
498 const char *dmVertexShaderAlphaIntensity =
500 "uniform mat4 uniMatrix;\n"
501 "in vec2 inVertex;\n"
502 "in vec2 inTexcoord0;\n"
504 "out vec2 varTexcoord0;\n"
505 "out vec4 varColor;\n"
509 " varTexcoord0 = inTexcoord0 * (1.0/" CC_STRINGIFY(DM_TEXCOORD_NORMFACTOR) ");\n"
510 " varColor = inColor;\n"
511 " gl_Position = uniMatrix * vec4( inVertex, 0.0, 1.0 );\n"
517 const char *dmFragmentShaderAlphaIntensity =
519 "uniform sampler2D texBase;\n"
520 "in vec2 varTexcoord0;\n"
521 "in vec4 varColor;\n"
525 " tex = texture2D( texBase, varTexcoord0 ).rg;\n"
526 " gl_FragColor = vec4( varColor.rgb * tex.g, varColor.a * tex.r );\n"
531 const char *dmVertexShaderAlphaIntensityExtColor =
533 "uniform mat4 uniMatrix;\n"
534 "in vec2 inVertex;\n"
535 "in vec2 inTexcoord0;\n"
537 "in vec4 inExtColor;\n"
538 "out vec2 varTexcoord0;\n"
539 "out vec4 varColor;\n"
540 "out vec4 varExtColor;\n"
544 " varTexcoord0 = inTexcoord0 * (1.0/" CC_STRINGIFY(DM_TEXCOORD_NORMFACTOR) ");\n"
545 " varColor = inColor;\n"
546 " varExtColor = inExtColor;\n"
547 " gl_Position = uniMatrix * vec4( inVertex, 0.0, 1.0 );\n"
553 const char *dmFragmentShaderAlphaIntensityExtColor =
555 "uniform sampler2D texBase;\n"
556 "in vec2 varTexcoord0;\n"
557 "in vec4 varColor;\n"
558 "in vec4 varExtColor;\n"
562 " tex = texture2D( texBase, varTexcoord0 ).rg;\n"
563 " gl_FragColor = vec4( mix( varExtColor.rgb, varColor.rgb, tex.g ), mix( varExtColor.a, varColor.a, tex.g ) * tex.r );\n"
571 static void matrixOrtho( float *m, float left, float right, float bottom, float top, float nearval, float farval )
573 float x = 2.0f / ( right - left );
574 float y = 2.0f / ( top - bottom );
575 float z = -2.0f / ( farval - nearval );
576 float tx = -( right + left ) / ( right - left );
577 float ty = -( top + bottom ) / ( top - bottom );
578 float tz = -( farval + nearval ) / ( farval - nearval );
580 #define M(row,col) m[col*4+row]
581 M(0,0) = x; M(0,1) = 0.0; M(0,2) = 0.0; M(0,3) = tx;
582 M(1,0) = 0.0; M(1,1) = y; M(1,2) = 0.0; M(1,3) = ty;
583 M(2,0) = 0.0; M(2,1) = 0.0; M(2,2) = z; M(2,3) = tz;
584 M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
591 /* FIXME: Radix sort, not hybrid sort! */
593 static inline int dmSortImagesCmp( DMImageBuffer *draw0, DMImageBuffer *draw1 )
595 return ( ( draw0->orderindex < draw1->orderindex ) ? 0 : 1 );
598 #define HSORT_MAIN dmSortImages
599 #define HSORT_CMP dmSortImagesCmp
600 #define HSORT_TYPE DMImageBuffer
601 #include "cchybridsort.h"
609 // TOFIX: Make this private, have a property
610 public class DrawManagerFlags : uint32 { public: bool prehistoricOpenGL:1; }
612 public class DrawManager
614 DrawManagerFlags flags;
615 DMProgram shaderPrograms[DM_PROGRAM_COUNT];
620 int imageBufferCount;
622 DMImageBuffer *imageBuffer;
623 DMImageBuffer *imageBufferTmp;
625 // Buffers for drawimages() batching
626 DMDrawBuffer drawBuffer[DM_CONTEXT_DRAW_BUFFER_COUNT];
628 int drawBarrierIndex;
629 uint32 orderBarrierMask;
631 // Counter to track program uniforms and such
636 static DMProgram *flushUseProgram( int programIndex )
638 DMProgram *program = &shaderPrograms[ programIndex ];
639 if( !program->flags.valid)
645 glUseProgram( program->glProgram );
646 if( program->lastUpdateCount != this.updateCount )
648 glUniformMatrix4fv( program->matrixloc, 1, GL_FALSE, this.matrix );
649 glUniform1i( program->texbaseloc, 0 );
650 program->lastUpdateCount = this.updateCount;
656 static void flushRenderDrawBufferArchaic( DMDrawBuffer drawBuffer, DMProgram program, int vertexCount )
658 glEnable( GL_TEXTURE_2D );
659 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer.vbo );
660 glColor3f( 1.0, 1.0, 1.0 );
662 glEnableClientState( GL_VERTEX_ARRAY );
663 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
664 glEnableClientState( GL_COLOR_ARRAY );
666 glVertexPointer( 2, GL_FLOAT, sizeof(DMDrawVertexFlat), (void *)OFFSET(DMDrawVertexFlat,vertex) );
667 glTexCoordPointer( 2, GL_FLOAT, sizeof(DMDrawVertexFlat), (void *)OFFSET(DMDrawVertexFlat,texcoord0) );
668 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(DMDrawVertexFlat), (void *)OFFSET(DMDrawVertexFlat,color) );
670 glDrawArrays( GL_TRIANGLES, 0, vertexCount );
672 glDisableClientState( GL_VERTEX_ARRAY );
673 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
674 glDisableClientState( GL_COLOR_ARRAY );
675 glDisable( GL_TEXTURE_2D );
677 #if DM_FLUSH_EACH_RENDER_DRAW_BUFFER
682 void flushDrawImagesArchaic( )
684 bool flushflag, stateBlend;
685 int index, vertexCount, programIndex;
686 float vx0, vx1, vx2, vx3, vy0, vy1, vy2, vy3;
687 #if DM_ENABLE_IMAGE_ROTATION
688 float angsin, angcos, sizex, sizey;
690 float tx0, tx1, ty0, ty1;
691 DMImageBuffer *imageBuffer;
692 DMImage *image, *bindimage;
693 Texture texture, bindTexture;
694 DMDrawBuffer *drawBuffer;
695 DMDrawVertexFlat *vboVertex;
700 drawBarrierIndex = 0;
701 orderBarrierMask = drawBarrierIndex << DM_BARRIER_ORDER_SHIFT;
704 // Sort by image type and texture, minimize state changes
705 dmSortImages( this.imageBuffer, imageBufferTmp, imageBufferCount, (uint32)( (intptr_t)this.imageBuffer >> 4 ) );
707 // Fill a drawBuffer, write vertex and texcoords
708 drawBuffer = &this.drawBuffer[drawBufferIndex];
709 drawBufferIndex = ( drawBufferIndex + 1 ) % DM_CONTEXT_DRAW_BUFFER_COUNT;
710 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
711 vboVertex = glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
714 glActiveTexture( GL_TEXTURE0 );
715 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
716 glDisable( GL_BLEND );
718 #if DM_RENDER_IMAGE_DEBUG
719 printf( " Flush %d images\n", (int)imageBufferCount );
727 imageBuffer = this.imageBuffer;
728 for( index = 0 ; index < imageBufferCount ; index++, imageBuffer++ )
730 image = imageBuffer->image;
731 texture = image->texture;
734 if( image != bindimage )
736 if( stateBlend != image->flags.blending )
738 if( texture != bindTexture )
741 if( vertexCount >= ( drawBuffer->vertexAlloc - 6 ) )
748 glUnmapBuffer( GL_ARRAY_BUFFER );
749 // Flush font manager texture updates
751 // Render buffered images
752 flushRenderDrawBufferArchaic( drawBuffer, program, vertexCount );
753 drawBuffer = &this.drawBuffer[drawBufferIndex];
754 drawBufferIndex = ( drawBufferIndex + 1 ) % DM_CONTEXT_DRAW_BUFFER_COUNT;
755 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
756 vboVertex = glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
760 if( stateBlend != ( image->flags.blending ) )
762 stateBlend = image->flags.blending;
763 ( stateBlend ? glEnable : glDisable )( GL_BLEND );
764 #if DM_RENDER_IMAGE_DEBUG
765 printf( " Switch blending %d\n", stateBlend != false );
768 if( programIndex != image->programIndex )
770 programIndex = image->programIndex;
771 program = flushUseProgram( programIndex );
773 if( texture != bindTexture )
775 bindTexture = texture;
776 glBindTexture( GL_TEXTURE_2D, bindTexture.glTex );
777 #if DM_RENDER_IMAGE_DEBUG
778 printf( " Switch to texture 0x%x\n", (int)texture.orderMask );
784 #if DM_RENDER_IMAGE_DEBUG
785 printf( " Render image at %d %d, order 0x%x, texture %p\n", (int)imageBuffer->offsetx, (int)imageBuffer->offsety, (int)imageBuffer->orderindex, texture );
788 #if DM_ENABLE_IMAGE_ROTATION
789 angsin = (float)imageBuffer->angsin * (1.0f/DM_IMAGE_ROTATION_NORMFACTOR);
790 angcos = (float)imageBuffer->angcos * (1.0f/DM_IMAGE_ROTATION_NORMFACTOR);
791 sizex = (float)imageBuffer->sizex;
792 sizey = (float)imageBuffer->sizey;
793 vx0 = (float)imageBuffer->offsetx * (1.0f/DM_VERTEX_NORMFACTOR);
794 vy0 = (float)imageBuffer->offsety * (1.0f/DM_VERTEX_NORMFACTOR);
795 vx1 = vx0 + ( angcos * sizex );
796 vy1 = vy0 + ( angsin * sizex );
797 vx2 = vx0 - ( angsin * sizey );
798 vy2 = vy0 + ( angcos * sizey );
799 vx3 = vx0 + ( angcos * sizex ) - ( angsin * sizey );
800 vy3 = vy0 + ( angsin * sizex ) + ( angcos * sizey );
802 vx0 = (float)imageBuffer->offsetx * (1.0f/DM_VERTEX_NORMFACTOR);
803 vy0 = (float)imageBuffer->offsety * (1.0f/DM_VERTEX_NORMFACTOR);
804 vx3 = vx0 + (float)( imageBuffer->sizex );
805 vy3 = vy0 + (float)( imageBuffer->sizey );
812 tx0 = (float)( image->srcx ) * texture.widthinv;
813 ty0 = (float)( image->srcy ) * texture.heightinv;
814 tx1 = (float)( image->srcx + image->sizex ) * texture.widthinv;
815 ty1 = (float)( image->srcy + image->sizey ) * texture.heightinv;
818 vboVertex[0].vertex[0] = vx3;
819 vboVertex[0].vertex[1] = vy3;
820 vboVertex[0].texcoord0[0] = tx1;
821 vboVertex[0].texcoord0[1] = ty1;
822 vboVertex[0].color = imageBuffer->color;
823 #if DM_ENABLE_EXT_COLOR
824 vboVertex[0].extcolor = imageBuffer->extcolor;
826 vboVertex[1].vertex[0] = vx1;
827 vboVertex[1].vertex[1] = vy1;
828 vboVertex[1].texcoord0[0] = tx1;
829 vboVertex[1].texcoord0[1] = ty0;
830 vboVertex[1].color = imageBuffer->color;
831 #if DM_ENABLE_EXT_COLOR
832 vboVertex[1].extcolor = imageBuffer->extcolor;
834 vboVertex[2].vertex[0] = vx2;
835 vboVertex[2].vertex[1] = vy2;
836 vboVertex[2].texcoord0[0] = tx0;
837 vboVertex[2].texcoord0[1] = ty1;
838 vboVertex[2].color = imageBuffer->color;
839 #if DM_ENABLE_EXT_COLOR
840 vboVertex[2].extcolor = imageBuffer->extcolor;
842 vboVertex[3].vertex[0] = vx0;
843 vboVertex[3].vertex[1] = vy0;
844 vboVertex[3].texcoord0[0] = tx0;
845 vboVertex[3].texcoord0[1] = ty0;
846 vboVertex[3].color = imageBuffer->color;
847 #if DM_ENABLE_EXT_COLOR
848 vboVertex[3].extcolor = imageBuffer->extcolor;
850 vboVertex[4].vertex[0] = vx2;
851 vboVertex[4].vertex[1] = vy2;
852 vboVertex[4].texcoord0[0] = tx0;
853 vboVertex[4].texcoord0[1] = ty1;
854 vboVertex[4].color = imageBuffer->color;
855 #if DM_ENABLE_EXT_COLOR
856 vboVertex[4].extcolor = imageBuffer->extcolor;
858 vboVertex[5].vertex[0] = vx1;
859 vboVertex[5].vertex[1] = vy1;
860 vboVertex[5].texcoord0[0] = tx1;
861 vboVertex[5].texcoord0[1] = ty0;
862 vboVertex[5].color = imageBuffer->color;
863 #if DM_ENABLE_EXT_COLOR
864 vboVertex[5].extcolor = imageBuffer->extcolor;
871 glUnmapBuffer( GL_ARRAY_BUFFER );
873 // Flush font manager texture updates
876 // Render buffered images
877 flushRenderDrawBufferArchaic( drawBuffer, program, vertexCount );
878 imageBufferCount = 0;
885 void flushRenderDrawBuffer( DMDrawBuffer drawBuffer, DMProgram program, int vertexCount )
887 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer.vbo );
888 if( program.vertexloc != -1 )
890 glEnableVertexAttribArray( program.vertexloc );
891 glVertexAttribPointer( program.vertexloc, 2, GL_SHORT, GL_FALSE, sizeof(DMDrawVertex), (void *)OFFSET(DMDrawVertex,vertex) );
893 if( program.texcoord0loc != -1 )
895 glEnableVertexAttribArray( program.texcoord0loc );
896 glVertexAttribPointer( program.texcoord0loc, 2, GL_SHORT, GL_FALSE, sizeof(DMDrawVertex), (void *)OFFSET(DMDrawVertex,texcoord0) );
898 if( program.colorloc != -1 )
900 glEnableVertexAttribArray( program.colorloc );
901 glVertexAttribPointer( program.colorloc, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(DMDrawVertex), (void *)OFFSET(DMDrawVertex,color) );
904 #if DM_ENABLE_EXT_COLOR
905 if( program.extcolorloc != -1 )
907 glEnableVertexAttribArray( program.extcolorloc );
908 glVertexAttribPointer( program.extcolorloc, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(DMDrawVertex), (void *)OFFSET(DMDrawVertex,extcolor) );
912 glDrawArrays( GL_TRIANGLES, 0, vertexCount );
914 if( program.vertexloc != -1 )
915 glDisableVertexAttribArray( program.vertexloc );
916 if( program.texcoord0loc != -1 )
917 glDisableVertexAttribArray( program.texcoord0loc );
918 if( program.colorloc != -1 )
919 glDisableVertexAttribArray( program.colorloc );
921 #if DM_FLUSH_EACH_RENDER_DRAW_BUFFER
926 void flushDrawImages( )
928 int index, stateblend, vertexcount, flushflag, programIndex;
929 float vx0, vx1, vx2, vx3, vy0, vy1, vy2, vy3;
930 #if DM_ENABLE_IMAGE_ROTATION
931 float angsin, angcos, sizex, sizey;
933 float tx0, tx1, ty0, ty1;
934 DMImageBuffer *imageBuffer;
935 DMImage *image, *bindimage;
936 Texture texture, bindtexture;
937 DMDrawBuffer *drawBuffer;
938 DMDrawVertex *vboVertex;
943 this.drawBarrierIndex = 0;
944 orderBarrierMask = drawBarrierIndex << DM_BARRIER_ORDER_SHIFT;
945 if( imageBufferCount )
947 /* Sort by image type and texture, minimize state changes */
948 dmSortImages( this.imageBuffer, this.imageBufferTmp, imageBufferCount, (uint32)( (uintptr)this.imageBuffer >> 4 ) );
950 /* Fill a drawBuffer, write vertex and texcoords */
951 drawBuffer = &this.drawBuffer[this.drawBufferIndex];
952 this.drawBufferIndex = ( this.drawBufferIndex + 1 ) % DM_CONTEXT_DRAW_BUFFER_COUNT;
953 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
954 vboVertex = glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
957 glActiveTexture( GL_TEXTURE0 );
958 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
959 glDisable( GL_BLEND );
961 #if DM_RENDER_IMAGE_DEBUG
962 printf( " Flush %d images\n", (int)imageBufferCount );
970 imageBuffer = this.imageBuffer;
971 for( index = 0 ; index < imageBufferCount ; index++, imageBuffer++ )
973 image = imageBuffer->image;
974 texture = image->texture;
977 if( image != bindimage )
979 if( stateblend != ( image->flags.blending ) )
981 if( texture != bindtexture )
984 if( vertexcount >= ( drawBuffer->vertexAlloc - 6 ) )
991 glUnmapBuffer( GL_ARRAY_BUFFER );
992 // Flush font manager texture updates
995 // Render buffered images
996 flushRenderDrawBuffer( drawBuffer, program, vertexcount );
997 drawBuffer = &this.drawBuffer[this.drawBufferIndex];
998 this.drawBufferIndex = ( this.drawBufferIndex + 1 ) % DM_CONTEXT_DRAW_BUFFER_COUNT;
999 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
1000 vboVertex = glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
1004 if( stateblend != ( image->flags.blending ) )
1006 stateblend = image->flags.blending;
1007 ( stateblend ? glEnable : glDisable )( GL_BLEND );
1008 #if DM_RENDER_IMAGE_DEBUG
1009 printf( " Switch blending %d\n", ( stateblend != 0 ) );
1012 if( programIndex != image->programIndex )
1014 programIndex = image->programIndex;
1015 program = flushUseProgram( programIndex );
1017 if( texture != bindtexture )
1019 bindtexture = texture;
1020 glBindTexture( GL_TEXTURE_2D, bindtexture.glTex );
1021 #if DM_RENDER_IMAGE_DEBUG
1022 printf( " Switch to texture 0x%x\n", (int)texture.orderMask );
1028 #if DM_RENDER_IMAGE_DEBUG
1029 printf( " Render image at %d %d, order 0x%x, texture %p\n", (int)imageBuffer->offsetx, (int)imageBuffer->offsety, (int)imageBuffer->orderindex, texture );
1032 #if DM_ENABLE_IMAGE_ROTATION
1033 /* FIXME TODO: Don't go through float, compute texcoord integers directly */
1034 angsin = (float)imageBuffer->angsin * (1.0f/DM_IMAGE_ROTATION_NORMFACTOR);
1035 angcos = (float)imageBuffer->angcos * (1.0f/DM_IMAGE_ROTATION_NORMFACTOR);
1036 sizex = (float)imageBuffer->sizex;
1037 sizey = (float)imageBuffer->sizey;
1038 vx0 = (float)imageBuffer->offsetx * (1.0f/DM_VERTEX_NORMFACTOR);
1039 vy0 = (float)imageBuffer->offsety * (1.0f/DM_VERTEX_NORMFACTOR);
1040 vx1 = vx0 + ( angcos * sizex );
1041 vy1 = vy0 + ( angsin * sizex );
1042 vx2 = vx0 - ( angsin * sizey );
1043 vy2 = vy0 + ( angcos * sizey );
1044 vx3 = vx0 + ( angcos * sizex ) - ( angsin * sizey );
1045 vy3 = vy0 + ( angsin * sizex ) + ( angcos * sizey );
1047 /* FIXME TODO: Don't go through float, compute texcoord integers directly */
1048 vx0 = (float)imageBuffer->offsetx * (1.0f/DM_VERTEX_NORMFACTOR);
1049 vy0 = (float)imageBuffer->offsety * (1.0f/DM_VERTEX_NORMFACTOR);
1050 vx3 = vx0 + (float)( imageBuffer->sizex );
1051 vy3 = vy0 + (float)( imageBuffer->sizey );
1058 /* FIXME TODO: Don't go through float, compute texcoord integers directly */
1059 tx0 = (float)( image->srcx ) * texture.widthinv;
1060 ty0 = (float)( image->srcy ) * texture.heightinv;
1061 tx1 = (float)( image->srcx + image->sizex ) * texture.widthinv;
1062 ty1 = (float)( image->srcy + image->sizey ) * texture.heightinv;
1064 /* Write data to VBO */
1065 /* TODO: write vertex/texcoord all at once with SSE */
1066 vboVertex[0].vertex[0] = (short)( vx3 * DM_VERTEX_NORMFACTOR );
1067 vboVertex[0].vertex[1] = (short)( vy3 * DM_VERTEX_NORMFACTOR );
1068 vboVertex[0].texcoord0[0] = (short)( tx1 * DM_TEXCOORD_NORMFACTOR );
1069 vboVertex[0].texcoord0[1] = (short)( ty1 * DM_TEXCOORD_NORMFACTOR );
1070 vboVertex[0].color = imageBuffer->color;
1071 vboVertex[0].extcolor = imageBuffer->extcolor;
1072 vboVertex[1].vertex[0] = (short)( vx1 * DM_VERTEX_NORMFACTOR );
1073 vboVertex[1].vertex[1] = (short)( vy1 * DM_VERTEX_NORMFACTOR );
1074 vboVertex[1].texcoord0[0] = (short)( tx1 * DM_TEXCOORD_NORMFACTOR );
1075 vboVertex[1].texcoord0[1] = (short)( ty0 * DM_TEXCOORD_NORMFACTOR );
1076 vboVertex[1].color = imageBuffer->color;
1077 vboVertex[1].extcolor = imageBuffer->extcolor;
1078 vboVertex[2].vertex[0] = (short)( vx2 * DM_VERTEX_NORMFACTOR );
1079 vboVertex[2].vertex[1] = (short)( vy2 * DM_VERTEX_NORMFACTOR );
1080 vboVertex[2].texcoord0[0] = (short)( tx0 * DM_TEXCOORD_NORMFACTOR );
1081 vboVertex[2].texcoord0[1] = (short)( ty1 * DM_TEXCOORD_NORMFACTOR );
1082 vboVertex[2].color = imageBuffer->color;
1083 vboVertex[2].extcolor = imageBuffer->extcolor;
1084 vboVertex[3].vertex[0] = (short)( vx0 * DM_VERTEX_NORMFACTOR );
1085 vboVertex[3].vertex[1] = (short)( vy0 * DM_VERTEX_NORMFACTOR );
1086 vboVertex[3].texcoord0[0] = (short)( tx0 * DM_TEXCOORD_NORMFACTOR );
1087 vboVertex[3].texcoord0[1] = (short)( ty0 * DM_TEXCOORD_NORMFACTOR );
1088 vboVertex[3].color = imageBuffer->color;
1089 vboVertex[3].extcolor = imageBuffer->extcolor;
1090 vboVertex[4].vertex[0] = (short)( vx2 * DM_VERTEX_NORMFACTOR );
1091 vboVertex[4].vertex[1] = (short)( vy2 * DM_VERTEX_NORMFACTOR );
1092 vboVertex[4].texcoord0[0] = (short)( tx0 * DM_TEXCOORD_NORMFACTOR );
1093 vboVertex[4].texcoord0[1] = (short)( ty1 * DM_TEXCOORD_NORMFACTOR );
1094 vboVertex[4].color = imageBuffer->color;
1095 vboVertex[4].extcolor = imageBuffer->extcolor;
1096 vboVertex[5].vertex[0] = (short)( vx1 * DM_VERTEX_NORMFACTOR );
1097 vboVertex[5].vertex[1] = (short)( vy1 * DM_VERTEX_NORMFACTOR );
1098 vboVertex[5].texcoord0[0] = (short)( tx1 * DM_TEXCOORD_NORMFACTOR );
1099 vboVertex[5].texcoord0[1] = (short)( ty0 * DM_TEXCOORD_NORMFACTOR );
1100 vboVertex[5].color = imageBuffer->color;
1101 vboVertex[5].extcolor = imageBuffer->extcolor;
1107 glUnmapBuffer( GL_ARRAY_BUFFER );
1108 // Flush font manager texture updates
1110 // Render buffered images
1111 flushRenderDrawBuffer( drawBuffer, program, vertexcount );
1112 imageBufferCount = 0;
1120 virtual void flush();
1122 bool init( DrawManagerFlags flags )
1124 int drawBufferIndex, programIndex;
1125 DMDrawBuffer *drawBuffer;
1128 imageBufferCount = 0;
1129 imageBufferSize = 4096;
1130 imageBuffer = new DMImageBuffer[imageBufferSize];
1131 imageBufferTmp = new DMImageBuffer[imageBufferSize];
1135 if( flags.prehistoricOpenGL )
1136 vertexSize = sizeof(DMDrawVertexFlat);
1140 for( programIndex = 0 ; programIndex < DM_PROGRAM_COUNT ; programIndex++ )
1142 program = &shaderPrograms[ programIndex ];
1144 program->lastUpdateCount = -1;
1146 program = &shaderPrograms[ DM_PROGRAM_NORMAL ];
1147 if( !( dmCreateProgram( program, dmVertexShaderNormal, dmFragmentShaderNormal, 0 ) ) )
1149 program = &shaderPrograms[ DM_PROGRAM_ALPHABLEND ];
1150 if( !( dmCreateProgram( program, dmVertexShaderAlpha, dmFragmentShaderAlpha, 0 ) ) )
1152 program = &shaderPrograms[ DM_PROGRAM_ALPHABLEND_INTENSITY ];
1153 if( !( dmCreateProgram( program, dmVertexShaderAlphaIntensity, dmFragmentShaderAlphaIntensity, 0 ) ) )
1155 program = &shaderPrograms[ DM_PROGRAM_ALPHABLEND_INTENSITY_EXTCOLOR ];
1156 if( !( dmCreateProgram( program, dmVertexShaderAlphaIntensityExtColor, dmFragmentShaderAlphaIntensityExtColor, 0 ) ) )
1158 // glUseProgram( 0 );
1159 vertexSize = sizeof(DMDrawVertex);
1162 for( drawBufferIndex = 0 ; drawBufferIndex < DM_CONTEXT_DRAW_BUFFER_COUNT ; drawBufferIndex++ )
1164 drawBuffer = &this.drawBuffer[drawBufferIndex];
1165 drawBuffer->glType = GL_FLOAT;
1166 drawBuffer->vertexCount = 0;
1167 drawBuffer->vertexAlloc = DM_CONTEXT_DRAW_BUFFER_VERTEX_ALLOC;
1170 glGenBuffers( 1, &drawBuffer->vbo );
1171 glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
1172 glBufferData( GL_ARRAY_BUFFER, drawBuffer->vertexAlloc * vertexSize, 0, GL_DYNAMIC_DRAW );
1174 drawBuffer->vertexBuffer = new byte[drawBuffer->vertexAlloc * vertexSize];
1187 for( i = 0 ; i < DM_CONTEXT_DRAW_BUFFER_COUNT ; i++ )
1189 DMDrawBuffer *db = &drawBuffer[i];
1191 glDeleteBuffers( 1, &db->vbo );
1192 delete db->vertexBuffer;
1195 // TODO: Destroy the shaders!
1197 delete imageBufferTmp;
1200 void ready( int viewportwidth, int viewportheight )
1204 glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *)&prevProgram);
1205 // while(glGetError());
1209 // Save OpenGL state
1210 // FIXME: no glPushAttrib() in core profile
1212 glPushClientAttrib( GL_CLIENT_ALL_ATTRIB_BITS );
1213 glPushAttrib( GL_ALL_ATTRIB_BITS );
1216 // Prepare rendering pass
1217 matrixOrtho( matrix, 0.0, (float)viewportwidth, (float)viewportheight, 0.0, -1.0f, 1.0 );
1218 norminv = 1.0f / DM_VERTEX_NORMFACTOR;
1219 for( mindex = 0 ; mindex < 12 ; mindex += 4 )
1221 matrix[mindex+0] *= norminv;
1222 matrix[mindex+1] *= norminv;
1223 matrix[mindex+2] *= norminv;
1225 drawBarrierIndex = 0;
1226 orderBarrierMask = drawBarrierIndex << DM_BARRIER_ORDER_SHIFT;
1227 orderBarrierMask = 0;
1232 void drawImage( DMImage image, int offsetx, int offsety, int sizex, int sizey, uint32 color )
1234 DMImageBuffer *imageBuffer;
1236 if( image.flags.empty || ( sizex <= 0 ) || ( sizey <= 0 ) )
1239 if( imageBufferCount >= imageBufferSize )
1241 imageBufferSize <<= 1;
1242 this.imageBuffer = renew this.imageBuffer DMImageBuffer[imageBufferSize];
1243 imageBufferTmp = renew imageBufferTmp DMImageBuffer[imageBufferSize];
1246 imageBuffer = &this.imageBuffer[ imageBufferCount ];
1247 imageBuffer->image = image;
1248 imageBuffer->offsetx = (short)(offsetx << DM_VERTEX_NORMSHIFT);
1249 imageBuffer->offsety = (short)(offsety << DM_VERTEX_NORMSHIFT);
1250 imageBuffer->sizex = (short)sizex;
1251 imageBuffer->sizey = (short)sizey;
1252 #if DM_ENABLE_IMAGE_ROTATION
1253 imageBuffer->angsin = 0;
1254 imageBuffer->angcos = (short)DM_IMAGE_ROTATION_NORMFACTOR;
1256 imageBuffer->color = color;
1257 imageBuffer->orderindex = image.orderMask | orderBarrierMask;
1259 #if DM_RENDER_IMAGE_DEBUG
1260 printf( " Queue image at %d %d, order 0x%x\n", (int)imageBuffer->offsetx, (int)imageBuffer->offsety, (int)imageBuffer->orderindex );
1266 void drawImageExtColor( DMImage image, int offsetx, int offsety, int sizex, int sizey, uint32 color, uint32 extcolor )
1268 DMImageBuffer *imageBuffer;
1270 if( ( image.flags.empty ) || ( sizex <= 0 ) || ( sizey <= 0 ) )
1273 if( imageBufferCount >= imageBufferSize )
1275 imageBufferSize <<= 1;
1276 this.imageBuffer = renew this.imageBuffer DMImageBuffer[imageBufferSize];
1277 imageBufferTmp = renew imageBufferTmp DMImageBuffer[imageBufferSize];
1280 imageBuffer = &this.imageBuffer[ imageBufferCount ];
1281 imageBuffer->image = image;
1282 imageBuffer->offsetx = (short)(offsetx << DM_VERTEX_NORMSHIFT);
1283 imageBuffer->offsety = (short)(offsety << DM_VERTEX_NORMSHIFT);
1284 imageBuffer->sizex = (short)sizex;
1285 imageBuffer->sizey = (short)sizey;
1286 #if DM_ENABLE_IMAGE_ROTATION
1287 imageBuffer->angsin = 0;
1288 imageBuffer->angcos = (short)DM_IMAGE_ROTATION_NORMFACTOR;
1290 imageBuffer->color = color;
1291 #if DM_ENABLE_EXT_COLOR
1292 imageBuffer->extcolor = extcolor;
1294 imageBuffer->orderindex = image.orderMask | orderBarrierMask;
1296 #if DM_RENDER_IMAGE_DEBUG
1297 printf( " Queue image at %d %d, order 0x%x\n", (int)imageBuffer->offsetx, (int)imageBuffer->offsety, (int)imageBuffer->orderindex );
1300 this.imageBufferCount++;
1303 void drawImageFloat( DMImage image, float offsetx, float offsety, float sizex, float sizey, float angsin, float angcos, uint32 color )
1305 DMImageBuffer *imageBuffer;
1307 if( image.flags.empty || sizex <= 0 || sizey <= 0 )
1310 if( imageBufferCount >= imageBufferSize )
1312 imageBufferSize <<= 1;
1313 this.imageBuffer = renew this.imageBuffer DMImageBuffer[imageBufferSize];
1314 imageBufferTmp = renew imageBufferTmp DMImageBuffer[imageBufferSize];
1317 imageBuffer = &this.imageBuffer[ imageBufferCount ];
1318 imageBuffer->image = image;
1319 imageBuffer->offsetx = (short)roundf(offsetx * DM_VERTEX_NORMFACTOR);
1320 imageBuffer->offsety = (short)roundf(offsety * DM_VERTEX_NORMFACTOR);
1321 imageBuffer->sizex = (short)sizex;
1322 imageBuffer->sizey = (short)sizey;
1323 #if DM_ENABLE_IMAGE_ROTATION
1324 imageBuffer->angsin = (short)roundf( angsin * DM_IMAGE_ROTATION_NORMFACTOR );
1325 imageBuffer->angcos = (short)roundf( angcos * DM_IMAGE_ROTATION_NORMFACTOR );
1327 imageBuffer->color = color;
1328 imageBuffer->orderindex = image.orderMask | orderBarrierMask;
1330 #if DM_RENDER_IMAGE_DEBUG
1331 printf( " Queue image at %d %d, order 0x%x\n", (int)imageBuffer->offsetx, (int)imageBuffer->offsety, (int)imageBuffer->orderindex );
1337 void drawImageFloatExtColor( DMImage image, float offsetx, float offsety, float sizex, float sizey, float angsin, float angcos, uint32 color, uint32 extcolor )
1339 DMImageBuffer *imageBuffer;
1341 if( ( image.flags.empty ) || ( sizex <= 0 ) || ( sizey <= 0 ) )
1344 if( this.imageBufferCount >= this.imageBufferSize )
1346 imageBufferSize <<= 1;
1347 this.imageBuffer = renew this.imageBuffer DMImageBuffer[imageBufferSize];
1348 imageBufferTmp = renew imageBufferTmp DMImageBuffer[imageBufferSize];
1351 imageBuffer = &this.imageBuffer[ imageBufferCount ];
1352 imageBuffer->image = image;
1353 imageBuffer->offsetx = (short)roundf( offsetx * DM_VERTEX_NORMFACTOR );
1354 imageBuffer->offsety = (short)roundf( offsety * DM_VERTEX_NORMFACTOR );
1355 imageBuffer->sizex = (short)sizex;
1356 imageBuffer->sizey = (short)sizey;
1357 #if DM_ENABLE_IMAGE_ROTATION
1358 imageBuffer->angsin = (short)roundf( angsin * DM_IMAGE_ROTATION_NORMFACTOR );
1359 imageBuffer->angcos = (short)roundf( angcos * DM_IMAGE_ROTATION_NORMFACTOR );
1361 imageBuffer->color = color;
1362 #if DM_ENABLE_EXT_COLOR
1363 imageBuffer->extcolor = extcolor;
1365 imageBuffer->orderindex = image.orderMask | orderBarrierMask;
1367 #if DM_RENDER_IMAGE_DEBUG
1368 printf( " Queue image at %d %d, order 0x%x\n", (int)imageBuffer->offsetx, (int)imageBuffer->offsety, (int)imageBuffer->orderindex );
1371 this.imageBufferCount++;
1376 if( flags.prehistoricOpenGL )
1377 flushDrawImagesArchaic( );
1382 glBindBuffer( GL_ARRAY_BUFFER, 0 );
1383 glabCurArrayBuffer = 0;
1384 if( !flags.prehistoricOpenGL )
1385 glUseProgram( prevProgram );
1386 // Restore OpenGL state
1387 // FIXME: no glPushAttrib() in core profile
1390 glPopClientAttrib();
1397 if( drawBarrierIndex >= ( 1 << DM_BARRIER_ORDER_BITS ) )
1399 orderBarrierMask = drawBarrierIndex << DM_BARRIER_ORDER_SHIFT;