From: Spacy <sp...@us...> - 2006-08-11 10:58:42
|
Update of /cvsroot/vba/VisualBoyAdvance/src/win32 In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv26812/src/win32 Modified Files: Direct3D.cpp MainWndOptions.cpp OpenGL.cpp Log Message: No more border corruption in OpenGL. OpenGL supports aspect ratio correct scaling, OpenGL & Direct3D instantly respond to MaxScale / StretchToFit commands. Index: MainWndOptions.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/win32/MainWndOptions.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MainWndOptions.cpp 6 Aug 2006 12:40:35 -0000 1.14 --- MainWndOptions.cpp 11 Aug 2006 10:58:39 -0000 1.15 *************** *** 1762,1765 **** --- 1762,1769 ---- dlg.DoModal(); + + if( theApp.display ) { + theApp.display->setOption( _T("maxScale"), theApp.fsMaxScale ); + } } Index: OpenGL.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/win32/OpenGL.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** OpenGL.cpp 5 Aug 2006 17:30:22 -0000 1.9 --- OpenGL.cpp 11 Aug 2006 10:58:39 -0000 1.10 *************** *** 60,63 **** --- 60,64 ---- float size; u8 *filterData; + RECT destRect; bool failed; *************** *** 66,69 **** --- 67,71 ---- void updateFiltering( int value ); void setVSync( int interval = 1 ); + void calculateDestRect( int w, int h ); public: *************** *** 368,371 **** --- 370,375 ---- void OpenGLDisplay::render() { + clear(); + int pitch = theApp.filterWidth * 4 + 4; u8 *data = pix + ( theApp.sizeX + 1 ) * 4; *************** *** 386,395 **** // Texturemap complete texture to surface // so we have free scaling and antialiasing ! int mult = 1; ! if( theApp.filterFunction) { ! glPixelStorei( GL_UNPACK_ROW_LENGTH, 2 * theApp.sizeX ); mult = 2; } else { glPixelStorei( GL_UNPACK_ROW_LENGTH, theApp.sizeX + 1 ); } --- 390,400 ---- // Texturemap complete texture to surface // so we have free scaling and antialiasing ! int mult; ! if( theApp.filterFunction ) { ! glPixelStorei( GL_UNPACK_ROW_LENGTH, theApp.sizeX << 1 ); mult = 2; } else { glPixelStorei( GL_UNPACK_ROW_LENGTH, theApp.sizeX + 1 ); + mult = 1; } *************** *** 404,429 **** GL_UNSIGNED_BYTE, data ); ! if( theApp.glType == 0 ) { glBegin( GL_TRIANGLE_STRIP ); glTexCoord2f( 0.0f, 0.0f ); glVertex3i( 0, 0, 0 ); ! glTexCoord2f( (float)mult * (float)theApp.sizeX / size, 0.0f ); glVertex3i( theApp.surfaceSizeX, 0, 0 ); ! glTexCoord2f( 0.0f, (float)mult * (float)theApp.sizeY / size ); glVertex3i( 0, theApp.surfaceSizeY, 0 ); ! glTexCoord2f( (float)mult * (float)theApp.sizeX / size, (float)mult * (float)theApp.sizeY / size ); glVertex3i( theApp.surfaceSizeX, theApp.surfaceSizeY, 0 ); glEnd(); } else { glBegin( GL_QUADS ); glTexCoord2f( 0.0f, 0.0f ); glVertex3i( 0, 0, 0 ); ! glTexCoord2f( (float)mult * (float)theApp.sizeX / size, 0.0f ); glVertex3i( theApp.surfaceSizeX, 0, 0 ); ! glTexCoord2f( (float)mult * (float)theApp.sizeX / size, (float)mult * (float)theApp.sizeY / size ); glVertex3i( theApp.surfaceSizeX, theApp.surfaceSizeY, 0 ); ! glTexCoord2f( 0.0f, (float)mult * (float)theApp.sizeY / size ); glVertex3i( 0, theApp.surfaceSizeY, 0 ); glEnd(); } --- 409,444 ---- GL_UNSIGNED_BYTE, data ); ! if( theApp.glType == 0 ) { glBegin( GL_TRIANGLE_STRIP ); + glTexCoord2f( 0.0f, 0.0f ); glVertex3i( 0, 0, 0 ); ! ! glTexCoord2f( (float)(mult * theApp.sizeX) / size, 0.0f ); glVertex3i( theApp.surfaceSizeX, 0, 0 ); ! ! glTexCoord2f( 0.0f, (float)(mult * theApp.sizeY) / size ); glVertex3i( 0, theApp.surfaceSizeY, 0 ); ! ! glTexCoord2f( (float)(mult * theApp.sizeX) / size, (float)(mult * theApp.sizeY) / size ); glVertex3i( theApp.surfaceSizeX, theApp.surfaceSizeY, 0 ); + glEnd(); } else { glBegin( GL_QUADS ); + glTexCoord2f( 0.0f, 0.0f ); glVertex3i( 0, 0, 0 ); ! ! glTexCoord2f( (float)(mult * theApp.sizeX) / size, 0.0f ); glVertex3i( theApp.surfaceSizeX, 0, 0 ); ! ! glTexCoord2f( (float)(mult * theApp.sizeX) / size, (float)(mult * theApp.sizeY) / size ); glVertex3i( theApp.surfaceSizeX, theApp.surfaceSizeY, 0 ); ! ! glTexCoord2f( 0.0f, (float)(mult * theApp.sizeY) / size ); glVertex3i( 0, theApp.surfaceSizeY, 0 ); + glEnd(); } *************** *** 479,482 **** --- 494,500 ---- break; } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); } *************** *** 484,499 **** void OpenGLDisplay::initializeMatrices( int w, int h ) { ! glViewport( 0, 0, w, h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( ! 0.0f, ! (GLdouble)(w), ! (GLdouble)(h), ! 0.0f, 0.0f, 1.0f ); ! glMatrixMode(GL_MODELVIEW); glLoadIdentity(); --- 502,526 ---- void OpenGLDisplay::initializeMatrices( int w, int h ) { ! if( theApp.fullScreenStretch ) { ! glViewport( 0, 0, w, h ); ! } else { ! calculateDestRect( w, h ); ! glViewport( ! destRect.left, ! destRect.top, ! destRect.right - destRect.left, ! destRect.bottom - destRect.top ); ! } glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( ! /* left */ 1.0f, ! /* right */ (GLdouble)(w - 1), ! /* bottom */ (GLdouble)(h - 1), ! /* top */ 1.0f, 0.0f, 1.0f ); ! glMatrixMode(GL_MODELVIEW); glLoadIdentity(); *************** *** 578,581 **** --- 605,633 ---- + void OpenGLDisplay::calculateDestRect( int w, int h ) + { + float scaleX = (float)w / (float)width; + float scaleY = (float)h / (float)height; + float min = (scaleX < scaleY) ? scaleX : scaleY; + if( theApp.fsMaxScale && (min > theApp.fsMaxScale) ) { + min = (float)theApp.fsMaxScale; + } + destRect.left = 0; + destRect.top = 0; + destRect.right = (LONG)(width * min); + destRect.bottom = (LONG)(height * min); + if( destRect.right != w ) { + LONG diff = (w - destRect.right) / 2; + destRect.left += diff; + destRect.right += diff; + } + if( destRect.bottom != h ) { + LONG diff = (h - destRect.bottom) / 2; + destRect.top += diff; + destRect.bottom += diff; + } + } + + void OpenGLDisplay::setOption( const char *option, int value ) { *************** *** 587,590 **** --- 639,650 ---- updateFiltering( value ); } + + if( !_tcscmp( option, _T("maxScale") ) ) { + initializeMatrices( theApp.dest.right, theApp.dest.bottom ); + } + + if( !_tcscmp( option, _T("fullScreenStretch") ) ) { + initializeMatrices( theApp.dest.right, theApp.dest.bottom ); + } } Index: Direct3D.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/win32/Direct3D.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Direct3D.cpp 5 Aug 2006 17:30:07 -0000 1.13 --- Direct3D.cpp 11 Aug 2006 10:58:39 -0000 1.14 *************** *** 386,391 **** copyImage( pix, lr.pBits, theApp.sizeX, theApp.sizeY, lr.Pitch, systemColorDepth ); } else { ! theApp.filterFunction( pix + (theApp.filterWidth * (systemColorDepth>>3)) + 4, ! theApp.filterWidth * (systemColorDepth>>3) + 4, (u8*)theApp.delta, (u8*)lr.pBits, --- 386,392 ---- copyImage( pix, lr.pBits, theApp.sizeX, theApp.sizeY, lr.Pitch, systemColorDepth ); } else { ! u32 pitch = theApp.filterWidth * (systemColorDepth>>3) + 4; ! theApp.filterFunction( pix + pitch, ! pitch, (u8*)theApp.delta, (u8*)lr.pBits, *************** *** 602,605 **** --- 603,610 ---- } } + + if( !_tcscmp( option, _T("maxScale") ) ) { + calculateDestRect(); + } } |