DXGL r702 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r701‎ | r702 | r703 >
Date:17:07, 24 April 2017
Author:admin
Status:new
Tags:
Comment:
First attempt (don't use) to implement first pass scaling.
Fix saving first pass scaling in dxglcfg
Modified paths:
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /dxglcfg/dxglcfg.c (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.c
@@ -530,6 +530,8 @@
531531 else cfgmask = &defaultmask;
532532 memset(&defaultmask,1,sizeof(DXGLCFG));
533533 defaultmask.aspect = 1.0f;
 534+ defaultmask.firstscalex = 1.0f;
 535+ defaultmask.firstscaley = 1.0f;
534536 WriteDWORD(hKey,cfg->scaler,cfgmask->scaler,_T("ScalingMode"));
535537 WriteDWORD(hKey, cfg->fullmode, cfgmask->fullmode, _T("FullscreenWindowMode"));
536538 WriteBool(hKey,cfg->colormode,cfgmask->colormode,_T("ChangeColorDepth"));
Index: ddraw/glDirectDraw.cpp
@@ -1627,7 +1627,7 @@
16281628 DEBUG("IDirectDraw::SetDisplayMode: implement multiple monitors\n");
16291629 DEVMODE newmode,newmode2;
16301630 DEVMODE currmode;
1631 - float aspect,xmul,ymul;
 1631+ float aspect,xmul,ymul,xscale,yscale;
16321632 LONG error;
16331633 DWORD flags;
16341634 if(!oldmode.dmSize)
@@ -1638,6 +1638,19 @@
16391639 currmode.dmSize = sizeof(DEVMODE);
16401640 EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&currmode);
16411641 this->currmode.dmSize = 0;
 1642+ if (_isnan(dxglcfg.firstscalex) || _isnan(dxglcfg.firstscaley) ||
 1643+ (dxglcfg.firstscalex < 0.25f) || (dxglcfg.firstscaley < 0.25f))
 1644+ {
 1645+ if (dwWidth <= 400) xscale = 2;
 1646+ else xscale = 1;
 1647+ if (dwHeight <= 240) yscale = 2;
 1648+ else yscale = 1;
 1649+ }
 1650+ else
 1651+ {
 1652+ xscale = dxglcfg.firstscalex;
 1653+ yscale = dxglcfg.firstscaley;
 1654+ }
16421655 switch (dxglcfg.fullmode)
16431656 {
16441657 case 0:
@@ -1650,8 +1663,8 @@
16511664 default:
16521665 newmode.dmSize = sizeof(DEVMODE);
16531666 newmode.dmDriverExtra = 0;
1654 - newmode.dmPelsWidth = dwWidth;
1655 - newmode.dmPelsHeight = dwHeight;
 1667+ newmode.dmPelsWidth = dwWidth * xscale;
 1668+ newmode.dmPelsHeight = dwHeight * yscale;
16561669 if (dxglcfg.colormode)
16571670 newmode.dmBitsPerPel = dwBPP;
16581671 else newmode.dmBitsPerPel = currmode.dmBitsPerPel;
@@ -1665,8 +1678,10 @@
16661679 {
16671680 case DISP_CHANGE_SUCCESSFUL:
16681681 if (fullscreen) this->currmode = newmode;
1669 - internalx = primaryx = screenx = newmode.dmPelsWidth;
1670 - internaly = primaryy = screeny = newmode.dmPelsHeight;
 1682+ primaryx = screenx = newmode.dmPelsWidth;
 1683+ primaryy = screeny = newmode.dmPelsHeight;
 1684+ internalx = newmode.dmPelsWidth * xscale;
 1685+ internaly = newmode.dmPelsHeight * yscale;
16711686 internalbpp = screenbpp = newmode.dmBitsPerPel;
16721687 primarybpp = dwBPP;
16731688 if (dwRefreshRate) internalrefresh = primaryrefresh = screenrefresh = dwRefreshRate;
Index: ddraw/glRenderer.cpp
@@ -2790,6 +2790,19 @@
27912791 //glRenderer__InitCommandBuffer(This, &This->cmd2, width * height * (NextMultipleOf8(bpp) / 8));
27922792 //BufferObject_Map(This->cmd1.vertices, GL_ARRAY_BUFFER, GL_WRITE_ONLY);
27932793 //BufferObject_Map(This->cmd1.indices, GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
 2794+ if (_isnan(dxglcfg.firstscalex) || _isnan(dxglcfg.firstscaley) ||
 2795+ (dxglcfg.firstscalex < 0.25f) || (dxglcfg.firstscaley < 0.25f))
 2796+ {
 2797+ if (width <= 400) This->firstscalex = 2.0f;
 2798+ else This->firstscaley = 1.0f;
 2799+ if (height <= 240) This->firstscaley = 2;
 2800+ else This->firstscaley = 1;
 2801+ }
 2802+ else
 2803+ {
 2804+ This->firstscalex = dxglcfg.firstscalex;
 2805+ This->firstscaley = dxglcfg.firstscaley;
 2806+ }
27942807 TRACE_SYSINFO();
27952808 return TRUE;
27962809 }
@@ -3197,44 +3210,50 @@
31983211 glTexture__FinishCreate(texture);
31993212 }
32003213
3201 -void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype)
 3214+void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype, BOOL paletted)
32023215 {
32033216 GLfloat view[4];
32043217 DDSURFACEDESC2 ddsd;
 3218+ DWORD x2, y2;
 3219+ x2 = x * This->firstscalex;
 3220+ y2 = y * This->firstscaley;
32053221 glUtil_SetActiveTexture(This->util,0);
32063222 if(!This->backbuffer)
32073223 {
32083224 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
32093225 memcpy(&ddsd, &ddsdbackbuffer, sizeof(DDSURFACEDESC2));
3210 - ddsd.dwWidth = x;
3211 - ddsd.lPitch = x * 4;
3212 - ddsd.dwHeight = y;
3213 - glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
 3226+ ddsd.dwWidth = x2;
 3227+ ddsd.lPitch = x2 * 4;
 3228+ ddsd.dwHeight = y2;
 3229+ glTexture_Create(&ddsd, &This->backbuffer, This, x2, y2, FALSE, TRUE);
32143230 }
3215 - if((This->backbuffer->levels[0].ddsd.dwWidth != x) || (This->backbuffer->levels[0].ddsd.dwHeight != y))
 3231+ if((This->backbuffer->levels[0].ddsd.dwWidth != x2) || (This->backbuffer->levels[0].ddsd.dwHeight != y2))
32163232 {
32173233 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
32183234 ddsd.dwSize = sizeof(DDSURFACEDESC2);
3219 - ddsd.dwWidth = x;
3220 - ddsd.dwHeight = y;
 3235+ ddsd.dwWidth = x2;
 3236+ ddsd.dwHeight = y2;
32213237 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
32223238 glTexture__SetSurfaceDesc(This->backbuffer, &ddsd);
32233239 }
32243240 glUtil_SetFBOTextures(This->util,&This->fbo,This->backbuffer,NULL,0,0,FALSE);
32253241 view[0] = view[2] = 0;
3226 - view[1] = (GLfloat)x;
3227 - view[3] = (GLfloat)y;
3228 - glUtil_SetViewport(This->util,0,0,x,y);
 3242+ view[1] = (GLfloat)x2;
 3243+ view[3] = (GLfloat)y2;
 3244+ glUtil_SetViewport(This->util,0,0,x2,y2);
32293245 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
32303246 glUtil_SetTexture(This->util,0,*texture);
32313247 *texture = This->backbuffer;
 3248+ if (!paletted && dxglcfg.firstscalefilter == 1)
 3249+ glTexture__SetFilter(*texture, 0, GL_LINEAR, GL_LINEAR, This);
 3250+ else glTexture__SetFilter(*texture, 0, GL_NEAREST, GL_NEAREST, This);
32323251 if(This->ext->GLEXT_ARB_sampler_objects) glTexture__SetFilter(NULL,0,GL_LINEAR,GL_LINEAR, This);
32333252 This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
32343253 This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
32353254 This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
32363255 This->bltvertices[0].y = This->bltvertices[1].y = This->bltvertices[1].x = This->bltvertices[3].x = 0.;
3237 - This->bltvertices[0].x = This->bltvertices[2].x = (float)x;
3238 - This->bltvertices[2].y = This->bltvertices[3].y = (float)y;
 3256+ This->bltvertices[0].x = This->bltvertices[2].x = (float)x2;
 3257+ This->bltvertices[2].y = This->bltvertices[3].y = (float)y2;
32393258 glUtil_EnableArray(This->util,This->shaders->shaders[progtype].pos,TRUE);
32403259 This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos,2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].x);
32413260 glUtil_EnableArray(This->util,This->shaders->shaders[progtype].texcoord,TRUE);
@@ -3365,13 +3384,13 @@
33663385 This->ext->glUniform1i(This->shaders->shaders[progtype].pal,9);
33673386 glUtil_SetTexture(This->util,8,texture);
33683387 glUtil_SetTexture(This->util,9,paltex);
3369 - if(dxglcfg.scalingfilter)
 3388+ if(dxglcfg.scalingfilter || (This->firstscalex != 1.0f) || (This->firstscaley != 1.0f))
33703389 {
3371 - glRenderer__DrawBackbuffer(This,&texture,texture->bigwidth,texture->bigheight,progtype);
 3390+ glRenderer__DrawBackbuffer(This,&texture,texture->bigwidth,texture->bigheight,progtype,TRUE);
33723391 ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
33733392 progtype = PROG_TEXTURE;
3374 - glUtil_SetTexture(This->util,0,texture);
3375 - This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
 3393+ glUtil_SetTexture(This->util,8,texture);
 3394+ This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,8);
33763395 }
33773396 if(This->ext->GLEXT_ARB_sampler_objects)
33783397 {
@@ -3381,6 +3400,14 @@
33823401 }
33833402 else
33843403 {
 3404+ if ((This->firstscalex != 1.0f) || (This->firstscaley != 1.0f))
 3405+ {
 3406+ glRenderer__DrawBackbuffer(This, &texture, texture->bigwidth, texture->bigheight, progtype, FALSE);
 3407+ ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, 0);
 3408+ progtype = PROG_TEXTURE;
 3409+ glUtil_SetTexture(This->util, 8, texture);
 3410+ This->ext->glUniform1i(This->shaders->shaders[progtype].tex0, 0);
 3411+ }
33853412 ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
33863413 progtype = PROG_TEXTURE;
33873414 glUtil_SetTexture(This->util,8,texture);
@@ -3702,7 +3729,19 @@
37033730 glRenderer__SetSwap(This,0);
37043731 glUtil_SetViewport(This->util, 0, 0, width, height);
37053732 }
3706 -
 3733+ if (_isnan(dxglcfg.firstscalex) || _isnan(dxglcfg.firstscaley) ||
 3734+ (dxglcfg.firstscalex < 0.25f) || (dxglcfg.firstscaley < 0.25f))
 3735+ {
 3736+ if (width <= 400) This->firstscalex = 2.0f;
 3737+ else This->firstscaley = 1.0f;
 3738+ if (height <= 240) This->firstscaley = 2;
 3739+ else This->firstscaley = 1;
 3740+ }
 3741+ else
 3742+ {
 3743+ This->firstscalex = dxglcfg.firstscalex;
 3744+ This->firstscaley = dxglcfg.firstscaley;
 3745+ }
37073746 SetEvent(This->busy);
37083747 }
37093748
Index: ddraw/glRenderer.h
@@ -159,6 +159,7 @@
160160 DWORD last_fvf;
161161 GLsizei fvf_stride;
162162 BOOL mode_3d;
 163+ float firstscalex, firstscaley;
163164 } glRenderer;
164165
165166 HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *cmd, BOOL inner, BOOL wait);
@@ -206,7 +207,7 @@
207208 void glRenderer__MakeTexture(glRenderer *This, glTexture *texture);
208209 void glRenderer__DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous, BOOL setsync);
209210 void glRenderer__DeleteTexture(glRenderer *This, glTexture *texture);
210 -void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype);
 211+void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype, BOOL paletted);
211212 void glRenderer__DrawBackbufferRect(glRenderer *This, glTexture *texture, RECT srcrect, int progtype);
212213 void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y);
213214 void glRenderer__Clear(glRenderer *This, ClearCommand *cmd);
Index: dxglcfg/dxglcfg.c
@@ -469,6 +469,7 @@
470470 *ptr = 0;
471471 *x = _ttof(buffer);
472472 *y = _ttof(ptr + 1);
 473+ if ((*x >= 0.25f) && (*y < 0.25f)) *y = *x;
473474 return;
474475 }
475476 else
Index: dxglcfg2/dxglcfg2.c
@@ -523,6 +523,7 @@
524524 *ptr = 0;
525525 *x = _ttof(buffer);
526526 *y = _ttof(ptr + 1);
 527+ if ((*x >= 0.25f) && (*y < 0.25f)) *y = *x;
527528 return;
528529 }
529530 else