From 2ec3cd6694b5d748258ebb3550ced31fcdfb2864 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Fri, 26 Dec 2008 12:47:32 +0000 Subject: [PATCH] Move VertexShaderManager too. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1688 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../VideoCommon/Src/PixelShaderManager.cpp | 4 +- Source/Core/VideoCommon/Src/SConscript | 1 + .../VideoCommon}/Src/VertexShaderManager.cpp | 115 +++--------------- .../VideoCommon}/Src/VertexShaderManager.h | 2 +- Source/Core/VideoCommon/Src/VideoCommon.h | 28 +++++ Source/Core/VideoCommon/VideoCommon.vcproj | 8 ++ .../Plugin_VideoOGL/Plugin_VideoOGL.vcproj | 8 -- Source/Plugins/Plugin_VideoOGL/Src/Globals.h | 29 ----- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 90 ++++++++++++++ Source/Plugins/Plugin_VideoOGL/Src/SConscript | 1 - .../Plugin_VideoOGL/Src/TextureConverter.cpp | 8 +- .../Plugin_VideoOGL/Src/VertexManager.cpp | 2 +- 12 files changed, 153 insertions(+), 143 deletions(-) rename Source/{Plugins/Plugin_VideoOGL => Core/VideoCommon}/Src/VertexShaderManager.cpp (81%) rename Source/{Plugins/Plugin_VideoOGL => Core/VideoCommon}/Src/VertexShaderManager.h (96%) diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 0b9f4ab7c9..ba2c528e11 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -23,9 +23,7 @@ #include "Statistics.h" #include "PixelShaderManager.h" - -// TODO: move logging to VideoCommon. Until then - -#define PRIM_LOG(x, ...) +#include "VideoCommon.h" static int s_nColorsChanged[2]; // 0 - regular colors, 1 - k colors static int s_nIndTexMtxChanged = 0; diff --git a/Source/Core/VideoCommon/Src/SConscript b/Source/Core/VideoCommon/Src/SConscript index cc19c260eb..0b8c44cbc4 100644 --- a/Source/Core/VideoCommon/Src/SConscript +++ b/Source/Core/VideoCommon/Src/SConscript @@ -13,6 +13,7 @@ files = [ "PixelShader.cpp", "PixelShaderManager.cpp", "VertexShader.cpp", + "VertexShaderManager.cpp", "ImageWrite.cpp", "Statistics.cpp", "Fifo.cpp", diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp similarity index 81% rename from Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp rename to Source/Core/VideoCommon/Src/VertexShaderManager.cpp index b21a0b7d1c..48e9128298 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -16,20 +16,24 @@ // http://code.google.com/p/dolphin-emu/ #include "Common.h" -#include "Globals.h" #include "Profiler.h" #include #include "Statistics.h" -#include "Config.h" -#include "Render.h" #include "VertexShader.h" #include "VertexShaderManager.h" -#include "VertexManager.h" -#include "VertexLoader.h" +#include "BPMemory.h" +#include "CPMemory.h" #include "XFMemory.h" +#include "VideoCommon.h" + +// Temporary ugly declaration. +namespace VertexManager +{ + void Flush(); +} static float s_fMaterials[16]; @@ -41,6 +45,7 @@ static int nNormalMatricesChanged[2]; // min,max static int nPostTransformMatricesChanged[2]; // min,max static int nLightsChanged[2]; // min,max +void UpdateViewport(); void VertexShaderManager::Init() { @@ -64,7 +69,7 @@ void VertexShaderManager::Shutdown() // ======================================================================================= // Syncs the shader constant buffers with xfmem // ---------------- -void VertexShaderManager::SetConstants() +void VertexShaderManager::SetConstants(bool proj_hax_1, bool proj_hax_2) { //nTransformMatricesChanged[0] = 0; nTransformMatricesChanged[1] = 256; //nNormalMatricesChanged[0] = 0; nNormalMatricesChanged[1] = 96; @@ -185,90 +190,8 @@ void VertexShaderManager::SetConstants() if (bViewportChanged) { bViewportChanged = false; - // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) - // [0] = width/2 - // [1] = height/2 - // [2] = 16777215 * (farz - nearz) - // [3] = xorig + width/2 + 342 - // [4] = yorig + height/2 + 342 - // [5] = 16777215 * farz - - /*INFO_LOG("view: topleft=(%f,%f), wh=(%f,%f), z=(%f,%f)\n", - rawViewport[3]-rawViewport[0]-342, rawViewport[4]+rawViewport[1]-342, - 2 * rawViewport[0], 2 * rawViewport[1], - (rawViewport[5] - rawViewport[2]) / 16777215.0f, rawViewport[5] / 16777215.0f);*/ - - // Keep aspect ratio at 4:3 - // rawViewport[0] = 320, rawViewport[1] = -240 - int scissorXOff = bpmem.scissorOffset.x * 2 - 342; - int scissorYOff = bpmem.scissorOffset.y * 2 - 342; - float fourThree = 4.0f / 3.0f; - float wAdj, hAdj; - float actualRatiow, actualRatioh; - int overfl; - int xoffs = 0, yoffs = 0; - int wid, hei, actualWid, actualHei; - - int winw = OpenGL_GetWidth(); - int winh = OpenGL_GetHeight(); - float ratio = (float)winw / (float)winh / fourThree; - if (g_Config.bKeepAR) - { - // Check if height or width is the limiting factor - if (ratio > 1) // then we are to wide and have to limit the width - { - wAdj = ratio; - hAdj = 1; - - wid = ceil(fabs(2 * xfregs.rawViewport[0]) / wAdj); - hei = ceil(fabs(2 * xfregs.rawViewport[1]) / hAdj); - - actualWid = ceil((float)winw / ratio); - actualRatiow = (float)actualWid / (float)wid; // the picture versus the screen - overfl = (winw - actualWid) / actualRatiow; - xoffs = overfl / 2; - } - else // the window is to high, we have to limit the height - { - ratio = 1 / ratio; - - wAdj = 1; - hAdj = ratio; - - wid = ceil(fabs(2 * xfregs.rawViewport[0]) / wAdj); - hei = ceil(fabs(2 * xfregs.rawViewport[1]) / hAdj); - - actualHei = ceil((float)winh / ratio); - actualRatioh = (float)actualHei / (float)hei; // the picture versus the screen - overfl = (winh - actualHei) / actualRatioh; - yoffs = overfl / 2; - } - } - else - { - wid = ceil(fabs(2 * xfregs.rawViewport[0])); - hei = ceil(fabs(2 * xfregs.rawViewport[1])); - } - - if (g_Config.bStretchToFit) - { - glViewport( - (int)(xfregs.rawViewport[3]-xfregs.rawViewport[0]-342-scissorXOff) + xoffs, - Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4]-xfregs.rawViewport[1]-342-scissorYOff)) + yoffs, - wid, // width - hei // height - ); - } - else - { - 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); + // This is so implementation-dependent that we can't have it here. + UpdateViewport(); } if (bProjectionChanged) { @@ -292,15 +215,15 @@ void VertexShaderManager::SetConstants() //---------Projection[11]--------- // No hacks - if ((!g_Config.bProjectionHax1 && !g_Config.bProjectionHax2) || (g_Config.bProjectionHax1 && g_Config.bProjectionHax2)) + if ((!proj_hax_1 && !proj_hax_2) || (proj_hax_1 && proj_hax_2)) g_fProjectionMatrix[11] = -(0.0f - xfregs.rawProjection[5]); // Before R945 Hack - if (g_Config.bProjectionHax1 && !g_Config.bProjectionHax2) + if (proj_hax_1 && !proj_hax_2) g_fProjectionMatrix[11] = -(1.0f - xfregs.rawProjection[5]); // R844 Hack - if (!g_Config.bProjectionHax1 && g_Config.bProjectionHax2) + if (!proj_hax_1 && proj_hax_2) g_fProjectionMatrix[11] = xfregs.rawProjection[5]; //-------------------------------- @@ -328,15 +251,15 @@ void VertexShaderManager::SetConstants() //---------Projection[11]--------- // No hacks - if ((!g_Config.bProjectionHax1 && !g_Config.bProjectionHax2) || (g_Config.bProjectionHax1 && g_Config.bProjectionHax2)) + if ((!proj_hax_1 && !proj_hax_2) || (proj_hax_1 && proj_hax_2)) g_fProjectionMatrix[11] = -(-1.0f - xfregs.rawProjection[5]); // Before R945 Hack - if (g_Config.bProjectionHax1 && !g_Config.bProjectionHax2) + if (proj_hax_1 && !proj_hax_2) g_fProjectionMatrix[11] = -(0.0f - xfregs.rawProjection[5]); // R844 Hack - if (!g_Config.bProjectionHax1 && g_Config.bProjectionHax2) + if (!proj_hax_1 && proj_hax_2) g_fProjectionMatrix[11] = -xfregs.rawProjection[5]; //-------------------------------- diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h b/Source/Core/VideoCommon/Src/VertexShaderManager.h similarity index 96% rename from Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h rename to Source/Core/VideoCommon/Src/VertexShaderManager.h index 30275d2641..10d308a66d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderManager.h +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.h @@ -28,7 +28,7 @@ public: static void Shutdown(); // constant management - static void SetConstants(); + static void SetConstants(bool proj_hax_1, bool proj_hax_2); static void SetViewport(float* _Viewport); static void SetViewportChanged(); diff --git a/Source/Core/VideoCommon/Src/VideoCommon.h b/Source/Core/VideoCommon/Src/VideoCommon.h index 1f891631f3..cea4bcaf00 100644 --- a/Source/Core/VideoCommon/Src/VideoCommon.h +++ b/Source/Core/VideoCommon/Src/VideoCommon.h @@ -21,6 +21,17 @@ #include "Common.h" #include "pluginspecs_video.h" +enum { + EFB_WIDTH = 640, + EFB_HEIGHT = 528, +}; + +enum { + XFB_WIDTH = 640, + XFB_HEIGHT = 480, // 528 is max height ... ? or 538? + // TODO: figure out what to do with PAL +}; + extern SVideoInitialize g_VideoInitialize; void DebugLog(const char* _fmt, ...); @@ -57,4 +68,21 @@ struct TRectangle int left, top, right, bottom; }; +void DebugLog(const char* _fmt, ...); +void __Log(const char *format, ...); +void __Log(int type, const char *format, ...); +void HandleGLError(); + +#define ERROR_LOG __Log + +#if defined(_DEBUG) || defined(DEBUGFAST) +#define INFO_LOG if( g_Config.iLog & CONF_LOG ) __Log +#define PRIM_LOG if( g_Config.iLog & CONF_PRIMLOG ) __Log +#define DEBUG_LOG __Log +#else +#define INFO_LOG(...) +#define PRIM_LOG(...) +#define DEBUG_LOG(...) +#endif + #endif // _VIDEOCOMMON_H diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj index 08a68aec10..c5471a6164 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcproj +++ b/Source/Core/VideoCommon/VideoCommon.vcproj @@ -547,6 +547,14 @@ RelativePath=".\Src\VertexLoaderManager.h" > + + + + diff --git a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj index 16d69afd52..b6ad681dc7 100644 --- a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj +++ b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj @@ -860,14 +860,6 @@ RelativePath=".\Src\VertexShaderCache.h" > - - - - 1) // then we are to wide and have to limit the width + { + wAdj = ratio; + hAdj = 1; + + wid = ceil(fabs(2 * xfregs.rawViewport[0]) / wAdj); + hei = ceil(fabs(2 * xfregs.rawViewport[1]) / hAdj); + + actualWid = ceil((float)winw / ratio); + actualRatiow = (float)actualWid / (float)wid; // the picture versus the screen + overfl = (winw - actualWid) / actualRatiow; + xoffs = overfl / 2; + } + else // the window is to high, we have to limit the height + { + ratio = 1 / ratio; + + wAdj = 1; + hAdj = ratio; + + wid = ceil(fabs(2 * xfregs.rawViewport[0]) / wAdj); + hei = ceil(fabs(2 * xfregs.rawViewport[1]) / hAdj); + + actualHei = ceil((float)winh / ratio); + actualRatioh = (float)actualHei / (float)hei; // the picture versus the screen + overfl = (winh - actualHei) / actualRatioh; + yoffs = overfl / 2; + } + } + else + { + wid = ceil(fabs(2 * xfregs.rawViewport[0])); + hei = ceil(fabs(2 * xfregs.rawViewport[1])); + } + + if (g_Config.bStretchToFit) + { + glViewport( + (int)(xfregs.rawViewport[3]-xfregs.rawViewport[0]-342-scissorXOff) + xoffs, + Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4]-xfregs.rawViewport[1]-342-scissorYOff)) + yoffs, + wid, // width + hei // height + ); + } + else + { + 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); +} \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript index 34506467c7..c30b5aa9e6 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript +++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript @@ -25,7 +25,6 @@ files = [ 'VertexLoader_Position.cpp', 'VertexLoader_TextCoord.cpp', 'VertexLoaderManager.cpp', - 'VertexShaderManager.cpp', 'PixelShaderCache.cpp', 'VertexShaderCache.cpp', 'TextureConverter.cpp', diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index c32e415208..4a7b45b406 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -156,7 +156,7 @@ void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc, GL_REPORT_ERRORD(); // TODO: this is real slow. try using a pixel buffer object. - glReadPixels(0, 0, dstFmtWidth, dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr); + glReadPixels(0, 0, (GLsizei)dstFmtWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr); GL_REPORT_ERRORD(); Renderer::SetFramebuffer(0); @@ -191,7 +191,7 @@ void DecodeToTexture(u8* srcAddr, int srcWidth, int srcHeight, GLuint destTextur glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture); // TODO: this is slow. try using a pixel buffer object. - glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, srcFmtWidth, srcHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, srcAddr); + glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, (GLsizei)srcFmtWidth, (GLsizei)srcHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, srcAddr); TextureMngr::EnableTexRECT(0); for (int i = 1; i < 8; ++i) @@ -205,10 +205,10 @@ void DecodeToTexture(u8* srcAddr, int srcWidth, int srcHeight, GLuint destTextur GL_REPORT_ERRORD(); glBegin(GL_QUADS); - glTexCoord2f(srcFmtWidth, srcHeight); glVertex2f(1,-1); + glTexCoord2f(srcFmtWidth, (float)srcHeight); glVertex2f(1,-1); glTexCoord2f(srcFmtWidth, 0); glVertex2f(1,1); glTexCoord2f(0, 0); glVertex2f(-1,1); - glTexCoord2f(0, srcHeight); glVertex2f(-1,-1); + glTexCoord2f(0, (float)srcHeight); glVertex2f(-1,-1); glEnd(); // reset state diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index edb5cce746..b2d65971b6 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -248,7 +248,7 @@ void Flush() } // set global constants - VertexShaderManager::SetConstants(); + VertexShaderManager::SetConstants(g_Config.bProjectionHax1, g_Config.bProjectionHax2); PixelShaderManager::SetConstants(); // finally bind