Some testgl work

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1812 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2009-01-06 20:54:47 +00:00
parent fa3c6c1247
commit ca3ebe743f
8 changed files with 105 additions and 174 deletions

View File

@ -1,6 +1,7 @@
#ifndef _GLWINDOW_H #ifndef _GLWINDOW_H
#define _GLWINDOW_H #define _GLWINDOW_H
#include <vector>
#include "Common.h" #include "Common.h"
#include "EventHandler.h" #include "EventHandler.h"
#include "Globals.h" #include "Globals.h"
@ -21,28 +22,70 @@ enum OGL_Props {
OGL_PROP_COUNT OGL_PROP_COUNT
}; };
struct res {
u32 x;
u32 y;
};
class GLWindow { class GLWindow {
private: private:
u32 width, height; u32 xWin, yWin; // windows size
int yOffset, xOffset; int xOffset, yOffset; // offset in window
float xMax, yMax; float xMax, yMax; // ???
u32 xRender, yRender; // render area
bool properties[OGL_PROP_COUNT]; bool properties[OGL_PROP_COUNT];
protected:
res origRes, currFullRes, currWinRes;
std::vector<res> fullResolutions;
std::vector<res> winResolutions;
virtual void SetRender(u32 x, u32 y) {
xRender = x;
yRender = y;
}
public: public:
virtual void SwapBuffers() {}; virtual void SwapBuffers() {};
virtual void SetWindowText(const char *text) {}; virtual void SetWindowText(const char *text) {};
virtual bool PeekMessages() {return false;}; virtual bool PeekMessages() {return false;};
virtual void Update() {};; virtual void Update() {};
virtual bool MakeCurrent() {return false;}; virtual bool MakeCurrent() {return false;};
bool getProperty(OGL_Props prop) {return properties[prop];} virtual void updateDim() {
virtual bool setProperty(OGL_Props prop, bool value) if (GetProperty(OGL_FULLSCREEN))
SetWinSize(currFullRes.x, currFullRes.y);
else
SetWinSize(currWinRes.x, currWinRes.y);
float FactorX = 640.0f / (float)GetXwin();
float FactorY = 480.0f / (float)GetYwin();
float Max = (FactorX < FactorY) ? FactorX : FactorY;
if(GetProperty(OGL_STRETCHTOFIT)) {
SetMax(1.0f / FactorX, 1.0f / FactorY);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((GetXwin() - (640 * GetXmax())) / 2),
(int)((GetYwin() - (480 * GetYmax())) / 2));
}
}
bool GetProperty(OGL_Props prop) {return properties[prop];}
virtual bool SetProperty(OGL_Props prop, bool value)
{return properties[prop] = value;} {return properties[prop] = value;}
u32 GetWidth() {return width;}
u32 GetHeight() {return height;} u32 GetXrender() {return xRender;}
void SetSize(u32 newWidth, u32 newHeight) { u32 GetYrender() {return yRender;}
width = newWidth;
height = newHeight; u32 GetXwin() {return xWin;}
u32 GetYwin() {return yWin;}
void SetWinSize(u32 x, u32 y) {
xWin = x;
yWin = y;
} }
int GetYoff() {return yOffset;} int GetYoff() {return yOffset;}
@ -56,11 +99,28 @@ public:
yMax = y; yMax = y;
xMax = x; xMax = x;
} }
float GetXmax() {return xMax;} float GetXmax() {return xMax;}
float GetYmax() {return yMax;} float GetYmax() {return yMax;}
static bool valid() { return false; } static bool valid() { return false;}
// bool GLwindow(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight) {};
GLWindow() {
// Load defaults
sscanf(g_Config.iFSResolution, "%dx%d",
&currFullRes.x, &currFullRes.y);
sscanf(g_Config.iWindowedRes, "%dx%d",
&currWinRes.x, &currWinRes.y);
SetProperty(OGL_FULLSCREEN, g_Config.bFullscreen);
SetProperty(OGL_STRETCHTOFIT, g_Config.bFullscreen);
SetProperty(OGL_KEEPRATIO, g_Config.bFullscreen);
updateDim();
}
// setResolution // setResolution
// resolution iter // resolution iter
}; };

View File

@ -21,21 +21,8 @@ void SDLWindow::Update() {
return; return;
} }
SetSize(surface->w, surface->h); // SetSize(surface->w, surface->h);
updateDim();
float FactorW = 640.0f / (float)GetWidth();
float FactorH = 480.0f / (float)GetHeight();
float Max = (FactorW < FactorH) ? FactorH : FactorW;
// AR = (float)surface->w / (float)surface->h;;
if (g_Config.bStretchToFit) {
SetMax(1,1);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((GetWidth() - (640 * GetXmax())) / 2),
(int)((GetHeight() - (480 * GetYmax())) / 2));
}
} }
@ -61,7 +48,7 @@ bool SDLWindow::MakeCurrent() {
| ( g_Config.bFullscreen ? SDL_FULLSCREEN : 0); | ( g_Config.bFullscreen ? SDL_FULLSCREEN : 0);
// Set vide mode. // Set vide mode.
// TODO: Can we use this field or is a separate field needed? // TODO: Can we use this field or is a separate field needed?
SDL_Surface *screen = SDL_SetVideoMode(GetWidth(), GetHeight(), SDL_Surface *screen = SDL_SetVideoMode(GetXwin(), GetYwin(),
0, videoFlags); 0, videoFlags);
if (!screen) { if (!screen) {
PanicAlert("Couldn't set video mode"); PanicAlert("Couldn't set video mode");
@ -76,38 +63,7 @@ SDLWindow::~SDLWindow() {
SDL_Quit(); SDL_Quit();
} }
SDLWindow::SDLWindow(int _iwidth, int _iheight) { SDLWindow::SDLWindow() : GLWindow() {
int _twidth, _theight;
if(g_Config.bFullscreen) {
if(strlen(g_Config.iFSResolution) > 1) {
sscanf(g_Config.iFSResolution, "%dx%d", &_twidth, &_theight);
} else { // No full screen reso set, fall back to default reso
_twidth = _iwidth;
_theight = _iheight;
}
} else { // Going Windowed
if(strlen(g_Config.iWindowedRes) > 1) {
sscanf(g_Config.iWindowedRes, "%dx%d", &_twidth, &_theight);
} else {// No Window reso set, fall back to default
_twidth = _iwidth;
_theight = _iheight;
}
}
SetSize(_iwidth, _theight);
float FactorW = 640.0f / (float)_twidth;
float FactorH = 480.0f / (float)_theight;
float Max = (FactorW < FactorH) ? FactorH : FactorW;
if(g_Config.bStretchToFit) {
SetMax(1.0f / FactorW, 1.0f / FactorH);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((_twidth - (640 * GetXmax())) / 2),
(int)((_theight - (480 * GetYmax())) / 2));
}
//init sdl video //init sdl video
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {

View File

@ -16,14 +16,14 @@ public:
static bool valid() { return true; } static bool valid() { return true; }
~SDLWindow(); ~SDLWindow();
SDLWindow(int _iwidth, int _iheight); SDLWindow();
}; };
#else #else
class SDLWindow : public GLWindow class SDLWindow : public GLWindow
{ {
public: public:
SDLWindow(int _iwidth, int _iheight) {} SDLWindow() {}
}; };
#endif #endif
#endif #endif

View File

@ -14,19 +14,7 @@ bool WXGLWindow::PeekMessages() {
} }
void WXGLWindow::Update() { void WXGLWindow::Update() {
float FactorW = 640.0f / (float)GetWidth(); updateDim();
float FactorH = 480.0f / (float)GetHeight();
float Max = (FactorW < FactorH) ? FactorH : FactorW;
//AR = (float)nBackbufferWidth / (float)nBackbufferHeight;
if(g_Config.bStretchToFit) {
SetMax(1,1);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((GetWidth() - (640 * GetXmax())) / 2),
(int)((GetHeight() - (480 * GetYmax())) / 2));
}
} }
bool WXGLWindow::MakeCurrent() { bool WXGLWindow::MakeCurrent() {
@ -39,38 +27,9 @@ WXGLWindow::~WXGLWindow() {
delete frame; delete frame;
} }
WXGLWindow::WXGLWindow(int _iwidth, int _iheight) { WXGLWindow::WXGLWindow() : GLWindow() {
int _twidth, _theight;
if(g_Config.bFullscreen) {
if(strlen(g_Config.iFSResolution) > 1) {
sscanf(g_Config.iFSResolution, "%dx%d", &_twidth, &_theight);
} else {// No full screen reso set, fall back to default reso
_twidth = _iwidth;
_theight = _iheight;
}
} else {// Going Windowed
if(strlen(g_Config.iWindowedRes) > 1) {
sscanf(g_Config.iWindowedRes, "%dx%d", &_twidth, &_theight);
} else {// No Window reso set, fall back to default
_twidth = _iwidth;
_theight = _iheight;
}
}
SetSize(_iwidth, _theight); updateDim();
float FactorW = 640.0f / (float)_twidth;
float FactorH = 480.0f / (float)_theight;
float Max = (FactorW < FactorH) ? FactorH : FactorW;
if(g_Config.bStretchToFit) {
SetMax(1.0f / FactorW, 1.0f / FactorH);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((_twidth - (640 * GetXmax())) / 2),
(int)((_theight - (480 * GetYmax())) / 2));
}
int args[] = {WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0}; int args[] = {WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0};

View File

@ -23,14 +23,14 @@ public:
static bool valid() { return true; } static bool valid() { return true; }
~WXGLWindow(); ~WXGLWindow();
WXGLWindow(int _iwidth, int _iheight); WXGLWindow();
}; };
#else #else
class WXGLWindow : public GLWindow class WXGLWindow : public GLWindow
{ {
public: public:
WXGLWindow(int _iwidth, int _iheight) {} WXGLWindow() {}
}; };
#endif #endif
#endif #endif

View File

@ -1,42 +1,9 @@
#include "X11Window.h" #include "X11Window.h"
static EventHandler *eventHandler = EventHandler::GetInstance(); static EventHandler *eventHandler = EventHandler::GetInstance();
X11Window::X11Window(int _iwidth, int _iheight) {
int _twidth, _theight;
if(g_Config.bFullscreen) {
if(strlen(g_Config.iFSResolution) > 1) {
sscanf(g_Config.iFSResolution, "%dx%d", &_twidth, &_theight);
}
else { // No full screen reso set, fall back to default {
_twidth = _iwidth;
_theight = _iheight;
}
} else {// Going Windowed
if(strlen(g_Config.iWindowedRes) > 1) {
sscanf(g_Config.iWindowedRes, "%dx%d", &_twidth, &_theight);
}
else { // No Window reso set, fall back to default
_twidth = _iwidth;
_theight = _iheight;
}
}
SetSize(_twidth, _theight);
float FactorW = 640.0f / (float)_twidth;
float FactorH = 480.0f / (float)_theight;
float Max = (FactorW < FactorH) ? FactorH : FactorW;
if(g_Config.bStretchToFit) {
SetMax(1.0f / FactorW, 1.0f / FactorH);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((_twidth - (640 * GetXmax())) / 2),
(int)((_theight - (480 * GetYmax())) / 2));
}
X11Window::X11Window() : GLWindow() {
XVisualInfo *vi; XVisualInfo *vi;
Colormap cmap; Colormap cmap;
int dpyWidth, dpyHeight; int dpyWidth, dpyHeight;
@ -115,8 +82,8 @@ X11Window::X11Window(int _iwidth, int _iheight) {
deskMode = *modes[0]; deskMode = *modes[0];
/* look for mode with requested resolution */ /* look for mode with requested resolution */
for (int i = 0; i < modeNum; i++) { for (int i = 0; i < modeNum; i++) {
if ((modes[i]->hdisplay == _twidth) && if ((modes[i]->hdisplay == GetXwin()) &&
(modes[i]->vdisplay == _theight)) { (modes[i]->vdisplay == GetYwin())) {
bestMode = i; bestMode = i;
} }
} }
@ -158,8 +125,8 @@ X11Window::X11Window(int _iwidth, int _iheight) {
attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
KeyReleaseMask | ButtonReleaseMask | KeyReleaseMask | ButtonReleaseMask |
StructureNotifyMask | ResizeRedirectMask; StructureNotifyMask | ResizeRedirectMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, _twidth, win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, GetXwin(),
_theight, 0, vi->depth, InputOutput, vi->visual, GetYwin(), 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &attr); CWBorderPixel | CWColormap | CWEventMask, &attr);
// only set window title and handle wm_delete_events if in windowed mode // only set window title and handle wm_delete_events if in windowed mode
wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", True); wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
@ -286,21 +253,7 @@ void X11Window::Update() {
} }
eventHandler->Update(); eventHandler->Update();
updateDim();
float FactorW = 640.0f / (float)GetWidth();
float FactorH = 480.0f / (float)GetHeight();
float Max = (FactorW < FactorH) ? FactorH : FactorW;
// AR = (float)surface->w / (float)surface->h;;
if (g_Config.bStretchToFit) {
SetMax(1,1);
SetOffset(0,0);
} else {
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((GetWidth() - (640 * GetXmax())) / 2),
(int)((GetHeight() - (480 * GetYmax())) / 2));
}
} }
bool X11Window::MakeCurrent() { bool X11Window::MakeCurrent() {
@ -313,7 +266,7 @@ bool X11Window::MakeCurrent() {
glXMakeCurrent(dpy, win, ctx); glXMakeCurrent(dpy, win, ctx);
XGetGeometry(dpy, win, &winDummy, &x, &y, XGetGeometry(dpy, win, &winDummy, &x, &y,
&w, &h, &borderDummy, &depth); &w, &h, &borderDummy, &depth);
SetSize(w, h);
ERROR_LOG("GLWin Depth %d", depth); ERROR_LOG("GLWin Depth %d", depth);
if (glXIsDirect(dpy, ctx)) if (glXIsDirect(dpy, ctx))
ERROR_LOG("you have Direct Rendering!"); ERROR_LOG("you have Direct Rendering!");

View File

@ -33,7 +33,7 @@ public:
static bool valid() { return true; } static bool valid() { return true; }
~X11Window(); ~X11Window();
X11Window(int _iwidth, int _iheight); X11Window();
static sf::Key::Code KeysymToSF(KeySym Sym); static sf::Key::Code KeysymToSF(KeySym Sym);
private: private:
void ProcessEvent(XEvent WinEvent); void ProcessEvent(XEvent WinEvent);
@ -43,7 +43,7 @@ private:
class X11Window : public GLWindow class X11Window : public GLWindow
{ {
public: public:
X11Window(int _iwidth, int _iheight) {} X11Window() {}
}; };
#endif #endif
#endif #endif

View File

@ -56,15 +56,18 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize,
g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay; g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay;
if (strncasecmp(g_Config.iBackend, "sdl", 10) == 0) if (strncasecmp(g_Config.iBackend, "sdl", 10) == 0)
glWin = new SDLWindow(width, height); glWin = new SDLWindow();
else if (strncasecmp(g_Config.iBackend, "x11", 10) == 0) else if (strncasecmp(g_Config.iBackend, "x11", 10) == 0)
glWin = new X11Window(width, height); glWin = new X11Window();
else if (strncasecmp(g_Config.iBackend, "wxgl", 10) == 0) else if (strncasecmp(g_Config.iBackend, "wxgl", 10) == 0)
glWin = new WXGLWindow(width, height); glWin = new WXGLWindow();
else else
PanicAlert("Invalid backend %s", g_Config.iBackend); PanicAlert("Invalid backend %s", g_Config.iBackend);
return (glWin?true:false); if (! glWin)
return false;
return true;
} }
bool OpenGL_MakeCurrent() bool OpenGL_MakeCurrent()
@ -92,15 +95,15 @@ void OpenGL_Shutdown()
} }
u32 OpenGL_GetWidth() { u32 OpenGL_GetWidth() {
return glWin->GetWidth(); return glWin->GetXwin();
} }
u32 OpenGL_GetHeight() { u32 OpenGL_GetHeight() {
return glWin->GetHeight(); return glWin->GetYwin();
} }
void OpenGL_SetSize(u32 width, u32 height) { void OpenGL_SetSize(u32 width, u32 height) {
glWin->SetSize(width, height); glWin->SetWinSize(width, height);
} }
int OpenGL_GetXoff() { int OpenGL_GetXoff() {