X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fglwidget.cpp;h=af51f47ed3c8c093a6b6b41d85cde92732ceec0c;hb=83fce768d2c1e0e16691c092ea02d64e2b280fad;hp=d0e1934ed32a84a2a3499979522bd63ead26fe32;hpb=85fb2fe5f5a002a261e6b873b8393e085990a700;p=virtualjaguar diff --git a/src/gui/glwidget.cpp b/src/gui/glwidget.cpp index d0e1934..af51f47 100644 --- a/src/gui/glwidget.cpp +++ b/src/gui/glwidget.cpp @@ -1,42 +1,45 @@ // OpenGL implementation in Qt // Parts of this are blantantly ripped off from BSNES (thanks Byuu!) // -// by James L. Hammons +// by James Hammons // (C) 2010 Underground Software // -// JLH = James L. Hammons +// JLH = James Hammons // // Who When What // --- ---------- ------------------------------------------------------------- // JLH 01/14/2010 Created this file +// JLH 02/03/2013 Added "centered" fullscreen mode with correct aspect ratio // #include "glwidget.h" +#include "jaguar.h" #include "settings.h" #include "tom.h" -#include "video.h" + +#ifdef __GCCWIN32__ +// Apparently on win32, various OpenGL constants aren't pulled in. +#include +#endif + GLWidget::GLWidget(QWidget * parent/*= 0*/): QGLWidget(parent), texture(0), - textureWidth(0), textureHeight(0), buffer(0), rasterWidth(320), rasterHeight(240) + textureWidth(0), textureHeight(0), buffer(0), rasterWidth(340), rasterHeight(240), + offset(0) { -// tomDeviceWidth = rasterWidth; - tomDeviceWidth = 1024; // It has to be the texture width... - - // Set up the backbuffer - // To be safe, this should be 1280 * 625 * 2... - backbuffer = (uint32_t *)malloc(1280 * 625 * sizeof(uint32_t)); -// memset(backbuffer, 0x44, rasterWidth * - memset(backbuffer, 0xFF, 1024 * - (vjs.hardwareTypeNTSC ? rasterHeight : VIRTUAL_SCREEN_HEIGHT_PAL) - * sizeof(uint32_t)); + // Screen pitch has to be the texture width (in 32-bit pixels)... + JaguarSetScreenPitch(1024); } + GLWidget::~GLWidget() { - free(backbuffer); + if (buffer) + delete[] buffer; } + void GLWidget::initializeGL() { format().setDoubleBuffer(true); @@ -52,18 +55,29 @@ void GLWidget::initializeGL() glClearColor(0.0, 0.0, 0.0, 0.0); } + void GLWidget::paintGL() { //kludge -rasterHeight = (vjs.hardwareTypeNTSC ? 240 : 256); +rasterHeight = (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL); + + // If we're in fullscreen mode, we take the value of the screen width as + // set by MainWin, since it may be wider than what our aspect ratio allows. + // In that case, we adjust the viewport over so that it's centered on the + // screen. Otherwise, we simply take the width from our width() funtion + // which will always be correct in windowed mode. + +// unsigned outputWidth = width(); + if (!fullscreen) + outputWidth = width(); - unsigned outputWidth = width(); unsigned outputHeight = height(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, outputWidth, 0, outputHeight, -1.0, 1.0); - glViewport(0, 0, outputWidth, outputHeight); +// glViewport(0, 0, outputWidth, outputHeight); + glViewport(0 + offset, 0, outputWidth, outputHeight); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -82,24 +96,28 @@ rasterHeight = (vjs.hardwareTypeNTSC ? 240 : 256); unsigned v = outputHeight; glBegin(GL_TRIANGLE_STRIP); +#if 1 glTexCoord2f(0, 0); glVertex3i(0, v, 0); glTexCoord2f(w, 0); glVertex3i(u, v, 0); glTexCoord2f(0, h); glVertex3i(0, 0, 0); glTexCoord2f(w, h); glVertex3i(u, 0, 0); +#else + glTexCoord2f(0, 0); glVertex3i(0 + offset, v, 0); + glTexCoord2f(w, 0); glVertex3i(u + offset, v, 0); + glTexCoord2f(0, h); glVertex3i(0 + offset, 0, 0); + glTexCoord2f(w, h); glVertex3i(u + offset, 0, 0); +#endif glEnd(); } + void GLWidget::resizeGL(int width, int height) { if (width > textureWidth || height > textureHeight) { -// textureWidth = max(width, textureWidth); -// textureHeight = max(height, textureHeight); -// Seems that power of 2 sizes are still mandatory... - textureWidth = 1024;//(width > textureWidth ? width : textureWidth); - textureHeight = 512;//(height > textureHeight ? height : textureHeight); -// textureWidth = (width > textureWidth ? width : textureWidth); -// textureHeight = (height > textureHeight ? height : textureHeight); + // Seems that power of 2 sizes are still mandatory... + textureWidth = 1024; + textureHeight = 512; #if 0 printf("Resizing: new texture width/height = %i x %i\n", textureWidth, textureHeight); printf("Resizing: new raster width/height = %i x %i\n", rasterWidth, rasterHeight); @@ -112,16 +130,20 @@ printf("Resizing: new raster width/height = %i x %i\n", rasterWidth, rasterHeigh } buffer = new uint32_t[textureWidth * textureHeight]; + JaguarSetScreenBuffer(buffer); + +//??? +memset(buffer, 0xFF, textureWidth * textureHeight * sizeof(uint32_t)); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glPixelStorei(GL_UNPACK_ROW_LENGTH, textureWidth); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); -// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL); } } + #if 0 class RubyGLWidget: public QGLWidget {