Index: ddraw/glRenderer.cpp |
— | — | @@ -36,7 +36,9 @@ |
37 | 37 |
|
38 | 38 | WNDCLASSEXA wndclass;
|
39 | 39 | bool wndclasscreated = false;
|
40 | | -
|
| 40 | +GLuint backbuffer = 0;
|
| 41 | +int backx = 0;
|
| 42 | +int backy = 0;
|
41 | 43 | BltVertex bltvertices[4];
|
42 | 44 | const GLushort bltindices[4] = {0,1,2,3};
|
43 | 45 |
|
— | — | @@ -342,47 +344,6 @@ |
343 | 345 | TranslateMessage(&Msg);
|
344 | 346 | DispatchMessage(&Msg);
|
345 | 347 | }
|
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);*/
|
387 | 348 | if(hRenderWnd) DestroyWindow(hRenderWnd);
|
388 | 349 | hRenderWnd = NULL;
|
389 | 350 | wndbusy = false;
|
— | — | @@ -400,7 +361,7 @@ |
401 | 362 | wndclass.lpfnWndProc = RenderWndProc;
|
402 | 363 | wndclass.cbClsExtra = 0;
|
403 | 364 | wndclass.cbWndExtra = 0;
|
404 | | - wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);//(HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
|
| 365 | + wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
|
405 | 366 | wndclass.hIcon = NULL;
|
406 | 367 | wndclass.hCursor = NULL;
|
407 | 368 | wndclass.hbrBackground = NULL;
|
— | — | @@ -705,6 +666,50 @@ |
706 | 667 | return texture;
|
707 | 668 | }
|
708 | 669 |
|
| 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 | +
|
709 | 714 | void glRenderer::_DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
|
710 | 715 | {
|
711 | 716 | RECT r,r2;
|
— | — | @@ -720,6 +725,7 @@ |
721 | 726 | SetSwap(swapinterval);
|
722 | 727 | LONG sizes[6];
|
723 | 728 | GLfloat view[4];
|
| 729 | + GLint viewport[4];
|
724 | 730 | if(src->dirty & 1)
|
725 | 731 | {
|
726 | 732 | _UploadTexture(src->buffer,src->bigbuffer,texture,src->ddsd.dwWidth,src->ddsd.dwHeight,
|
— | — | @@ -733,7 +739,9 @@ |
734 | 740 | if(ddInterface->GetFullscreen())
|
735 | 741 | {
|
736 | 742 | 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];
|
738 | 746 | view[0] = (GLfloat)-(sizes[4]-sizes[0])/2;
|
739 | 747 | view[1] = (GLfloat)(sizes[4]-sizes[0])/2+sizes[0];
|
740 | 748 | view[2] = (GLfloat)(sizes[5]-sizes[1])/2+sizes[1];
|
— | — | @@ -741,7 +749,9 @@ |
742 | 750 | }
|
743 | 751 | else
|
744 | 752 | {
|
745 | | - glViewport(0,0,viewrect->right,viewrect->bottom);
|
| 753 | + viewport[0] = viewport[1] = 0;
|
| 754 | + viewport[2] = viewrect->right;
|
| 755 | + viewport[3] = viewrect->bottom;
|
746 | 756 | ClientToScreen(hRenderWnd,(LPPOINT)&viewrect->left);
|
747 | 757 | ClientToScreen(hRenderWnd,(LPPOINT)&viewrect->right);
|
748 | 758 | view[0] = (GLfloat)viewrect->left;
|
— | — | @@ -772,6 +782,16 @@ |
773 | 783 | glActiveTexture(GL_TEXTURE1);
|
774 | 784 | glBindTexture(GL_TEXTURE_2D,paltex);
|
775 | 785 | 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 | + }
|
776 | 796 | }
|
777 | 797 | else
|
778 | 798 | {
|
— | — | @@ -780,7 +800,9 @@ |
781 | 801 | glBindTexture(GL_TEXTURE_2D,texture);
|
782 | 802 | GLuint prog = GetProgram() & 0xFFFFFFFF;
|
783 | 803 | GLint texloc = glGetUniformLocation(prog,"Texture");
|
| 804 | + glUniform1i(texloc,0);
|
784 | 805 | }
|
| 806 | + glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
|
785 | 807 | GLuint prog = GetProgram();
|
786 | 808 | GLint viewloc = glGetUniformLocation(prog,"view");
|
787 | 809 | glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
|
— | — | @@ -877,6 +899,7 @@ |
878 | 900 | glDeleteBuffers(1,&PBO);
|
879 | 901 | PBO = 0;
|
880 | 902 | }
|
| 903 | + if(backbuffer) glDeleteTextures(1,&backbuffer);
|
881 | 904 | wglMakeCurrent(NULL,NULL);
|
882 | 905 | wglDeleteContext(hRC);
|
883 | 906 | };
|
Index: ddraw/glRenderer.h |
— | — | @@ -89,6 +89,7 @@ |
90 | 90 | GLuint _MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
|
91 | 91 | void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
|
92 | 92 | void _DeleteTexture(GLuint texture);
|
| 93 | + void _DrawBackbuffer(GLuint *texture, int x, int y);
|
93 | 94 | glDirectDraw7 *ddInterface;
|
94 | 95 | void* inputs[32];
|
95 | 96 | void* outputs[32];
|