DXGL r386 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r385‎ | r386 | r387 >
Date:01:31, 24 June 2013
Author:admin
Status:new
Tags:
Comment:
Add support for sampler objects.
Update release version.
Modified paths:
  • /ReadMe.txt (modified) (history)
  • /common/releasever.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/texture.cpp (modified) (history)
  • /ddraw/texture.h (modified) (history)

Diff [purge]

Index: ReadMe.txt
@@ -1,4 +1,4 @@
2 -DXGL 0.5.0
 2+DXGL 0.5.1
33 http://www.williamfeely.info/wiki/DXGL
44
55 == Introduction ==
@@ -35,7 +35,7 @@
3636 * 8-bit color emulated with GLSL shader
3737
3838 What partially works:
39 -* 3D graphics are only partially supported, and only advertised in Debug builds.
 39+* 3D graphics are only partially supported.
4040
4141 What doesn't work:
4242 * Many functions are stubbed out and return an error
Index: common/releasever.h
@@ -4,7 +4,7 @@
55
66 #define DXGLMAJORVER 0
77 #define DXGLMINORVER 5
8 -#define DXGLPOINTVER 0
 8+#define DXGLPOINTVER 1
99
1010 #define STR2(x) #x
1111 #define STR(x) STR2(x)
Index: ddraw/glDirectDrawSurface.cpp
@@ -1409,19 +1409,30 @@
14101410 min = GL_LINEAR_MIPMAP_LINEAR;
14111411 break;
14121412 }
1413 - if(GLEXT_EXT_direct_state_access)
 1413+ if(GLEXT_ARB_sampler_objects)
14141414 {
1415 - glTextureParameteriEXT(texture->id,GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
1416 - glTextureParameteriEXT(texture->id,GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
 1415+ glSamplerParameteri(samplers[level].id,GL_TEXTURE_MAG_FILTER,mag);
 1416+ glSamplerParameteri(samplers[level].id,GL_TEXTURE_MIN_FILTER,min);
14171417 }
14181418 else
14191419 {
1420 - ::SetTexture(level,texture);
1421 - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
1422 - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
 1420+ if(GLEXT_EXT_direct_state_access)
 1421+ {
 1422+ glTextureParameteriEXT(texture->id,GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
 1423+ glTextureParameteriEXT(texture->id,GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
 1424+ }
 1425+ else
 1426+ {
 1427+ ::SetTexture(level,texture);
 1428+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
 1429+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
 1430+ }
14231431 }
1424 - magfilter = mag;
1425 - minfilter = min;
 1432+ if(this)
 1433+ {
 1434+ magfilter = mag;
 1435+ minfilter = min;
 1436+ }
14261437 TRACE_EXIT(0,0);
14271438 }
14281439
Index: ddraw/glRenderer.cpp
@@ -631,6 +631,7 @@
632632 if(dib.hdc) DeleteDC(dib.hdc);
633633 ZeroMemory(&dib,sizeof(DIB));
634634 }
 635+ DeleteSamplers();
635636 DeleteShaders();
636637 ::DeleteFBO(&fbo);
637638 if(PBO)
@@ -838,6 +839,7 @@
839840 glBindBuffer(GL_PIXEL_PACK_BUFFER,PBO);
840841 glBufferData(GL_PIXEL_PACK_BUFFER,width*height*4,NULL,GL_STREAM_READ);
841842 glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
 843+ InitSamplers();
842844 TRACE_SYSINFO();
843845 return TRUE;
844846 }
@@ -962,7 +964,15 @@
963965 progtype = PROG_TEXTURE;
964966 glUniform1i(shaders[progtype].tex0,0);
965967 }
966 - if(src) SetTexture(0,src->GetTexture());
 968+ if(src)
 969+ {
 970+ SetTexture(0,src->GetTexture());
 971+ if(GLEXT_ARB_sampler_objects)
 972+ {
 973+ if((dxglcfg.scalingfilter == 0) || (ddInterface->GetBPP() == 8)) src->SetFilter(0,GL_NEAREST,GL_NEAREST);
 974+ else src->SetFilter(0,GL_LINEAR,GL_LINEAR);
 975+ }
 976+ }
967977 else SetTexture(0,NULL);
968978 glUniform4f(shaders[progtype].view,0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
969979 dest->dirty |= 2;
@@ -1028,6 +1038,7 @@
10291039 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
10301040 SetTexture(0,*texture);
10311041 *texture = backbuffer;
 1042+ if(GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR);
10321043 glUniform4f(shaders[progtype].view,view[0],view[1],view[2],view[3]);
10331044 bltvertices[0].s = bltvertices[0].t = bltvertices[1].t = bltvertices[2].s = 1.;
10341045 bltvertices[1].s = bltvertices[2].t = bltvertices[3].s = bltvertices[3].t = 0.;
@@ -1122,6 +1133,7 @@
11231134 SetTexture(0,texture);
11241135 glUniform1i(shaders[progtype].tex0,0);
11251136 }
 1137+ if(GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(1,GL_NEAREST,GL_NEAREST);
11261138 }
11271139 else
11281140 {
Index: ddraw/glutil.cpp
@@ -214,9 +214,31 @@
215215 {
216216 texwrap[level*2+coord] = wrapmode;
217217 //int currtexture = texlevel;
218 - SetActiveTexture(level);
219 - if(coord) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapmode);
220 - else glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrapmode);
 218+ if(GLEXT_ARB_sampler_objects)
 219+ {
 220+ if(coord)
 221+ {
 222+ if(samplers[level].wrapt != wrapmode)
 223+ {
 224+ glSamplerParameteri(samplers[level].id,GL_TEXTURE_WRAP_T,wrapmode);
 225+ samplers[level].wrapt = wrapmode;
 226+ }
 227+ }
 228+ else
 229+ {
 230+ if(samplers[level].wraps != wrapmode)
 231+ {
 232+ glSamplerParameteri(samplers[level].id,GL_TEXTURE_WRAP_S,wrapmode);
 233+ samplers[level].wraps = wrapmode;
 234+ }
 235+ }
 236+ }
 237+ else
 238+ {
 239+ SetActiveTexture(level);
 240+ if(coord) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapmode);
 241+ else glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrapmode);
 242+ }
221243 //SetActiveTexture(currtexture);
222244 }
223245 }
Index: ddraw/texture.cpp
@@ -51,6 +51,37 @@
5252 GLint texlevel = 0;
5353 GLuint textures[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
5454
 55+SAMPLER samplers[8];
 56+
 57+void InitSamplers()
 58+{
 59+ if(GLEXT_ARB_sampler_objects)
 60+ {
 61+ memset(samplers,0,8*sizeof(SAMPLER));
 62+ for(int i = 0; i < 8; i++)
 63+ {
 64+ glGenSamplers(1,&samplers[i].id);
 65+ glBindSampler(i,samplers[i].id);
 66+ glSamplerParameteri(samplers[i].id,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
 67+ glSamplerParameteri(samplers[i].id,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
 68+ glSamplerParameteri(samplers[i].id,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
 69+ glSamplerParameteri(samplers[i].id,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
 70+ }
 71+ }
 72+}
 73+void DeleteSamplers()
 74+{
 75+ if(GLEXT_ARB_sampler_objects)
 76+ {
 77+ for(int i = 0; i < 8; i++)
 78+ {
 79+ glBindSampler(i,0);
 80+ glDeleteSamplers(1,&samplers[i].id);
 81+ samplers[i].id = 0;
 82+ }
 83+ }
 84+}
 85+
5586 void CreateTextureClassic(TEXTURE *texture, int width, int height)
5687 {
5788 int texformat = -1;
@@ -258,7 +289,7 @@
259290
260291
261292
262 -/*
 293+/* old code
263294 if(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)
264295 {
265296 switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
Index: ddraw/texture.h
@@ -37,6 +37,19 @@
3838 DDPIXELFORMAT pixelformat;
3939 } TEXTURE;
4040
 41+typedef struct
 42+{
 43+ GLuint id;
 44+ GLint wraps;
 45+ GLint wrapt;
 46+ GLint minfilter;
 47+ GLint magfilter;
 48+} SAMPLER;
 49+
 50+extern SAMPLER samplers[8];
 51+
 52+void InitSamplers();
 53+void DeleteSamplers();
4154 void InitTexture(DXGLCFG *cfg);
4255 void SetActiveTexture(int level);
4356 void SetTexture(unsigned int level, TEXTURE *texture);