DXGL r92 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r91‎ | r92 | r93 >
Date:18:03, 28 January 2012
Author:admin
Status:new
Tags:
Comment:
Add bilinear filtering to 8-bit modes
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -36,7 +36,9 @@
3737
3838 WNDCLASSEXA wndclass;
3939 bool wndclasscreated = false;
40 -
 40+GLuint backbuffer = 0;
 41+int backx = 0;
 42+int backy = 0;
4143 BltVertex bltvertices[4];
4244 const GLushort bltindices[4] = {0,1,2,3};
4345
@@ -342,47 +344,6 @@
343345 TranslateMessage(&Msg);
344346 DispatchMessage(&Msg);
345347 }
346 -/* do
347 - {
348 - WaitForSingleObject(EventSend,INFINITE);
349 - switch(eventnum)
350 - {
351 - case GLEVENT_DELETE:
352 - break;
353 - case GLEVENT_CREATE:
354 - outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
355 - (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8]);
356 - SetEvent(EventWait);
357 - break;
358 - case GLEVENT_UPLOAD:
359 - outputs[0] = (void*)_UploadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
360 - (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
361 - (int)inputs[10],(int)inputs[11],(int)inputs[12]);
362 - SetEvent(EventWait);
363 - break;
364 - case GLEVENT_DOWNLOAD:
365 - outputs[0] = (void*)_DownloadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
366 - (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
367 - (int)inputs[10],(int)inputs[11]);
368 - SetEvent(EventWait);
369 - break;
370 - case GLEVENT_DELETETEX:
371 - _DeleteTexture((GLuint)inputs[0]);
372 - SetEvent(EventWait);
373 - break;
374 - case GLEVENT_BLT:
375 - outputs[0] = (void*)_Blt((LPRECT)inputs[0],(glDirectDrawSurface7*)inputs[1],(glDirectDrawSurface7*)inputs[2],
376 - (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
377 - SetEvent(EventWait);
378 - break;
379 - case GLEVENT_DRAWSCREEN:
380 - _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
381 - SetEvent(EventWait);
382 - break;
383 - default:
384 - break;
385 - }
386 - } while(eventnum != GLEVENT_DELETE);*/
387348 if(hRenderWnd) DestroyWindow(hRenderWnd);
388349 hRenderWnd = NULL;
389350 wndbusy = false;
@@ -400,7 +361,7 @@
401362 wndclass.lpfnWndProc = RenderWndProc;
402363 wndclass.cbClsExtra = 0;
403364 wndclass.cbWndExtra = 0;
404 - wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);//(HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
 365+ wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
405366 wndclass.hIcon = NULL;
406367 wndclass.hCursor = NULL;
407368 wndclass.hbrBackground = NULL;
@@ -705,6 +666,50 @@
706667 return texture;
707668 }
708669
 670+void glRenderer::_DrawBackbuffer(GLuint *texture, int x, int y)
 671+{
 672+ GLfloat view[4];
 673+ glActiveTexture(GL_TEXTURE0);
 674+ if(!backbuffer)
 675+ {
 676+ backbuffer = _MakeTexture(GL_LINEAR,GL_LINEAR,GL_CLAMP,GL_CLAMP,x,y,GL_BGRA,GL_UNSIGNED_BYTE,GL_RGBA8);
 677+ backx = x;
 678+ backy = y;
 679+ }
 680+ if((backx != x) || (backy != y))
 681+ {
 682+ glBindTexture(GL_TEXTURE_2D,backbuffer);
 683+ glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,x,y,0,GL_BGRA,GL_UNSIGNED_BYTE,NULL);
 684+ backx = x;
 685+ backy = y;
 686+ }
 687+ SetFBO(backbuffer,0,false);
 688+ view[0] = view[2] = 0;
 689+ view[1] = (GLfloat)x;
 690+ view[3] = (GLfloat)y;
 691+ glViewport(0,0,x,y);
 692+ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
 693+ glBindTexture(GL_TEXTURE_2D,*texture);
 694+ *texture = backbuffer;
 695+ GLuint prog = GetProgram();
 696+ GLint viewloc = glGetUniformLocation(prog,"view");
 697+ glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
 698+
 699+ bltvertices[0].s = bltvertices[0].t = bltvertices[1].t = bltvertices[2].s = 1.;
 700+ bltvertices[1].s = bltvertices[2].t = bltvertices[3].s = bltvertices[3].t = 0.;
 701+ bltvertices[0].y = bltvertices[1].y = bltvertices[1].x = bltvertices[3].x = 0.;
 702+ bltvertices[0].x = bltvertices[2].x = (float)x;
 703+ bltvertices[2].y = bltvertices[3].y = (float)y;
 704+ GLint xyloc = glGetAttribLocation(prog,"xy");
 705+ glEnableVertexAttribArray(xyloc);
 706+ glVertexAttribPointer(xyloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
 707+ GLint stloc = glGetAttribLocation(prog,"st");
 708+ glEnableVertexAttribArray(stloc);
 709+ glVertexAttribPointer(stloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
 710+ glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
 711+ SetFBO(0,0,false);
 712+}
 713+
709714 void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
710715 {
711716 RECT r,r2;
@@ -720,6 +725,7 @@
721726 SetSwap(swapinterval);
722727 LONG sizes[6];
723728 GLfloat view[4];
 729+ GLint viewport[4];
724730 if(src->dirty & 1)
725731 {
726732 _UploadTexture(src->buffer,src->bigbuffer,texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
@@ -733,7 +739,9 @@
734740 if(ddInterface->GetFullscreen())
735741 {
736742 ddInterface->GetSizes(sizes);
737 - glViewport(0,0,sizes[4],sizes[5]);
 743+ viewport[0] = viewport[1] = 0;
 744+ viewport[2] = sizes[4];
 745+ viewport[3] = sizes[5];
738746 view[0] = (GLfloat)-(sizes[4]-sizes[0])/2;
739747 view[1] = (GLfloat)(sizes[4]-sizes[0])/2+sizes[0];
740748 view[2] = (GLfloat)(sizes[5]-sizes[1])/2+sizes[1];
@@ -741,7 +749,9 @@
742750 }
743751 else
744752 {
745 - glViewport(0,0,viewrect->right,viewrect->bottom);
 753+ viewport[0] = viewport[1] = 0;
 754+ viewport[2] = viewrect->right;
 755+ viewport[3] = viewrect->bottom;
746756 ClientToScreen(hRenderWnd,(LPPOINT)&viewrect->left);
747757 ClientToScreen(hRenderWnd,(LPPOINT)&viewrect->right);
748758 view[0] = (GLfloat)viewrect->left;
@@ -772,6 +782,16 @@
773783 glActiveTexture(GL_TEXTURE1);
774784 glBindTexture(GL_TEXTURE_2D,paltex);
775785 glActiveTexture(GL_TEXTURE0);
 786+ if(dxglcfg.scalingfilter)
 787+ {
 788+ _DrawBackbuffer(&texture,dest->fakex,dest->fakey);
 789+ SetShader(PROG_TEXTURE,true);
 790+ glEnable(GL_TEXTURE_2D);
 791+ glBindTexture(GL_TEXTURE_2D,texture);
 792+ GLuint prog = GetProgram() & 0xFFFFFFFF;
 793+ GLint texloc = glGetUniformLocation(prog,"Texture");
 794+ glUniform1i(texloc,0);
 795+ }
776796 }
777797 else
778798 {
@@ -780,7 +800,9 @@
781801 glBindTexture(GL_TEXTURE_2D,texture);
782802 GLuint prog = GetProgram() & 0xFFFFFFFF;
783803 GLint texloc = glGetUniformLocation(prog,"Texture");
 804+ glUniform1i(texloc,0);
784805 }
 806+ glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
785807 GLuint prog = GetProgram();
786808 GLint viewloc = glGetUniformLocation(prog,"view");
787809 glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
@@ -877,6 +899,7 @@
878900 glDeleteBuffers(1,&PBO);
879901 PBO = 0;
880902 }
 903+ if(backbuffer) glDeleteTextures(1,&backbuffer);
881904 wglMakeCurrent(NULL,NULL);
882905 wglDeleteContext(hRC);
883906 };
Index: ddraw/glRenderer.h
@@ -89,6 +89,7 @@
9090 GLuint _MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
9191 void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
9292 void _DeleteTexture(GLuint texture);
 93+ void _DrawBackbuffer(GLuint *texture, int x, int y);
9394 glDirectDraw7 *ddInterface;
9495 void* inputs[32];
9596 void* outputs[32];