DXGL r60 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r59‎ | r60 | r61 >
Date:19:50, 31 December 2011
Author:admin
Status:new
Tags:
Comment:
Set internalformat on textures
Change color key shader to not compare alpha bits
Modified paths:
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glExtensions.cpp (modified) (history)
  • /ddraw/glExtensions.h (modified) (history)
  • /ddraw/shaders.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirectDrawSurface.cpp
@@ -54,13 +54,13 @@
5555 }
5656
5757
58 -int UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2)
 58+int UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3)
5959 {
6060 if(bpp == 15) bpp = 16;
6161 glBindTexture(GL_TEXTURE_2D,texture); // Select surface's texture
6262 if((x == bigx && y == bigy) || !bigbuffer)
6363 {
64 - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,x,y,0,texformat,texformat2,buffer);
 64+ glTexImage2D(GL_TEXTURE_2D,0,texformat3,x,y,0,texformat,texformat2,buffer);
6565 }
6666 else
6767 {
@@ -80,7 +80,7 @@
8181 break;
8282 break;
8383 }
84 - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bigx,bigy,0,texformat,texformat2,bigbuffer);
 84+ glTexImage2D(GL_TEXTURE_2D,0,texformat3,bigx,bigy,0,texformat,texformat2,bigbuffer);
8585 }
8686 return 0;
8787 }
@@ -299,13 +299,16 @@
300300 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
301301 if(ddsd.dwFlags & DDSD_PIXELFORMAT)
302302 {
303 - switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
 303+ if(ddsd.dwFlags & DDPF_ZBUFFER)
304304 {
305 - case 8:
306 - case 16:
307 - case 32:
308 - break;
309 -
 305+ switch(ddsd.ddpfPixelFormat.dwZBufferBitDepth)
 306+ {
 307+ case 16:
 308+ default:
 309+ case 24:
 310+ case 32:
 311+ __asm nop
 312+ }
310313 }
311314 }
312315 else
@@ -316,6 +319,7 @@
317320 case 8:
318321 texformat = GL_LUMINANCE;
319322 texformat2 = GL_UNSIGNED_BYTE;
 323+ texformat3 = GL_LUMINANCE8;
320324 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
321325 ddsd.ddpfPixelFormat.dwRBitMask = 0;
322326 ddsd.ddpfPixelFormat.dwGBitMask = 0;
@@ -325,6 +329,7 @@
326330 case 15:
327331 texformat = GL_BGRA;
328332 texformat2 = GL_UNSIGNED_SHORT_1_5_5_5_REV;
 333+ texformat3 = GL_RGB5_A1;
329334 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
330335 ddsd.ddpfPixelFormat.dwRBitMask = 0x7C00;
331336 ddsd.ddpfPixelFormat.dwGBitMask = 0x3E0;
@@ -335,6 +340,7 @@
336341 case 16:
337342 texformat = GL_RGB;
338343 texformat2 = GL_UNSIGNED_SHORT_5_6_5;
 344+ texformat3 = GL_RGB565;
339345 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
340346 ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;
341347 ddsd.ddpfPixelFormat.dwGBitMask = 0x7E0;
@@ -344,6 +350,7 @@
345351 case 24:
346352 texformat = GL_BGR;
347353 texformat2 = GL_UNSIGNED_BYTE;
 354+ texformat3 = GL_RGB8;
348355 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
349356 ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
350357 ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
@@ -353,6 +360,7 @@
354361 case 32:
355362 texformat = GL_BGRA;
356363 texformat2 = GL_UNSIGNED_BYTE;
 364+ texformat3 = GL_RGBA8;
357365 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
358366 ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
359367 ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
@@ -371,7 +379,7 @@
372380 memcpy(bitmapinfo->bmiColors,colormasks,3*sizeof(DWORD));
373381 }
374382 }
375 - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,fakex,fakey,0,texformat,texformat2,NULL);
 383+ glTexImage2D(GL_TEXTURE_2D,0,texformat3,fakex,fakey,0,texformat,texformat2,NULL);
376384 }
377385
378386 refcount = 1;
@@ -517,7 +525,7 @@
518526 {
519527 UploadTexture(buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,
520528 fakex,fakey,ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*fakex)),
521 - ddsd.ddpfPixelFormat.dwRGBBitCount,texformat,texformat2);
 529+ ddsd.ddpfPixelFormat.dwRGBBitCount,texformat,texformat2,texformat3);
522530 dirty &= ~1;
523531 }
524532 if(src && (src->dirty & 1))
@@ -525,7 +533,7 @@
526534 UploadTexture(src->buffer,src->bigbuffer,src->texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
527535 src->fakex,src->fakey,src->ddsd.lPitch,
528536 (NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*src->fakex)),
529 - src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->texformat,src->texformat2);
 537+ src->ddsd.ddpfPixelFormat.dwRGBBitCount,src->texformat,src->texformat2,src->texformat3);
530538 src->dirty &= ~1;
531539 }
532540 LONG sizes[6];
@@ -621,25 +629,25 @@
622630 switch(ddInterface->GetBPP())
623631 {
624632 case 8:
625 - glUniform4i(keyloc,src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
626 - src->colorkey[0].key.dwColorSpaceHighValue,255);
 633+ glUniform3i(keyloc,src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
 634+ src->colorkey[0].key.dwColorSpaceHighValue);
627635 break;
628636 case 15:
629 - glUniform4i(keyloc,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
 637+ glUniform3i(keyloc,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
630638 _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 31),
631 - _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31),255);
 639+ _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
632640 break;
633641 case 16:
634 - glUniform4i(keyloc,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
 642+ glUniform3i(keyloc,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
635643 _6to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 63),
636 - _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31),255);
 644+ _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
637645 break;
638646 case 24:
639647 case 32:
640648 default:
641 - glUniform4i(keyloc,(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
 649+ glUniform3i(keyloc,(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
642650 (src->colorkey[0].key.dwColorSpaceHighValue>>8 & 255),
643 - (src->colorkey[0].key.dwColorSpaceHighValue & 255),255);
 651+ (src->colorkey[0].key.dwColorSpaceHighValue & 255));
644652 break;
645653 }
646654 GLint texloc = glGetUniformLocation(shaders[PROG_CKEY].prog,"myTexture");
@@ -742,7 +750,7 @@
743751 {
744752 UploadTexture(buffer,bigbuffer,texture,ddsd.dwWidth,ddsd.dwHeight,
745753 fakex,fakey,ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*fakex)),
746 - ddsd.ddpfPixelFormat.dwRGBBitCount,texformat,texformat2);
 754+ ddsd.ddpfPixelFormat.dwRGBBitCount,texformat,texformat2,texformat3);
747755 dirty &= ~1;
748756 }
749757 this->dirty |= 2;
@@ -753,7 +761,7 @@
754762 {
755763 UploadTexture(tmp->buffer,tmp->bigbuffer,tmp->texture,tmp->ddsd.dwWidth,tmp->ddsd.dwHeight,
756764 tmp->fakex,tmp->fakey,tmp->ddsd.lPitch,(NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*tmp->fakex)),
757 - tmp->ddsd.ddpfPixelFormat.dwRGBBitCount,tmp->texformat,tmp->texformat2);
 765+ tmp->ddsd.ddpfPixelFormat.dwRGBBitCount,tmp->texformat,tmp->texformat2,tmp->texformat3);
758766 tmp->dirty &= ~1;
759767 }
760768 tmp->dirty |= 2;
@@ -1058,7 +1066,7 @@
10591067 UploadTexture(buffer,surface->bigbuffer,texture,surface->ddsd.dwWidth,surface->ddsd.dwHeight,
10601068 surface->fakex,surface->fakey,surface->ddsd.lPitch,
10611069 (NextMultipleOf4((ddInterface->GetBPPMultipleOf8()/8)*surface->fakex)),
1062 - surface->ddsd.ddpfPixelFormat.dwRGBBitCount,surface->texformat,surface->texformat2);
 1070+ surface->ddsd.ddpfPixelFormat.dwRGBBitCount,surface->texformat,surface->texformat2,surface->texformat3);
10631071 surface->dirty &= ~1;
10641072 }
10651073 if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
Index: ddraw/glDirectDrawSurface.h
@@ -109,6 +109,7 @@
110110 int flipcount;
111111 GLenum texformat;
112112 GLenum texformat2;
 113+ GLint texformat3;
113114 DWORD fakex,fakey;
114115 DWORD dirty;
115116 HGLRC hrc;
Index: ddraw/glExtensions.cpp
@@ -45,6 +45,8 @@
4646
4747 GLint (APIENTRY *glGetUniformLocation) (GLuint program, const GLchar* name) = NULL;
4848 void (APIENTRY *glUniform1i) (GLint location, GLint v0) = NULL;
 49+void (APIENTRY *glUniform2i) (GLint location, GLint v0, GLint v1) = NULL;
 50+void (APIENTRY *glUniform3i) (GLint location, GLint v0, GLint v1, GLint v2) = NULL;
4951 void (APIENTRY *glUniform4i) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3) = NULL;
5052
5153 void (APIENTRY *glActiveTexture)(GLenum texture) = NULL;
@@ -80,6 +82,8 @@
8183 glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
8284 glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation");
8385 glUniform1i = (PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i");
 86+ glUniform2i = (PFNGLUNIFORM2IPROC)wglGetProcAddress("glUniform2i");
 87+ glUniform3i = (PFNGLUNIFORM3IPROC)wglGetProcAddress("glUniform3i");
8488 glUniform4i = (PFNGLUNIFORM4IPROC)wglGetProcAddress("glUniform4i");
8589 }
8690 const GLubyte *glextensions = glGetString(GL_EXTENSIONS);
Index: ddraw/glExtensions.h
@@ -25,8 +25,10 @@
2626 #ifndef GL_STENCIL_BUFFER
2727 #define GL_STENCIL_BUFFER 0x8224
2828 #endif
 29+#ifndef GL_RGB565
 30+#define GL_RGB565 0x8D62
 31+#endif
2932
30 -
3133 extern int GLEXT_ARB_framebuffer_object;
3234 extern int GLEXT_EXT_framebuffer_object;
3335 extern int GLEXT_NV_packed_depth_stencil;
@@ -65,6 +67,8 @@
6668
6769 GLAPI GLint (APIENTRY *glGetUniformLocation) (GLuint program, const GLchar* name);
6870 GLAPI void (APIENTRY *glUniform1i) (GLint location, GLint v0);
 71+GLAPI void (APIENTRY *glUniform2i) (GLint location, GLint v0, GLint v1);
 72+GLAPI void (APIENTRY *glUniform3i) (GLint location, GLint v0, GLint v1, GLint v2);
6973 GLAPI void (APIENTRY *glUniform4i) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
7074
7175 GLAPI void (APIENTRY *glActiveTexture)(GLenum texture);
Index: ddraw/shaders.cpp
@@ -32,11 +32,11 @@
3333 char frag_ColorKey[] = "\
3434 #version 110\n\
3535 uniform sampler2D myTexture;\n\
36 -uniform ivec4 keyIn;\n\
 36+uniform ivec3 keyIn;\n\
3737 void main (void)\n\
3838 {\n\
3939 vec4 value = texture2D(myTexture, vec2(gl_TexCoord[0]));\n\
40 - ivec4 comp = ivec4(texture2D(myTexture, vec2(gl_TexCoord[0]))*255.0);\n\
 40+ ivec3 comp = ivec3(texture2D(myTexture, vec2(gl_TexCoord[0]))*255.0);\n\
4141 if (comp == keyIn)\n\
4242 discard;\n\
4343 gl_FragColor = value;\n\