more code cleanup

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1622 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2008-12-21 21:02:43 +00:00
parent 1b0cb56d2b
commit a7c4697d22
16 changed files with 73 additions and 55 deletions

View File

@ -434,7 +434,9 @@ void BPWritten(int addr, int changes, int newval)
(int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x)),
(int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y))
};
//Need another rc here to get it to scale.
float MValueX = OpenGL_GetXmax();
float MValueY = OpenGL_GetYmax();
//Need another rc here to get it to scale.
//Here the bottom right is the out of the rectangle.
TRectangle multirc = {
(int)(bpmem.copyTexSrcXY.x * MValueX),

View File

@ -40,6 +40,7 @@ struct RECT
int gleft, gright, gtop, gbottom;
int nBackbufferWidth, nBackbufferHeight; // screen width
int nXoff, nYoff; // screen offset
float MValueX, MValueY;
float AR; // aspect ratio
#ifndef _WIN32
@ -67,6 +68,14 @@ void OpenGL_SwapBuffers()
#endif
}
float OpenGL_GetXmax() {
return MValueX;
}
float OpenGL_GetYmax() {
return MValueY;
}
int OpenGL_GetXoff() {
return nXoff;
}

View File

@ -118,6 +118,8 @@ extern GLWindow GLWin;
#endif
float OpenGL_GetXmax();
float OpenGL_GetYmax();
int OpenGL_GetXoff();
int OpenGL_GetYoff();
u32 OpenGL_GetWidth();

View File

@ -18,31 +18,37 @@ class GLWindow {
private:
u32 width, height;
int yOffset, xOffset;
float xMax, yMax;
public:
/* int screen;
int x, y;
unsigned int depth;*/
virtual void SwapBuffers() {};
virtual void SetWindowText(const char *text) {};
virtual bool PeekMessages() {return false;};
virtual void Update() {};;
virtual bool MakeCurrent() {return false;};
virtual void SetSize(u32 newWidth, u32 newHeight) {
u32 GetWidth() {return width;}
u32 GetHeight() {return height;}
void SetSize(u32 newWidth, u32 newHeight) {
width = newWidth;
height = newHeight;
}
int GetYoff() {return yOffset;}
int GetXoff() {return xOffset;}
void SetOffset(int x, int y) {
yOffset = y;
xOffset = x;
}
u32 GetWidth() {return width;}
u32 GetHeight() {return height;}
int GetYoff() {return yOffset;}
int GetXoff() {return xOffset;}
void SetMax(float x, float y) {
yMax = y;
xMax = x;
}
float GetXmax() {return xMax;}
float GetYmax() {return yMax;}
static bool valid() { return false; }
// bool GLwindow(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight) {};
// setResolution

View File

@ -83,7 +83,6 @@ static Renderer::RenderMode s_RenderMode = Renderer::RM_Normal;
static int s_nCurTarget = 0;
bool g_bBlendLogicOp = false;
float MValueX, MValueY; // Since it can Stretch to fit Window, we need two different multiplication values
int frameCount;
void HandleCgError(CGcontext ctx, CGerror err, void* appdata);
@ -587,7 +586,8 @@ bool Renderer::SetScissorRect()
{
int xoff = bpmem.scissorOffset.x * 2 - 342;
int yoff = bpmem.scissorOffset.y * 2 - 342;
float MValueX = OpenGL_GetXmax();
float MValueY = OpenGL_GetYmax();
float rc_left = bpmem.scissorTL.x - xoff - 342; // left = 0
rc_left *= MValueX;
if (rc_left < 0) rc_left = 0;

View File

@ -26,7 +26,6 @@
extern CGcontext g_cgcontext;
extern CGprofile g_cgvProf, g_cgfProf;
extern float MValueX, MValueY;
extern int frameCount;
class Renderer

View File

@ -24,14 +24,12 @@ void SDLWindow::Update() {
// AR = (float)surface->w / (float)surface->h;;
if (g_Config.bStretchToFit) {
MValueX = 1;
MValueY = 1;
SetMax(1,1);
SetOffset(0,0);
} else {
MValueX = 1.0f / Max;
MValueY = 1.0f / Max;
SetOffset((int)((surface->w - (640 * MValueX)) / 2),
(int)((surface->h - (480 * MValueY)) / 2));
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((surface->w - (640 * GetXmax())) / 2),
(int)((surface->h - (480 * GetYmax())) / 2));
}
SetSize(surface->w, surface->h);
@ -49,7 +47,7 @@ bool SDLWindow::MakeCurrent() {
// Fetch video info.
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
// TODO: Display an error message.
PanicAlert("Couldn't get video info");
SDL_Quit();
return false;
}
@ -62,7 +60,7 @@ bool SDLWindow::MakeCurrent() {
SDL_Surface *screen = SDL_SetVideoMode(GetWidth(), GetHeight(),
0, videoFlags);
if (!screen) {
//TODO : Display an error message
PanicAlert("Couldn't set video mode");
SDL_Quit();
return false;
}
@ -99,18 +97,17 @@ SDLWindow::SDLWindow(int _iwidth, int _iheight) {
float Max = (FactorW < FactorH) ? FactorH : FactorW;
if(g_Config.bStretchToFit) {
MValueX = 1.0f / FactorW;
MValueY = 1.0f / FactorH;
SetMax(1.0f / FactorW, 1.0f / FactorH);
SetOffset(0,0);
} else {
MValueX = 1.0f / Max;
MValueY = 1.0f / Max;
SetOffset((int)((_twidth - (640 * MValueX)) / 2),
(int)((_theight - (480 * MValueY)) / 2));
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((_twidth - (640 * GetXmax())) / 2),
(int)((_theight - (480 * GetYmax())) / 2));
}
//init sdl video
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
PanicAlert("Failed to init SDL");
//TODO : Display an error message
SDL_Quit();
// return NULL;

View File

@ -8,8 +8,6 @@
class SDLWindow : public GLWindow
{
public:
float MValueX, MValueY;
virtual void SwapBuffers();
virtual void SetWindowText(const char *text);
virtual bool PeekMessages();

View File

@ -583,6 +583,8 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
GL_REPORT_ERRORD();
glBegin(GL_QUADS);
float MValueX = OpenGL_GetXmax();
float MValueY = OpenGL_GetYmax();
glTexCoord2f((float)source->left * MValueX, Renderer::GetTargetHeight()-(float)source->bottom * MValueY); glVertex2f(-1,1);
glTexCoord2f((float)source->left * MValueX, Renderer::GetTargetHeight()-(float)source->top * MValueY); glVertex2f(-1,-1);
glTexCoord2f((float)source->right * MValueX, Renderer::GetTargetHeight()-(float)source->top * MValueY); glVertex2f(1,-1);

View File

@ -415,8 +415,10 @@ void VertexShaderMngr::SetConstants()
}
else
{
glViewport((int)(xfregs.rawViewport[3]-xfregs.rawViewport[0]-342-scissorXOff) * MValueX,
Renderer::GetTargetHeight()-((int)(xfregs.rawViewport[4]-xfregs.rawViewport[1]-342-scissorYOff)) * MValueY,
float MValueX = OpenGL_GetXmax();
float MValueY = OpenGL_GetYmax();
glViewport((int)(xfregs.rawViewport[3]-xfregs.rawViewport[0]-342-scissorXOff) * MValueX,
Renderer::GetTargetHeight()-((int)(xfregs.rawViewport[4]-xfregs.rawViewport[1]-342-scissorYOff)) * MValueY,
abs((int)(2 * xfregs.rawViewport[0])) * MValueX, abs((int)(2 * xfregs.rawViewport[1])) * MValueY);
}
glDepthRange((xfregs.rawViewport[5]- xfregs.rawViewport[2])/16777215.0f, xfregs.rawViewport[5]/16777215.0f);

View File

@ -19,15 +19,13 @@ void WXGLWindow::Update() {
float Max = (FactorW < FactorH) ? FactorH : FactorW;
//AR = (float)nBackbufferWidth / (float)nBackbufferHeight;
if (g_Config.bStretchToFit) {
MValueX = 1;
MValueY = 1;
if(g_Config.bStretchToFit) {
SetMax(1,1);
SetOffset(0,0);
} else {
MValueX = 1.0f / Max;
MValueY = 1.0f / Max;
SetOffset((int)((surface->w - (640 * MValueX)) / 2),
(int)((surface->h - (480 * MValueY)) / 2));
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((GetWidth() - (640 * GetXmax())) / 2),
(int)((GetHeight() - (480 * GetYmax())) / 2));
}
}
@ -65,15 +63,13 @@ WXGLWindow::WXGLWindow(int _iwidth, int _iheight) {
float FactorH = 480.0f / (float)_theight;
float Max = (FactorW < FactorH) ? FactorH : FactorW;
if(g_Config.bStretchToFit) {
MValueX = 1.0f / FactorW;
MValueY = 1.0f / FactorH;
if(g_Config.bStretchToFit) {
SetMax(1.0f / FactorW, 1.0f / FactorH);
SetOffset(0,0);
} else {
MValueX = 1.0f / Max;
MValueY = 1.0f / Max;
SetOffset((int)((_twidth - (640 * MValueX)) / 2),
(int)((_theight - (480 * MValueY)) / 2));
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};

View File

@ -15,8 +15,6 @@ private:
public:
float MValueX, MValueY;
virtual void SwapBuffers();
virtual void SetWindowText(const char *text);
virtual bool PeekMessages();

View File

@ -27,14 +27,12 @@ X11Window::X11Window(int _iwidth, int _iheight) {
float Max = (FactorW < FactorH) ? FactorH : FactorW;
if(g_Config.bStretchToFit) {
MValueX = 1.0f / FactorW;
MValueY = 1.0f / FactorH;
SetMax(1.0f / FactorW, 1.0f / FactorH);
SetOffset(0,0);
} else {
MValueX = 1.0f / Max;
MValueY = 1.0f / Max;
SetOffset((int)((_twidth - (640 * MValueX)) / 2),
(int)((_theight - (480 * MValueY)) / 2));
SetMax(1.0f / Max, 1.0f / Max);
SetOffset((int)((_twidth - (640 * GetXmax())) / 2),
(int)((_theight - (480 * GetYmax())) / 2));
}
XVisualInfo *vi;

View File

@ -23,7 +23,6 @@ public:
Bool fs;
Bool doubleBuffered;
XF86VidModeModeInfo deskMode;
float MValueX, MValueY;
virtual void SwapBuffers();
virtual void SetWindowText(const char *text);

View File

@ -111,6 +111,14 @@ int OpenGL_GetYoff() {
return glWin->GetYoff();
}
float OpenGL_GetXmax() {
return glWin->GetXmax();
}
float OpenGL_GetYmax() {
return glWin->GetYmax();
}
void OpenGL_AddBackends(ConfigDialog *frame) {
if(SDLWindow::valid())
frame->AddRenderBackend("SDL");

View File

@ -57,5 +57,7 @@ u32 OpenGL_GetHeight();
void OpenGL_SetSize(u32 width, u32 height);
int OpenGL_GetXoff();
int OpenGL_GetYoff();
float OpenGL_GetXmax();
float OpenGL_GetYmax();
#endif