Move VertexShaderManager too.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1688 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-12-26 12:47:32 +00:00
parent bd9ebbf8c9
commit 2ec3cd6694
12 changed files with 153 additions and 143 deletions

View File

@ -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;

View File

@ -13,6 +13,7 @@ files = [
"PixelShader.cpp",
"PixelShaderManager.cpp",
"VertexShader.cpp",
"VertexShaderManager.cpp",
"ImageWrite.cpp",
"Statistics.cpp",
"Fifo.cpp",

View File

@ -16,20 +16,24 @@
// http://code.google.com/p/dolphin-emu/
#include "Common.h"
#include "Globals.h"
#include "Profiler.h"
#include <cmath>
#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];
//--------------------------------

View File

@ -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();

View File

@ -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

View File

@ -547,6 +547,14 @@
RelativePath=".\Src\VertexLoaderManager.h"
>
</File>
<File
RelativePath=".\Src\VertexShaderManager.cpp"
>
</File>
<File
RelativePath=".\Src\VertexShaderManager.h"
>
</File>
<File
RelativePath=".\Src\VideoCommon.h"
>

View File

@ -860,14 +860,6 @@
RelativePath=".\Src\VertexShaderCache.h"
>
</File>
<File
RelativePath=".\Src\VertexShaderManager.cpp"
>
</File>
<File
RelativePath=".\Src\VertexShaderManager.h"
>
</File>
</Filter>
<Filter
Name="GUI"

View File

@ -23,37 +23,8 @@
// #define LOGGING
#include "Common.h"
#include "x64Emitter.h"
#include "Config.h"
#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
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
};
void DebugLog(const char* _fmt, ...);
void __Log(const char *format, ...);
void __Log(int type, const char *format, ...);
void HandleGLError();
#if defined(_MSC_VER) && !defined(__x86_64__) && !defined(_M_X64)
void * memcpy_amd(void *dest, const void *src, size_t n);
unsigned char memcmp_mmx(const void* src1, const void* src2, int cmpsize);

View File

@ -1030,3 +1030,93 @@ void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
// printf("pos: %d\n", loc);
}
}
// Called from VertexShaderManager
void UpdateViewport()
{
// 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);
}

View File

@ -25,7 +25,6 @@ files = [
'VertexLoader_Position.cpp',
'VertexLoader_TextCoord.cpp',
'VertexLoaderManager.cpp',
'VertexShaderManager.cpp',
'PixelShaderCache.cpp',
'VertexShaderCache.cpp',
'TextureConverter.cpp',

View File

@ -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

View File

@ -248,7 +248,7 @@ void Flush()
}
// set global constants
VertexShaderManager::SetConstants();
VertexShaderManager::SetConstants(g_Config.bProjectionHax1, g_Config.bProjectionHax2);
PixelShaderManager::SetConstants();
// finally bind