DXGL r475 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r474‎ | r475 | r476 >
Date:00:39, 4 August 2014
Author:admin
Status:new
Tags:
Comment:
Support fixing texture internal format when FBO rendering fails.
Update version info in resource script.
Modified paths:
  • /ddraw/TextureManager.c (modified) (history)
  • /ddraw/TextureManager.h (modified) (history)
  • /ddraw/ddraw.rc (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glUtil.cpp (modified) (history)
  • /ddraw/glUtil.h (modified) (history)
  • /dxglcfg/dxglcfg.rc (modified) (history)
  • /dxgltest/dxgltest.rc (modified) (history)

Diff [purge]

Index: ddraw/TextureManager.c
——@@ -366,3 +366,44 @@
367367 glBindTexture(GL_TEXTURE_2D,texname);
368368 }
369369 }
 370+
 371+BOOL TextureManager_FixTexture(TextureManager *This, TEXTURE *texture, void *data, DWORD *dirty)
 372+{
 373+ // data should be null to create uninitialized texture or be pointer to top-level
 374+ // buffer to retain texture data
 375+ TEXTURE newtexture;
 376+ GLenum error;
 377+ memcpy(&newtexture, texture, sizeof(TEXTURE));
 378+ if (texture->miplevel > 0) return FALSE;
 379+ if (texture->internalformats[1] == 0) return FALSE;
 380+ glGenTextures(1, &newtexture.id);
 381+ TextureManager_SetActiveTexture(This, 0);
 382+ if (data)
 383+ {
 384+ TextureManager_SetTexture(This, 0, texture);
 385+ glGetTexImage(GL_TEXTURE_2D, 0, texture->format, texture->type, data);
 386+ if (dirty) *dirty |= 2;
 387+ }
 388+ TextureManager_SetTexture(This, 0, &newtexture);
 389+ do
 390+ {
 391+ memmove(&newtexture.internalformats[0], &newtexture.internalformats[1], 7 * sizeof(GLint));
 392+ newtexture.internalformats[7] = 0;
 393+ ClearError();
 394+ glTexImage2D(GL_TEXTURE_2D, 0, newtexture.internalformats[0], newtexture.width, newtexture.height,
 395+ 0, newtexture.format, newtexture.type, NULL);
 396+ error = glGetError();
 397+ if (error != GL_NO_ERROR)
 398+ {
 399+ if (newtexture.internalformats[1] == 0)
 400+ {
 401+ FIXME("Failed to repair texture, cannot find internal format");
 402+ break;
 403+ }
 404+ }
 405+ else break;
 406+ } while (1);
 407+ TextureManager__DeleteTexture(This, texture);
 408+ memcpy(texture, &newtexture, sizeof(TEXTURE));
 409+ return TRUE;
 410+}
\ No newline at end of file
Index: ddraw/TextureManager.h
——@@ -74,6 +74,7 @@
7575 void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture);
7676 void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror);
7777 void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data);
 78+BOOL TextureManager_FixTexture(TextureManager *This, TEXTURE *texture, void *data, DWORD *dirty);
7879
7980 #ifdef __cplusplus
8081 }
Index: ddraw/ddraw.rc
——@@ -64,7 +64,7 @@
6565 VALUE "FileDescription", "DXGL DDraw Library"
6666 VALUE "FileVersion", DXGLVERSTRING
6767 VALUE "InternalName", "DXGL"
68 - VALUE "LegalCopyright", "Copyright (C) 2011-2012 William Feely"
 68+ VALUE "LegalCopyright", "Copyright (C) 2011-2014 William Feely"
6969 VALUE "OriginalFilename", "DDraw.dll"
7070 VALUE "ProductName", "DXGL"
7171 VALUE "ProductVersion", DXGLVERSTRING
Index: ddraw/glRenderer.cpp
——@@ -982,7 +982,12 @@
983983 This->shaders->SetShader(shaderid, NULL, NULL, 1);
984984 GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
985985 This->util->BlendEnable(false);
986 - This->util->SetFBO(dest);
 986+ do
 987+ {
 988+ if (This->util->SetFBO(dest) == GL_FRAMEBUFFER_COMPLETE) break;
 989+ if (!dest->texture->internalformats[1]) break;
 990+ TextureManager_FixTexture(This->texman, dest->texture, (dest->bigbuffer ? dest->bigbuffer : dest->buffer), &dest->dirty);
 991+ } while (1);
987992 This->util->SetViewport(0,0,dest->fakex,dest->fakey);
988993 This->util->DepthTest(false);
989994 DDSURFACEDESC2 ddsdSrc;
——@@ -1444,7 +1449,12 @@
14451450 This->outputs[0] = (void*)D3D_OK;
14461451 GLfloat color[4];
14471452 dwordto4float(dwColor,color);
1448 - This->util->SetFBO(target);
 1453+ do
 1454+ {
 1455+ if (This->util->SetFBO(target) == GL_FRAMEBUFFER_COMPLETE) break;
 1456+ if (!target->texture->internalformats[1]) break;
 1457+ TextureManager_FixTexture(This->texman, target->texture, (target->bigbuffer ? target->bigbuffer : target->buffer), &target->dirty);
 1458+ } while (1);
14491459 int clearbits = 0;
14501460 if(dwFlags & D3DCLEAR_TARGET)
14511461 {
——@@ -1815,8 +1825,14 @@
18161826 if(prog.uniforms[139]!= -1) This->ext->glUniform1f(prog.uniforms[139],device->viewport.dwX);
18171827 if(prog.uniforms[140]!= -1) This->ext->glUniform1f(prog.uniforms[140],device->viewport.dwY);
18181828 if(prog.uniforms[141]!= -1) This->ext->glUniform1i(prog.uniforms[141],device->renderstate[D3DRENDERSTATE_ALPHAREF]);
1819 - This->util->SetFBO(device->glDDS7);
1820 - This->util->SetViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
 1829+ do
 1830+ {
 1831+ if (This->util->SetFBO(device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
 1832+ if (!device->glDDS7->texture->internalformats[1]) break;
 1833+ TextureManager_FixTexture(This->texman, device->glDDS7->texture,
 1834+ (device->glDDS7->bigbuffer ? device->glDDS7->bigbuffer : device->glDDS7->buffer), &device->glDDS7->dirty);
 1835+ } while (1);
 1836+ This->util->SetViewport(device->viewport.dwX, device->viewport.dwY, device->viewport.dwWidth, device->viewport.dwHeight);
18211837 This->util->SetDepthRange(device->viewport.dvMinZ,device->viewport.dvMaxZ);
18221838 if(device->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) This->util->BlendEnable(true);
18231839 else This->util->BlendEnable(false);
Index: ddraw/glUtil.cpp
——@@ -147,41 +147,60 @@
148148 }
149149 }
150150
151 -void glUtil::SetFBO(glDirectDrawSurface7 *surface)
 151+GLenum glUtil::SetFBO(glDirectDrawSurface7 *surface)
152152 {
153 - if(!surface) SetFBO((FBO*)NULL);
154 - if(surface->zbuffer) SetFBO(&surface->fbo,surface->texture,surface->zbuffer->texture,surface->zbuffer->hasstencil);
155 - else SetFBO(&surface->fbo,surface->texture,NULL,false);
 153+ if(!surface) return SetFBO((FBO*)NULL);
 154+ if(surface->zbuffer) return SetFBO(&surface->fbo,surface->texture,surface->zbuffer->texture,surface->zbuffer->hasstencil);
 155+ else return SetFBO(&surface->fbo,surface->texture,NULL,false);
156156 }
157157
158 -void glUtil::SetFBO(FBO *fbo)
 158+GLenum glUtil::SetFBO(FBO *fbo)
159159 {
160 - if(fbo == currentfbo) return;
 160+ if (fbo == currentfbo)
 161+ {
 162+ if (fbo) return fbo->status;
 163+ else return GL_FRAMEBUFFER_COMPLETE;
 164+ }
161165 if(!fbo)
162166 {
163 - if(ext->GLEXT_ARB_framebuffer_object) ext->glBindFramebuffer(GL_FRAMEBUFFER,0);
 167+ if (ext->GLEXT_ARB_framebuffer_object) ext->glBindFramebuffer(GL_FRAMEBUFFER, 0);
164168 else if(ext->GLEXT_EXT_framebuffer_object) ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
165169 }
166170 else
167171 {
168 - if(ext->GLEXT_ARB_framebuffer_object) ext->glBindFramebuffer(GL_FRAMEBUFFER,fbo->fbo);
169 - else if(ext->GLEXT_EXT_framebuffer_object) ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo->fbo);
 172+ if (ext->GLEXT_ARB_framebuffer_object)
 173+ {
 174+ ext->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fbo);
 175+ fbo->status = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
 176+ }
 177+ else if (ext->GLEXT_EXT_framebuffer_object)
 178+ {
 179+ ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo);
 180+ fbo->status = ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 181+ }
170182 }
171183 currentfbo = fbo;
 184+ if (fbo) return fbo->status;
 185+ else
 186+ {
 187+ if (ext->GLEXT_ARB_framebuffer_object) return ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
 188+ else if (ext->GLEXT_EXT_framebuffer_object) return ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 189+ else return 0;
 190+ }
172191 }
173192
174 -void glUtil::SetFBO(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil)
 193+GLenum glUtil::SetFBO(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil)
175194 {
176195 if(!fbo)
177196 {
178 - SetFBO((FBO*)NULL);
179 - return;
 197+ return SetFBO((FBO*)NULL);
180198 }
181199 if(!fbo->fbo) InitFBO(fbo);
182 - if(!color) return;
 200+ if (!color) return GL_INVALID_ENUM;
183201 if((color != fbo->fbcolor) || (z != fbo->fbz) || (stencil != fbo->stencil))
184202 SetFBOTexture(fbo,color,z,stencil);
185 - if(fbo != currentfbo) SetFBO(fbo);
 203+ if(fbo != currentfbo) return SetFBO(fbo);
 204+ else return fbo->status;
186205 }
187206
188207 void glUtil::SetWrap(int level, DWORD coord, DWORD address, TextureManager *texman)
Index: ddraw/glUtil.h
——@@ -52,9 +52,9 @@
5353 void DeleteFBO(FBO *fbo);
5454 void SetFBOTexture(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil);
5555 void SetWrap(int level, DWORD coord, DWORD address, TextureManager *texman);
56 - void SetFBO(glDirectDrawSurface7 *surface);
57 - void SetFBO(FBO *fbo);
58 - void SetFBO(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil);
 56+ GLenum SetFBO(glDirectDrawSurface7 *surface);
 57+ GLenum SetFBO(FBO *fbo);
 58+ GLenum SetFBO(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil);
5959 void SetDepthComp(GLenum comp);
6060 void DepthWrite(bool enabled);
6161 void DepthTest(bool enabled);
Index: dxglcfg/dxglcfg.rc
——@@ -113,7 +113,7 @@
114114 VALUE "FileDescription", "DXGL Configuration Program"
115115 VALUE "FileVersion", DXGLVERSTRING
116116 VALUE "InternalName", "DXGL"
117 - VALUE "LegalCopyright", "Copyright © 2011-2012 William Feely"
 117+ VALUE "LegalCopyright", "Copyright © 2011-2014 William Feely"
118118 VALUE "OriginalFilename", "dxglcfg.exe"
119119 VALUE "ProductName", "DXGL"
120120 VALUE "ProductVersion", DXGLVERSTRING
Index: dxgltest/dxgltest.rc
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream