Massive style & comment cleanup of (mostly) GL plugin - also split some large files. A minor speedup for BP writes - merged the two switch()-es.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@899 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-10-17 11:30:14 +00:00
parent 4477f77cf6
commit dcbc8e78d4
45 changed files with 1288 additions and 1554 deletions

View File

@ -49,10 +49,12 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef _WIN32
// By default, MS' stdio implementation does not support 64-bit offsets.
// This little hack fixes that, keeping the code portable to linux where fseek and fread
// do support 64-bit offsets in modern distributions.
#define fseek _fseeki64 #define fseek _fseeki64
#define ftell _ftelli64 #define ftell _ftelli64
#endif
#define POSIX 0 #define POSIX 0
#define NOMINMAX #define NOMINMAX
@ -128,11 +130,9 @@ typedef union _LARGE_INTEGER
#undef max #undef max
template<class T> template<class T>
inline T min(const T& a, const T& b) {return(a > b ? b : a);} inline T min(const T& a, const T& b) {return a > b ? b : a;}
template<class T> template<class T>
inline T max(const T& a, const T& b) {return(a > b ? a : b);} inline T max(const T& a, const T& b) {return a > b ? a : b;}
// Byte ordering // Byte ordering

View File

@ -158,11 +158,11 @@ bool CFileSystemGCWii::InitFileSystem()
{ {
if (Read32(0x18) == 0x5D1C9EA3) if (Read32(0x18) == 0x5D1C9EA3)
{ {
m_OffsetShift = 2; m_OffsetShift = 2; // Wii file system
} }
else if (Read32(0x1c) == 0xC2339F3D) else if (Read32(0x1c) == 0xC2339F3D)
{ {
m_OffsetShift = 0; m_OffsetShift = 0; // GC file system
} }
else else
{ {
@ -206,8 +206,6 @@ bool CFileSystemGCWii::InitFileSystem()
return true; return true;
} }
// __________________________________________________________________________________________________
//
// Changed this stuff from C++ string to C strings for speed in debug mode. Doesn't matter in release, but // Changed this stuff from C++ string to C strings for speed in debug mode. Doesn't matter in release, but
// std::string is SLOW in debug mode. // std::string is SLOW in debug mode.
size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset) size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset)
@ -249,4 +247,3 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
} }
} // namespace } // namespace

View File

@ -18,11 +18,8 @@
#ifndef _DATAREADER_H #ifndef _DATAREADER_H
#define _DATAREADER_H #define _DATAREADER_H
extern u8* g_pVideoData; extern u8* g_pVideoData;
inline u8 DataPeek8(u32 _uOffset) inline u8 DataPeek8(u32 _uOffset)
{ {
return g_pVideoData[_uOffset]; return g_pVideoData[_uOffset];
@ -77,4 +74,3 @@ inline void DataSkip(u32 skip)
} }
#endif #endif

View File

@ -15,20 +15,14 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" // Simple profiler
#include "Common.h"
#include "Profiler.h" #include "Profiler.h"
////////////////////
// Small profiler //
////////////////////
#include <list> #include <list>
#include <string> #include <string>
#include <map> #include <map>
using namespace std;
int g_bWriteProfile=0;
#ifdef _WIN32 #ifdef _WIN32
@ -45,7 +39,14 @@ int g_bWriteProfile=0;
#pragma intrinsic(__rdtsc) #pragma intrinsic(__rdtsc)
#endif #endif
// Globals
static u64 luPerfFreq = 0; static u64 luPerfFreq = 0;
#ifdef DVPROFILE
int g_bWriteProfile = 1;
#else
int g_bWriteProfile = 1;
#endif
inline u64 GET_PROFILE_TIME() inline u64 GET_PROFILE_TIME()
{ {
#if defined (_MSC_VER) && _MSC_VER >= 1400 #if defined (_MSC_VER) && _MSC_VER >= 1400
@ -61,7 +62,6 @@ static u64 luPerfFreq=1000000;
#define GET_PROFILE_TIME() //GetCpuTick() #define GET_PROFILE_TIME() //GetCpuTick()
#endif #endif
struct DVPROFSTRUCT; struct DVPROFSTRUCT;
struct DVPROFSTRUCT struct DVPROFSTRUCT
@ -76,19 +76,21 @@ struct DVPROFSTRUCT
}; };
~DVPROFSTRUCT() { ~DVPROFSTRUCT() {
list<DVPROFSTRUCT*>::iterator it = listpChild.begin(); std::list<DVPROFSTRUCT *>::iterator it = listpChild.begin();
while (it != listpChild.end()) { while (it != listpChild.end()) {
delete *it; *it = NULL; delete *it;
*it = NULL;
++it; ++it;
} }
} }
list<DATA> listTimes; // before DVProfEnd is called, contains the global time it started // before DVProfEnd is called, contains the global time it started
// after DVProfEnd is called, contains the time it lasted // after DVProfEnd is called, contains the time it lasted
// the list contains all the tracked times // the list contains all the tracked times
char pname[256]; std::list<DATA> listTimes;
list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period char pname[256];
std::list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period
}; };
struct DVPROFTRACK struct DVPROFTRACK
@ -98,13 +100,19 @@ struct DVPROFTRACK
DVPROFSTRUCT* pprof; DVPROFSTRUCT* pprof;
}; };
list<DVPROFTRACK> g_listCurTracking; // the current profiling functions, the back element is the // the current profiling functions, the back element is the
// one that will first get popped off the list when DVProfEnd is called // one that will first get popped off the list when DVProfEnd is called
// the pointer is an element in DVPROFSTRUCT::listTimes // the pointer is an element in DVPROFSTRUCT::listTimes
list<DVPROFSTRUCT> g_listProfilers; // the current profilers, note that these are the parents static std::list<DVPROFTRACK> g_listCurTracking;
// the current profilers, note that these are the parents
// any profiler started during the time of another is held in // any profiler started during the time of another is held in
// DVPROFSTRUCT::listpChild // DVPROFSTRUCT::listpChild
list<DVPROFSTRUCT*> g_listAllProfilers; // ignores the hierarchy, pointer to elements in g_listProfilers static std::list<DVPROFSTRUCT> g_listProfilers;
// ignores the hierarchy, pointer to elements in g_listProfilers
static std::list<DVPROFSTRUCT*> g_listAllProfilers;
void DVProfRegister(const char *pname) void DVProfRegister(const char *pname)
{ {
@ -123,7 +131,7 @@ void DVProfRegister(const char *pname)
} }
#endif #endif
list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin(); std::list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin();
// while(it != g_listAllProfilers.end() ) { // while(it != g_listAllProfilers.end() ) {
// //
@ -191,19 +199,15 @@ struct DVTIMEINFO
u64 uInclusive, uExclusive; u64 uInclusive, uExclusive;
}; };
map<string, DVTIMEINFO> mapAggregateTimes; std::map<std::string, DVTIMEINFO> mapAggregateTimes;
u64 DVProfWriteStruct(FILE* f, DVPROFSTRUCT* p, int ident) u64 DVProfWriteStruct(FILE* f, const DVPROFSTRUCT* p, int ident)
{ {
fprintf(f, "%*s%s - ", ident, "", p->pname); fprintf(f, "%*s%s - ", ident, "", p->pname);
std::list<DVPROFSTRUCT::DATA>::const_iterator ittime = p->listTimes.begin();
list<DVPROFSTRUCT::DATA>::iterator ittime = p->listTimes.begin();
u64 utime = 0; u64 utime = 0;
while (ittime != p->listTimes.end()) { while (ittime != p->listTimes.end()) {
utime += ittime->dwTime; utime += ittime->dwTime;
if (ittime->dwUserData) if (ittime->dwUserData)
fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData); fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData);
else else
@ -212,9 +216,9 @@ u64 DVProfWriteStruct(FILE* f, DVPROFSTRUCT* p, int ident)
} }
// yes this is necessary, maps have problems with constructors on their type // yes this is necessary, maps have problems with constructors on their type
map<string, DVTIMEINFO>::iterator ittimes = mapAggregateTimes.find(p->pname); std::map<std::string, DVTIMEINFO>::iterator ittimes = mapAggregateTimes.find(p->pname);
if (ittimes == mapAggregateTimes.end()) { if (ittimes == mapAggregateTimes.end()) {
ittimes = mapAggregateTimes.insert(map<string, DVTIMEINFO>::value_type(p->pname, DVTIMEINFO())).first; ittimes = mapAggregateTimes.insert(std::map<std::string, DVTIMEINFO>::value_type(p->pname, DVTIMEINFO())).first;
ittimes->second.uExclusive = 0; ittimes->second.uExclusive = 0;
ittimes->second.uInclusive = 0; ittimes->second.uInclusive = 0;
} }
@ -223,11 +227,10 @@ u64 DVProfWriteStruct(FILE* f, DVPROFSTRUCT* p, int ident)
fprintf(f, "\n"); fprintf(f, "\n");
list<DVPROFSTRUCT*>::iterator itprof = p->listpChild.begin(); std::list<DVPROFSTRUCT*>::const_iterator itprof = p->listpChild.begin();
u64 uex = utime; u64 uex = utime;
while (itprof != p->listpChild.end()) { while (itprof != p->listpChild.end()) {
uex -= DVProfWriteStruct(f, *itprof, ident+4); uex -= DVProfWriteStruct(f, *itprof, ident+4);
++itprof; ++itprof;
} }
@ -247,15 +250,14 @@ void DVProfWrite(const char* pfilename, u32 frames)
// pop back any unused // pop back any unused
mapAggregateTimes.clear(); mapAggregateTimes.clear();
list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin(); std::list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin();
while (it != g_listProfilers.end() ) { while (it != g_listProfilers.end() ) {
DVProfWriteStruct(f, &(*it), 0); DVProfWriteStruct(f, &(*it), 0);
++it; ++it;
} }
{ std::map<std::string, DVTIMEINFO>::const_iterator iter;
map<string, DVTIMEINFO>::iterator iter;
fprintf(f, "\n\n-------------------------------------------------------------------\n\n"); fprintf(f, "\n\n-------------------------------------------------------------------\n\n");
u64 uTotal[2] = {0}; u64 uTotal[2] = {0};
@ -277,8 +279,6 @@ void DVProfWrite(const char* pfilename, u32 frames)
fprintf(f, "%s - ex: %f inc: %f\n", iter->first.c_str(), (float)((double)iter->second.uExclusive * fiTotalTime[0]), fprintf(f, "%s - ex: %f inc: %f\n", iter->first.c_str(), (float)((double)iter->second.uExclusive * fiTotalTime[0]),
(float)((double)iter->second.uInclusive * fiTotalTime[1])); (float)((double)iter->second.uInclusive * fiTotalTime[1]));
} }
}
fclose(f); fclose(f);
} }

View File

@ -21,17 +21,23 @@
#ifndef _PROFILER_H #ifndef _PROFILER_H
#define _PROFILER_H #define _PROFILER_H
#include <string>
#include "Common.h"
// #define DVPROFILE // comment out to disable profiling // #define DVPROFILE // comment out to disable profiling
extern int g_bWriteProfile; // global variable to enable/disable profiling (if DVPROFILE is defined) extern int g_bWriteProfile; // global variable to enable/disable profiling (if DVPROFILE is defined)
// IMPORTANT: For every Register there must be an End // IMPORTANT: For every Register there must be an End. Use the below DVProfileFunc utility class for safety.
void DVProfRegister(const char* pname); // first checks if this profiler exists in g_listProfilers void DVProfRegister(const char* pname); // first checks if this profiler exists in g_listProfilers
void DVProfEnd(u32 dwUserData); void DVProfEnd(u32 dwUserData);
void DVProfWrite(const char* pfilename, u32 frames = 0); void DVProfWrite(const char* pfilename, u32 frames = 0);
void DVProfGenReport(std::string *report);
void DVProfClear(); // clears all the profilers void DVProfClear(); // clears all the profilers
#if defined(DVPROFILE) && (defined(_WIN32)||defined(WIN32)) #if defined(DVPROFILE) && defined(_WIN32)
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -490,6 +490,14 @@
AssemblerOutput="4" AssemblerOutput="4"
/> />
</FileConfiguration> </FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AssemblerOutput="4"
/>
</FileConfiguration>
</File> </File>
<File <File
RelativePath=".\Src\XFBConvert.h" RelativePath=".\Src\XFBConvert.h"

View File

@ -1,8 +1,23 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _GLOBALS_H #ifndef _GLOBALS_H
#define _GLOBALS_H #define _GLOBALS_H
#include "Common.h" #include "Common.h"
#include "pluginspecs_dsp.h" #include "pluginspecs_dsp.h"
@ -14,6 +29,4 @@ u16 Memory_Read_U16(u32 _uAddress);
u32 Memory_Read_U32(u32 _uAddress); u32 Memory_Read_U32(u32 _uAddress);
float Memory_Read_Float(u32 _uAddress); float Memory_Read_Float(u32 _uAddress);
#endif #endif

View File

@ -763,6 +763,22 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="Docs"
>
<File
RelativePath="..\..\..\Docs\DSP\Crazy Taxi.txt"
>
</File>
<File
RelativePath="..\..\..\Docs\DSP\dsp_rom.txt"
>
</File>
<File
RelativePath="..\..\..\Docs\DSP\DSP_UC_Zelda.txt"
>
</File>
</Filter>
<File <File
RelativePath=".\Src\DSoundStream.cpp" RelativePath=".\Src\DSoundStream.cpp"
> >

View File

@ -19,6 +19,7 @@
#include "Globals.h" #include "Globals.h"
#include "Common.h" #include "Common.h"
#include "Profiler.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "TextureCache.h" #include "TextureCache.h"

View File

@ -23,7 +23,6 @@
#include "BPMemory.h" #include "BPMemory.h"
void BPInit(); void BPInit();
//bool BPWritten(int addr, int changes);
void LoadBPReg(u32 value0); void LoadBPReg(u32 value0);
void ActivateTextures(); void ActivateTextures();

View File

@ -28,6 +28,7 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "Common.h" #include "Common.h"
#include "Profiler.h"
#include "Globals.h" #include "Globals.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "TransformEngine.h" #include "TransformEngine.h"

View File

@ -17,6 +17,7 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "Utils.h" #include "Utils.h"
#include "Profiler.h"
#include "Globals.h" #include "Globals.h"
#include "ShaderManager.h" #include "ShaderManager.h"
#include "VertexLoader.h" #include "VertexLoader.h"

View File

@ -18,6 +18,7 @@
#include <fvec.h> #include <fvec.h>
#include "Common.h" #include "Common.h"
#include "Profiler.h"
#include "Globals.h" #include "Globals.h"
#include "Vec3.h" #include "Vec3.h"
#include "TransformEngine.h" #include "TransformEngine.h"

View File

@ -43,274 +43,3 @@ LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lPar
} }
return FALSE; return FALSE;
} }
////////////////////
// Small profiler //
////////////////////
#include <list>
#include <string>
#include <map>
using namespace std;
int g_bWriteProfile=0;
#ifdef _WIN32
#if defined (_MSC_VER) && _MSC_VER >= 1400
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
#define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64
#define _interlockedbittestandreset64 workaround_ms_header_bug_platform_sdk6_reset64
#include <intrin.h>
#undef _interlockedbittestandset
#undef _interlockedbittestandreset
#undef _interlockedbittestandset64
#undef _interlockedbittestandreset64
#pragma intrinsic(__rdtsc)
#endif
static u64 luPerfFreq=0;
inline u64 GET_PROFILE_TIME()
{
#if defined (_MSC_VER) && _MSC_VER >= 1400
return __rdtsc();
#else
LARGE_INTEGER lu;
QueryPerformanceCounter(&lu);
return lu.QuadPart;
#endif
}
#else
static u64 luPerfFreq = 1000000;
#define GET_PROFILE_TIME() //GetCpuTick()
#endif
struct DVPROFSTRUCT;
struct DVPROFSTRUCT
{
struct DATA
{
DATA(u64 time, u32 user = 0) : dwTime(time), dwUserData(user) {}
DATA() : dwTime(0), dwUserData(0) {}
u64 dwTime;
u32 dwUserData;
};
~DVPROFSTRUCT() {
list<DVPROFSTRUCT*>::iterator it = listpChild.begin();
while(it != listpChild.end() ) {
delete *it; *it = NULL;
++it;
}
}
list<DATA> listTimes; // before DVProfEnd is called, contains the global time it started
// after DVProfEnd is called, contains the time it lasted
// the list contains all the tracked times
char pname[256];
list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period
};
struct DVPROFTRACK
{
u32 dwUserData;
DVPROFSTRUCT::DATA* pdwTime;
DVPROFSTRUCT* pprof;
};
list<DVPROFTRACK> g_listCurTracking; // the current profiling functions, the back element is the
// one that will first get popped off the list when DVProfEnd is called
// the pointer is an element in DVPROFSTRUCT::listTimes
list<DVPROFSTRUCT> g_listProfilers; // the current profilers, note that these are the parents
// any profiler started during the time of another is held in
// DVPROFSTRUCT::listpChild
list<DVPROFSTRUCT*> g_listAllProfilers; // ignores the hierarchy, pointer to elements in g_listProfilers
void DVProfRegister(char* pname)
{
if( !g_bWriteProfile )
return;
#ifdef _WIN32
if( luPerfFreq <= 1 ) {
#if defined (_MSC_VER) && _MSC_VER >= 1400
luPerfFreq = 1000000;
#else
LARGE_INTEGER temp;
QueryPerformanceFrequency(&temp);
luPerfFreq = temp.QuadPart;
#endif
}
#endif
list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin();
// while(it != g_listAllProfilers.end() ) {
//
// if( _tcscmp(pname, (*it)->pname) == 0 ) {
// (*it)->listTimes.push_back(timeGetTime());
// DVPROFTRACK dvtrack;
// dvtrack.pdwTime = &(*it)->listTimes.back();
// dvtrack.pprof = *it;
// g_listCurTracking.push_back(dvtrack);
// return;
// }
//
// ++it;
// }
// else add in a new profiler to the appropriate parent profiler
DVPROFSTRUCT* pprof = NULL;
if( g_listCurTracking.size() > 0 ) {
assert( g_listCurTracking.back().pprof != NULL );
g_listCurTracking.back().pprof->listpChild.push_back(new DVPROFSTRUCT());
pprof = g_listCurTracking.back().pprof->listpChild.back();
}
else {
g_listProfilers.push_back(DVPROFSTRUCT());
pprof = &g_listProfilers.back();
}
strncpy(pprof->pname, pname, 256);
// setup the profiler for tracking
pprof->listTimes.push_back(DVPROFSTRUCT::DATA(GET_PROFILE_TIME()));
DVPROFTRACK dvtrack;
dvtrack.pdwTime = &pprof->listTimes.back();
dvtrack.pprof = pprof;
dvtrack.dwUserData = 0;
g_listCurTracking.push_back(dvtrack);
// add to all profiler list
g_listAllProfilers.push_back(pprof);
}
void DVProfEnd(u32 dwUserData)
{
if( !g_bWriteProfile )
return;
if( g_listCurTracking.size() == 0 )
return;
DVPROFTRACK dvtrack = g_listCurTracking.back();
assert( dvtrack.pdwTime != NULL && dvtrack.pprof != NULL );
dvtrack.pdwTime->dwTime = GET_PROFILE_TIME()- dvtrack.pdwTime->dwTime;
dvtrack.pdwTime->dwUserData= dwUserData;
g_listCurTracking.pop_back();
}
struct DVTIMEINFO
{
DVTIMEINFO() : uInclusive(0), uExclusive(0) {}
u64 uInclusive, uExclusive;
};
map<string, DVTIMEINFO> mapAggregateTimes;
u64 DVProfWriteStruct(FILE* f, DVPROFSTRUCT* p, int ident)
{
fprintf(f, "%*s%s - ", ident, "", p->pname);
list<DVPROFSTRUCT::DATA>::iterator ittime = p->listTimes.begin();
u64 utime = 0;
while(ittime != p->listTimes.end() ) {
utime += ittime->dwTime;
if( ittime->dwUserData )
fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData);
else
fprintf(f, "time: %d", (u32)ittime->dwTime);
++ittime;
}
// yes this is necessary, maps have problems with constructors on their type
map<string, DVTIMEINFO>::iterator ittimes = mapAggregateTimes.find(p->pname);
if( ittimes == mapAggregateTimes.end() ) {
ittimes = mapAggregateTimes.insert(map<string, DVTIMEINFO>::value_type(p->pname, DVTIMEINFO())).first;
ittimes->second.uExclusive = 0;
ittimes->second.uInclusive = 0;
}
ittimes->second.uInclusive += utime;
fprintf(f, "\n");
list<DVPROFSTRUCT*>::iterator itprof = p->listpChild.begin();
u64 uex = utime;
while(itprof != p->listpChild.end() ) {
uex -= DVProfWriteStruct(f, *itprof, ident+4);
++itprof;
}
if( uex > utime ) {
uex = 0;
}
ittimes->second.uExclusive += uex;
return utime;
}
void DVProfWrite(char* pfilename, u32 frames)
{
assert( pfilename != NULL );
FILE* f = fopen(pfilename, "w");
// pop back any unused
mapAggregateTimes.clear();
list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin();
while(it != g_listProfilers.end() ) {
DVProfWriteStruct(f, &(*it), 0);
++it;
}
{
map<string, DVTIMEINFO>::iterator it;
fprintf(f, "\n\n-------------------------------------------------------------------\n\n");
u64 uTotal[2] = {0};
double fiTotalTime[2];
for(it = mapAggregateTimes.begin(); it != mapAggregateTimes.end(); ++it) {
uTotal[0] += it->second.uExclusive;
uTotal[1] += it->second.uInclusive;
}
fprintf(f, "total times (%d): ex: %Lu ", frames, 1000000*uTotal[0]/(luPerfFreq*(u64)frames));
fprintf(f, "inc: %Lu\n", 1000000 * uTotal[1]/(luPerfFreq*(u64)frames));
fiTotalTime[0] = 1.0 / (double)uTotal[0];
fiTotalTime[1] = 1.0 / (double)uTotal[1];
// output the combined times
for(it = mapAggregateTimes.begin(); it != mapAggregateTimes.end(); ++it) {
fprintf(f, "%s - ex: %f inc: %f\n", it->first.c_str(), (float)((double)it->second.uExclusive * fiTotalTime[0]),
(float)((double)it->second.uInclusive * fiTotalTime[1]));
}
}
fclose(f);
}
void DVProfClear()
{
g_listCurTracking.clear();
g_listProfilers.clear();
g_listAllProfilers.clear();
}

View File

@ -60,54 +60,4 @@ inline float Memory_Read_Float(u32 _uAddress)
return *(float*)&uTemp; return *(float*)&uTemp;
} }
////
// profiling
///
extern int g_bWriteProfile; // global variable to enable/disable profiling (if DVPROFILE is defined)
// IMPORTANT: For every Register there must be an End
void DVProfRegister(char* pname); // first checks if this profiler exists in g_listProfilers
void DVProfEnd(u32 dwUserData);
void DVProfWrite(char* pfilename, u32 frames = 0);
void DVProfClear(); // clears all the profilers
// #define DVPROFILE // comment out to disable profiling
#if defined(DVPROFILE) && (defined(_WIN32)||defined(WIN32))
#ifdef _MSC_VER
#ifndef __PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif
#endif
#define DVSTARTPROFILE() DVProfileFunc _pf(__PRETTY_FUNCTION__);
class DVProfileFunc
{
public:
u32 dwUserData;
DVProfileFunc(char* pname) { DVProfRegister(pname); dwUserData = 0; }
DVProfileFunc(char* pname, u32 dwUserData) : dwUserData(dwUserData) { DVProfRegister(pname); }
~DVProfileFunc() { DVProfEnd(dwUserData); }
};
#else
#define DVSTARTPROFILE()
class DVProfileFunc
{
public:
u32 dwUserData;
__forceinline DVProfileFunc(char* pname) {}
__forceinline DVProfileFunc(char* pname, u32 dwUserData) { }
~DVProfileFunc() {}
};
#endif
#endif #endif

View File

@ -18,6 +18,7 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "Common.h" #include "Common.h"
#include "Profiler.h"
#include "Globals.h" #include "Globals.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"

View File

@ -20,6 +20,7 @@
#include "x64Emitter.h" #include "x64Emitter.h"
#include "Common.h" #include "Common.h"
#include "Profiler.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "XFStructs.h" #include "XFStructs.h"

View File

@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "stdafx.h" #include "stdafx.h"
#include "Profiler.h"
#include "XFStructs.h" #include "XFStructs.h"
#include "Render.h" #include "Render.h"
#include "main.h" #include "main.h"

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="Plugin_VideoOGL" Name="Plugin_VideoOGL"
ProjectGUID="{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}" ProjectGUID="{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}"
RootNamespace="Plugin_VideoOGL" RootNamespace="Plugin_VideoOGL"
@ -760,6 +760,14 @@
RelativePath=".\Src\VertexLoader_TextCoord.h" RelativePath=".\Src\VertexLoader_TextCoord.h"
> >
</File> </File>
<File
RelativePath=".\Src\VertexManager.cpp"
>
</File>
<File
RelativePath=".\Src\VertexManager.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Render" Name="Render"
@ -1072,6 +1080,14 @@
RelativePath=".\Src\Logging\Console.h" RelativePath=".\Src\Logging\Console.h"
> >
</File> </File>
<File
RelativePath=".\Src\ImageWrite.cpp"
>
</File>
<File
RelativePath=".\Src\ImageWrite.h"
>
</File>
<File <File
RelativePath=".\Src\Logging\Logging.cpp" RelativePath=".\Src\Logging\Logging.cpp"
> >

View File

@ -22,6 +22,7 @@
#include "Profiler.h" #include "Profiler.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexManager.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "Render.h" #include "Render.h"
@ -65,14 +66,9 @@ void BPInit()
} }
// ======================================================================================= // Called att the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
// Called att the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() >
// LoadBPReg()
// ---------------
void BPWritten(int addr, int changes, int newval) void BPWritten(int addr, int changes, int newval)
{ {
DVSTARTPROFILE();
//static int count = 0; //static int count = 0;
//ERROR_LOG("(%d) %x: %x\n", count++, addr, newval); //ERROR_LOG("(%d) %x: %x\n", count++, addr, newval);
@ -166,9 +162,8 @@ void BPWritten(int addr, int changes, int newval)
case BPMEM_LINEPTWIDTH: case BPMEM_LINEPTWIDTH:
{ {
float fratio = VertexShaderMngr::rawViewport[0] != 0 ? (float)Renderer::GetTargetWidth() / 640.0f : 1.0f; float fratio = VertexShaderMngr::rawViewport[0] != 0 ? (float)Renderer::GetTargetWidth() / 640.0f : 1.0f;
if( bpmem.lineptwidth.linesize > 0 ) { if (bpmem.lineptwidth.linesize > 0)
glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths
}
if (bpmem.lineptwidth.pointsize > 0) if (bpmem.lineptwidth.pointsize > 0)
glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f); glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f);
break; break;
@ -392,6 +387,154 @@ void BPWritten(int addr, int changes, int newval)
PixelShaderMngr::SetTevKSelChanged(addr-0xf6); PixelShaderMngr::SetTevKSelChanged(addr-0xf6);
} }
break; break;
case 0x45: //GXSetDrawDone
VertexManager::Flush();
switch (newval & 0xFF)
{
case 0x02:
g_VideoInitialize.pSetPEFinish(); // may generate interrupt
DebugLog("GXSetDrawDone SetPEFinish (value: 0x%02X)", (newval & 0xFFFF));
break;
default:
DebugLog("GXSetDrawDone ??? (value 0x%02X)", (newval & 0xFFFF));
break;
}
break;
case BPMEM_PE_TOKEN_ID:
g_VideoInitialize.pSetPEToken(static_cast<u16>(newval & 0xFFFF), FALSE);
DebugLog("SetPEToken 0x%04x", (newval & 0xFFFF));
break;
case BPMEM_PE_TOKEN_INT_ID:
g_VideoInitialize.pSetPEToken(static_cast<u16>(newval & 0xFFFF), TRUE);
DebugLog("SetPEToken + INT 0x%04x", (newval & 0xFFFF));
break;
case 0x67: // set gp metric?
break;
case 0x52:
{
DVProfileFunc _pf("LoadBPReg:swap");
VertexManager::Flush();
((u32*)&bpmem)[addr] = newval;
TRectangle rc = {
(int)(bpmem.copyTexSrcXY.x),
(int)(bpmem.copyTexSrcXY.y),
(int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)),
(int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1))
};
//Need another rc here to get it to scale.
TRectangle multirc = {
(int)(bpmem.copyTexSrcXY.x * MValueX),
(int)(bpmem.copyTexSrcXY.y * MValueY),
(int)((bpmem.copyTexSrcXY.x * MValueX + (bpmem.copyTexSrcWH.x + 1) * MValueX)),
(int)((bpmem.copyTexSrcXY.y * MValueY + (bpmem.copyTexSrcWH.y + 1) * MValueY))
};
UPE_Copy PE_copy;
PE_copy.Hex = bpmem.triggerEFBCopy;
if (PE_copy.copy_to_xfb == 0) {
// EFB to texture
// for some reason it sets bpmem.zcontrol.pixel_format to PIXELFMT_Z24 every time a zbuffer format is given as a dest to GXSetTexCopyDst
TextureMngr::CopyRenderTargetToTexture(bpmem.copyTexDest<<5, bpmem.zcontrol.pixel_format==PIXELFMT_Z24, PE_copy.intensity_fmt>0,
(PE_copy.target_pixel_format/2)+((PE_copy.target_pixel_format&1)*8), PE_copy.half_scale>0, &rc);
}
else {
// EFB to XFB
if(g_Config.bUseXFB)
{
XFB_Write(Memory_GetPtr(bpmem.copyTexDest<<5), multirc, (bpmem.copyMipMapStrideChannels << 4), bpmem.copyTexSrcWH.y + 1, bpmem.dispcopyyscale/256.0f);
}
else
{
Renderer::Swap(multirc);
}
g_VideoInitialize.pCopiedToXFB();
}
// clearing
if (PE_copy.clear) {
// clear color
Renderer::SetRenderMode(Renderer::RM_Normal);
u32 nRestoreZBufferTarget = Renderer::GetZBufferTarget();
glViewport(0, 0, Renderer::GetTargetWidth(), Renderer::GetTargetHeight());
// Always set the scissor in case it was set by the game and has not been reset
glScissor(multirc.left, (Renderer::GetTargetHeight() - multirc.bottom),
(multirc.right - multirc.left), (multirc.bottom - multirc.top));
VertexShaderMngr::SetViewportChanged();
// since clear operations use the source rectangle, have to do regular renders (glClear clears the entire buffer)
if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate || bpmem.zmode.updateenable) {
GLbitfield bits = 0;
if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate) {
u32 clearColor = (bpmem.clearcolorAR<<16)|bpmem.clearcolorGB;
glClearColor(((clearColor>>16)&0xff)*(1/255.0f),((clearColor>>8)&0xff)*(1/255.0f),
((clearColor>>0)&0xff)*(1/255.0f),((clearColor>>24)&0xff)*(1/255.0f));
bits |= GL_COLOR_BUFFER_BIT;
}
if (bpmem.zmode.updateenable) {
glClearDepth((float)(bpmem.clearZValue&0xFFFFFF) / float(0xFFFFFF));
bits |= GL_DEPTH_BUFFER_BIT;
}
if (nRestoreZBufferTarget )
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // don't clear ztarget here
glClear(bits);
}
if (bpmem.zmode.updateenable && nRestoreZBufferTarget) { // have to clear the target zbuffer
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
GL_REPORT_ERRORD();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
// red should probably be the LSB
glClearColor(((bpmem.clearZValue>>0)&0xff)*(1/255.0f),((bpmem.clearZValue>>8)&0xff)*(1/255.0f),
((bpmem.clearZValue>>16)&0xff)*(1/255.0f), 0);
glClear(GL_COLOR_BUFFER_BIT);
SetColorMask();
GL_REPORT_ERRORD();
}
if (nRestoreZBufferTarget) {
// restore target
GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
glDrawBuffers(2, s_drawbuffers);
}
SetScissorRect(); // reset the scissor rect
}
}
break;
case 0x65: //GXLoadTlut
{
DVProfileFunc _pf("LoadBPReg:GXLoadTlut");
VertexManager::Flush();
((u32*)&bpmem)[addr] = newval;
u32 tlutTMemAddr = (newval&0x3FF)<<9;
u32 tlutXferCount = (newval&0x1FFC00)>>5;
//do the transfer!!
memcpy_gc(texMem + tlutTMemAddr, g_VideoInitialize.pGetMemoryPointer((bpmem.tlutXferSrc&0xFFFFF)<<5), tlutXferCount);
// TODO(ector) : kill all textures that use this palette
// Not sure if it's a good idea, though. For now, we hash texture palettes
}
break;
default: default:
switch(addr & 0xFC) //texture sampler filter switch(addr & 0xFC) //texture sampler filter
@ -591,37 +734,35 @@ bool SetScissorRect()
int xoff = bpmem.scissorOffset.x * 2 - 342; int xoff = bpmem.scissorOffset.x * 2 - 342;
int yoff = bpmem.scissorOffset.y * 2 - 342; int yoff = bpmem.scissorOffset.y * 2 - 342;
RECT rc; int rc_left = bpmem.scissorTL.x - xoff - 342; // left = 0
rc_left *= MValueX;
if (rc_left < 0) rc_left = 0;
rc.left = bpmem.scissorTL.x - xoff - 342; // left = 0 int rc_top = bpmem.scissorTL.y - yoff - 342; // right = 0
rc.left *= MValueX; rc_top *= MValueY;
if (rc.left < 0) rc.left = 0; if (rc_top < 0) rc_top = 0;
rc.top = bpmem.scissorTL.y - yoff - 342; // right = 0 int rc_right = bpmem.scissorBR.x - xoff - 342; // right = 640
rc.top *= MValueY; rc_right *= MValueX;
if (rc.top < 0) rc.top = 0; if (rc_right > 640 * MValueX) rc_right = 640 * MValueX;
rc.right = bpmem.scissorBR.x - xoff - 342; // right = 640 int rc_bottom = bpmem.scissorBR.y - yoff - 342; // bottom = 480
rc.right *= MValueX; rc_bottom *= MValueY;
if (rc.right > 640 * MValueX) rc.right = 640 * MValueX; if (rc_bottom > 480 * MValueY) rc_bottom = 480 * MValueY;
rc.bottom = bpmem.scissorBR.y - yoff - 342; // bottom = 480
rc.bottom *= MValueY;
if (rc.bottom > 480 * MValueY) rc.bottom = 480 * MValueY;
/*__Log("Scissor: lt=(%d,%d), rb=(%d,%d,%i), off=(%d,%d)\n", /*__Log("Scissor: lt=(%d,%d), rb=(%d,%d,%i), off=(%d,%d)\n",
rc.left, rc.top, rc_left, rc_top,
rc.right, rc.bottom, Renderer::GetTargetHeight(), rc_right, rc_bottom, Renderer::GetTargetHeight(),
xoff, yoff xoff, yoff
);*/ );*/
if( rc.right>=rc.left && rc.bottom>=rc.top ) if (rc_right >= rc_left && rc_bottom >= rc_top )
{ {
glScissor( glScissor(
rc.left, // x = 0 rc_left, // x = 0
Renderer::GetTargetHeight()-(rc.bottom), // y = 0 Renderer::GetTargetHeight()-(rc_bottom), // y = 0
(rc.right-rc.left), // y = 0 (rc_right-rc_left), // y = 0
(rc.bottom-rc.top) // y = 0 (rc_bottom-rc_top) // y = 0
); );
return true; return true;
} }
@ -630,183 +771,38 @@ bool SetScissorRect()
} }
// =======================================================================================
// Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg() // Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg()
// ---------------
void LoadBPReg(u32 value0) void LoadBPReg(u32 value0)
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
//handle the mask register //handle the mask register
int opcode = value0 >> 24; int opcode = value0 >> 24;
int oldval = ((u32*)&bpmem)[opcode]; int oldval = ((u32*)&bpmem)[opcode];
int newval = (((u32*)&bpmem)[opcode] & ~bpmem.bpMask) | (value0 & bpmem.bpMask); int newval = (oldval & ~bpmem.bpMask) | (value0 & bpmem.bpMask);
int changes = (oldval ^ newval) & 0xFFFFFF; int changes = (oldval ^ newval) & 0xFFFFFF;
//reset the mask register //reset the mask register
if (opcode != 0xFE) if (opcode != 0xFE)
bpmem.bpMask = 0xFFFFFF; bpmem.bpMask = 0xFFFFFF;
switch (opcode)
{
case 0x45: //GXSetDrawDone
VertexManager::Flush();
switch (value0 & 0xFF)
{
case 0x02:
g_VideoInitialize.pSetPEFinish(); // may generate interrupt
DebugLog("GXSetDrawDone SetPEFinish (value: 0x%02X)", (value0 & 0xFFFF));
break;
default:
DebugLog("GXSetDrawDone ??? (value 0x%02X)", (value0 & 0xFFFF));
break;
}
break;
case BPMEM_PE_TOKEN_ID:
g_VideoInitialize.pSetPEToken(static_cast<u16>(value0 & 0xFFFF), FALSE);
DebugLog("SetPEToken 0x%04x", (value0 & 0xFFFF));
break;
case BPMEM_PE_TOKEN_INT_ID:
g_VideoInitialize.pSetPEToken(static_cast<u16>(value0 & 0xFFFF), TRUE);
DebugLog("SetPEToken + INT 0x%04x", (value0 & 0xFFFF));
break;
case 0x67: // set gp metric?
break;
case 0x52:
{
DVProfileFunc _pf("LoadBPReg:swap");
VertexManager::Flush();
((u32*)&bpmem)[opcode] = newval;
TRectangle rc = {
(int)(bpmem.copyTexSrcXY.x),
(int)(bpmem.copyTexSrcXY.y),
(int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)),
(int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1))
};
//Need another rc here to get it to scale.
TRectangle multirc = {
(int)(bpmem.copyTexSrcXY.x * MValueX),
(int)(bpmem.copyTexSrcXY.y * MValueY),
(int)((bpmem.copyTexSrcXY.x * MValueX + (bpmem.copyTexSrcWH.x + 1) * MValueX)),
(int)((bpmem.copyTexSrcXY.y * MValueY + (bpmem.copyTexSrcWH.y + 1) * MValueY))
};
UPE_Copy PE_copy;
PE_copy.Hex = bpmem.triggerEFBCopy;
if (PE_copy.copy_to_xfb == 0) {
// EFB to texture
// for some reason it sets bpmem.zcontrol.pixel_format to PIXELFMT_Z24 every time a zbuffer format is given as a dest to GXSetTexCopyDst
TextureMngr::CopyRenderTargetToTexture(bpmem.copyTexDest<<5, bpmem.zcontrol.pixel_format==PIXELFMT_Z24, PE_copy.intensity_fmt>0,
(PE_copy.target_pixel_format/2)+((PE_copy.target_pixel_format&1)*8), PE_copy.half_scale>0, &rc);
}
else {
// EFB to XFB
if(g_Config.bUseXFB)
{
XFB_Write(Memory_GetPtr(bpmem.copyTexDest<<5), multirc, (bpmem.copyMipMapStrideChannels << 4), bpmem.copyTexSrcWH.y + 1, bpmem.dispcopyyscale/256.0f);
}
else
{
Renderer::Swap(multirc);
}
g_VideoInitialize.pCopiedToXFB();
}
// clearing
if (PE_copy.clear) {
// clear color
Renderer::SetRenderMode(Renderer::RM_Normal);
u32 nRestoreZBufferTarget = Renderer::GetZBufferTarget();
glViewport(0, 0, Renderer::GetTargetWidth(), Renderer::GetTargetHeight());
// Always set the scissor in case it was set by the game and has not been reset
glScissor(multirc.left, (Renderer::GetTargetHeight() - multirc.bottom),
(multirc.right - multirc.left), (multirc.bottom - multirc.top));
VertexShaderMngr::SetViewportChanged();
// since clear operations use the source rectangle, have to do regular renders (glClear clears the entire buffer)
if( bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate || bpmem.zmode.updateenable ) {
GLbitfield bits = 0;
if( bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate ) {
u32 clearColor = (bpmem.clearcolorAR<<16)|bpmem.clearcolorGB;
glClearColor(((clearColor>>16)&0xff)*(1/255.0f),((clearColor>>8)&0xff)*(1/255.0f),
((clearColor>>0)&0xff)*(1/255.0f),((clearColor>>24)&0xff)*(1/255.0f));
bits |= GL_COLOR_BUFFER_BIT;
}
if( bpmem.zmode.updateenable ) {
glClearDepth((float)(bpmem.clearZValue&0xFFFFFF) / float(0xFFFFFF));
bits |= GL_DEPTH_BUFFER_BIT;
}
if( nRestoreZBufferTarget )
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // don't clear ztarget here
glClear(bits);
}
if (bpmem.zmode.updateenable && nRestoreZBufferTarget ) { // have to clear the target zbuffer
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
GL_REPORT_ERRORD();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
// red should probably be the LSB
glClearColor(((bpmem.clearZValue>>0)&0xff)*(1/255.0f),((bpmem.clearZValue>>8)&0xff)*(1/255.0f),
((bpmem.clearZValue>>16)&0xff)*(1/255.0f), 0);
glClear(GL_COLOR_BUFFER_BIT);
SetColorMask();
GL_REPORT_ERRORD();
}
if( nRestoreZBufferTarget ) {
// restore target
GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
glDrawBuffers(2, s_drawbuffers);
}
SetScissorRect(); // reset the scissor rect
}
}
break;
case 0x65: //GXLoadTlut
{
DVProfileFunc _pf("LoadBPReg:GXLoadTlut");
VertexManager::Flush();
((u32*)&bpmem)[opcode] = newval;
u32 tlutTMemAddr = (value0&0x3FF)<<9;
u32 tlutXferCount = (value0&0x1FFC00)>>5;
//do the transfer!!
memcpy_gc(texMem + tlutTMemAddr, g_VideoInitialize.pGetMemoryPointer((bpmem.tlutXferSrc&0xFFFFF)<<5), tlutXferCount);
// TODO(ector) : kill all textures that use this palette
// Not sure if it's a good idea, though. For now, we hash texture palettes
}
break;
}
//notify the video handling so it can update render states //notify the video handling so it can update render states
BPWritten(opcode, changes, newval); BPWritten(opcode, changes, newval);
//((u32*)&bpmem)[opcode] = newval;
} }
// ======================================================================================= // Never called? Should probably be called when loading a saved state.
// Never called? // Needs testing though.
// ---------------
void BPReload() void BPReload()
{ {
for (int i = 0; i < 254; i++) for (int i = 0; i < 254; i++)
{
switch (i) {
case 0x65:
case 0x45: //GXSetDrawDone
case BPMEM_PE_TOKEN_ID:
case BPMEM_PE_TOKEN_INT_ID:
case 0x67: // set gp metric?
case 0x52:
break;
default:
BPWritten(i, 0xFFFFFF, ((u32*)&bpmem)[i]); BPWritten(i, 0xFFFFFF, ((u32*)&bpmem)[i]);
} }
}
}

View File

@ -21,7 +21,6 @@
#include "BPMemory.h" #include "BPMemory.h"
void BPInit(); void BPInit();
//bool BPWritten(int addr, int changes);
void LoadBPReg(u32 value0); void LoadBPReg(u32 value0);
void SetColorMask(); void SetColorMask();

View File

@ -1,23 +1,19 @@
////////////////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2003-2008 Dolphin Project.
//
// Licensetype: GNU General Public License (GPL)
//
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
//
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
//
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
//
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
//
//////////////////////////////////////////////////////////////////////////////////////////
#include "../Globals.h" #include "../Globals.h"
#include "Debugger.h" #include "Debugger.h"

View File

@ -1,23 +1,19 @@
////////////////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2003-2008 Dolphin Project.
//
// Licensetype: GNU General Public License (GPL)
//
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
//
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
//
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
//
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
//
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef __CDebugger_h__ #ifndef __CDebugger_h__
#define __CDebugger_h__ #define __CDebugger_h__

View File

@ -15,10 +15,6 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
// ---------------------------------------------------------------------------------------
// includes
// -----------------
#include "../Globals.h" #include "../Globals.h"
#include "PBView.h" #include "PBView.h"
@ -27,24 +23,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
// ---------------------------------------------------------------------------------------
// external declarations
// -----------------
extern const char* GetGRPName(unsigned int index); extern const char* GetGRPName(unsigned int index);
// ---------------------------------------------------------------------------------------
// No buttons or events so far
// -----------------
BEGIN_EVENT_TABLE(CPBView, wxListCtrl) BEGIN_EVENT_TABLE(CPBView, wxListCtrl)
END_EVENT_TABLE() END_EVENT_TABLE()
// =======================================================================================
// The main wxListCtrl
// -------------
CPBView::CPBView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style) CPBView::CPBView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
: wxListCtrl(parent, id, pos, size, style) : wxListCtrl(parent, id, pos, size, style)
{ {
@ -54,7 +37,6 @@ CPBView::CPBView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, cons
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++)
{ {
// Print values from 0 to 63 // Print values from 0 to 63
char buffer [33]; char buffer [33];
sprintf(buffer, "%02i", i); sprintf(buffer, "%02i", i);
@ -72,18 +54,14 @@ CPBView::CPBView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, cons
Refresh(); Refresh();
} }
void CPBView::Update()
void
CPBView::Update()
{ {
Refresh(); Refresh();
} }
bool CPBView::MSWDrawSubItem(wxPaintDC& rPainDC, int item, int subitem)
bool
CPBView::MSWDrawSubItem(wxPaintDC& rPainDC, int item, int subitem)
{ {
bool Result = false; bool Result = false;
@ -135,13 +113,11 @@ CPBView::MSWDrawSubItem(wxPaintDC& rPainDC, int item, int subitem)
rPainDC.DrawText(text, 10, 4); rPainDC.DrawText(text, 10, 4);
#endif #endif
return(true); return true;
} }
else else
{ {
// what does this mean? // what does this mean?
return(Result); return Result;
} }
} }

View File

@ -23,24 +23,16 @@
#include "Common.h" #include "Common.h"
class CPBView class CPBView : public wxListCtrl
: public wxListCtrl
{ {
public: public:
CPBView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style); CPBView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style);
void Update(); void Update();
u32 m_CachedRegs[10][10]; u32 m_CachedRegs[10][10];
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
bool m_CachedRegHasChanged[64]; bool m_CachedRegHasChanged[64];
virtual bool MSWDrawSubItem(wxPaintDC& rPainDC, int item, int subitem); virtual bool MSWDrawSubItem(wxPaintDC& rPainDC, int item, int subitem);
}; };

View File

@ -19,9 +19,18 @@
#include "IniFile.h" #include "IniFile.h"
#include "svnrev.h" #include "svnrev.h"
#include "Render.h"
#if defined(_WIN32) #if defined(_WIN32)
#include "OS/Win32.h" #include "OS/Win32.h"
#else
struct RECT
{
int left, top;
int right, bottom;
};
#endif #endif
#include "GLInit.h" #include "GLInit.h"
#ifndef USE_SDL #ifndef USE_SDL
@ -33,16 +42,12 @@
// Handles OpenGL and the window // Handles OpenGL and the window
// ---------------------------------------------------------------------------------------
// externals // externals
// -------------
int gleft, gright, gtop, gbottom; int gleft, gright, gtop, gbottom;
int nBackbufferWidth, nBackbufferHeight; // screen width int nBackbufferWidth, nBackbufferHeight; // screen width
int nXoff, nYoff; // screen offset int nXoff, nYoff; // screen offset
float AR; // aspect ratio float AR; // aspect ratio
#ifndef _WIN32 #ifndef _WIN32
GLWindow GLWin; GLWindow GLWin;
#endif #endif
@ -104,7 +109,6 @@ BOOL Callback_PeekMessages()
#endif #endif
} }
void UpdateFPSDisplay(const char *text) void UpdateFPSDisplay(const char *text)
{ {
char temp[512]; char temp[512];
@ -116,10 +120,8 @@ void UpdateFPSDisplay(const char *text)
} }
// ======================================================================================= // =======================================================================================
// Create window. Called from main.cpp // Create window. Called from main.cpp
// ----------------
bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight) bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight)
{ {
int _twidth, _theight; int _twidth, _theight;
@ -186,7 +188,6 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
//sprintf(buff, "%i %i %d %d %d", nBackbufferWidth, nBackbufferHeight, Max, MValueX, MValueY); //sprintf(buff, "%i %i %d %d %d", nBackbufferWidth, nBackbufferHeight, Max, MValueX, MValueY);
//MessageBox(0, buff, "", 0); //MessageBox(0, buff, "", 0);
#if USE_SDL #if USE_SDL
//init sdl video //init sdl video
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {

View File

@ -15,7 +15,6 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/filepicker.h> #include <wx/filepicker.h>
#include <wx/notebook.h> #include <wx/notebook.h>
@ -30,8 +29,6 @@
#include "IniFile.h" #include "IniFile.h"
#include <assert.h> #include <assert.h>
float MValueX, MValueY; // Since it can Stretch to fit Window, we need two different multiplication values//
int frameCount;
Config g_Config; Config g_Config;
Statistics stats; Statistics stats;
@ -52,10 +49,6 @@ void Config::Load()
IniFile iniFile; IniFile iniFile;
iniFile.Load("gfx_opengl.ini"); iniFile.Load("gfx_opengl.ini");
iniFile.Get("Hardware", "Adapter", &iAdapter, 0);
if (iAdapter == -1)
iAdapter = 0;
// get resolution // get resolution
iniFile.Get("Hardware", "WindowedRes", &temp, 0); iniFile.Get("Hardware", "WindowedRes", &temp, 0);
if(temp.empty()) if(temp.empty())
@ -71,7 +64,6 @@ void Config::Load()
iniFile.Get("Settings", "ShowFPS", &bShowFPS, false); // Settings iniFile.Get("Settings", "ShowFPS", &bShowFPS, false); // Settings
iniFile.Get("Settings", "OverlayStats", &bOverlayStats, false); iniFile.Get("Settings", "OverlayStats", &bOverlayStats, false);
iniFile.Get("Settings", "Postprocess", &iPostprocessEffect, 0);
iniFile.Get("Settings", "DLOptimize", &iCompileDLsLevel, 0); iniFile.Get("Settings", "DLOptimize", &iCompileDLsLevel, 0);
iniFile.Get("Settings", "DumpTextures", &bDumpTextures, 0); iniFile.Get("Settings", "DumpTextures", &bDumpTextures, 0);
iniFile.Get("Settings", "ShowShaderErrors", &bShowShaderErrors, 0); iniFile.Get("Settings", "ShowShaderErrors", &bShowShaderErrors, 0);
@ -102,7 +94,6 @@ void Config::Save()
{ {
IniFile iniFile; IniFile iniFile;
iniFile.Load("gfx_opengl.ini"); iniFile.Load("gfx_opengl.ini");
iniFile.Set("Hardware", "Adapter", iAdapter);
iniFile.Set("Hardware", "WindowedRes", iWindowedRes); iniFile.Set("Hardware", "WindowedRes", iWindowedRes);
iniFile.Set("Hardware", "FullscreenRes", iFSResolution); iniFile.Set("Hardware", "FullscreenRes", iFSResolution);
iniFile.Set("Hardware", "Fullscreen", bFullscreen); iniFile.Set("Hardware", "Fullscreen", bFullscreen);
@ -110,7 +101,6 @@ void Config::Save()
iniFile.Set("Settings", "ShowFPS", bShowFPS); iniFile.Set("Settings", "ShowFPS", bShowFPS);
iniFile.Set("Settings", "OverlayStats", bOverlayStats); iniFile.Set("Settings", "OverlayStats", bOverlayStats);
iniFile.Set("Settings", "Postprocess", iPostprocessEffect);
iniFile.Set("Settings", "DLOptimize", iCompileDLsLevel); iniFile.Set("Settings", "DLOptimize", iCompileDLsLevel);
iniFile.Set("Settings", "DumpTextures", bDumpTextures); iniFile.Set("Settings", "DumpTextures", bDumpTextures);
iniFile.Set("Settings", "ShowShaderErrors", bShowShaderErrors); iniFile.Set("Settings", "ShowShaderErrors", bShowShaderErrors);
@ -129,93 +119,19 @@ void Config::Save()
iniFile.Save("gfx_opengl.ini"); iniFile.Save("gfx_opengl.ini");
} }
#if defined(_MSC_VER)
#pragma pack(push, 1)
#endif
struct TGA_HEADER
{
u8 identsize; // size of ID field that follows 18 u8 header (0 usually)
u8 colourmaptype; // type of colour map 0=none, 1=has palette
u8 imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
s16 colourmapstart; // first colour map entry in palette
s16 colourmaplength; // number of colours in palette
u8 colourmapbits; // number of bits per palette entry 15,16,24,32
s16 xstart; // image x origin
s16 ystart; // image y origin
s16 width; // image width in pixels
s16 height; // image height in pixels
u8 bits; // image bits per pixel 8,16,24,32
u8 descriptor; // image descriptor bits (vh flip bits)
// pixel data follows header
};
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
bool SaveTGA(const char* filename, int width, int height, void* pdata)
{
TGA_HEADER hdr;
FILE* f = fopen(filename, "wb");
if (f == NULL)
return false;
_assert_( sizeof(TGA_HEADER) == 18 && sizeof(hdr) == 18 );
memset(&hdr, 0, sizeof(hdr));
hdr.imagetype = 2;
hdr.bits = 32;
hdr.width = width;
hdr.height = height;
hdr.descriptor |= 8|(1<<5); // 8bit alpha, flip vertical
fwrite(&hdr, sizeof(hdr), 1, f);
fwrite(pdata, width*height*4, 1, f);
fclose(f);
return true;
}
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height)
{
GL_REPORT_ERRORD();
std::vector<u32> data(width*height);
glBindTexture(textarget, tex);
glGetTexImage(textarget, 0, GL_BGRA, GL_UNSIGNED_BYTE, &data[0]);
GLenum err;
GL_REPORT_ERROR();
if (err != GL_NO_ERROR) {
return false;
}
return SaveTGA(filename, width, height, &data[0]);
}
bool SaveData(const char* filename, const char* data)
{
FILE* f = fopen(filename, "wb");
if (f == NULL)
return false;
fwrite(data, strlen(data), 1, f);
fclose(f);
return true;
}
#ifdef _WIN32 #ifdef _WIN32
// The one for Linux is in Linux/Linux.cpp // The one for Linux is in Linux/Linux.cpp
static HANDLE hConsole = NULL; static HANDLE hConsole = NULL;
void OpenConsole() {
void OpenConsole()
{
COORD csize; COORD csize;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
SMALL_RECT srect; SMALL_RECT srect;
if (hConsole) return; if (hConsole)
return;
AllocConsole(); AllocConsole();
SetConsoleTitle("Opengl Plugin Output"); SetConsoleTitle("Opengl Plugin Output");
@ -234,18 +150,18 @@ void OpenConsole() {
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
} }
void CloseConsole() { void CloseConsole()
if (hConsole == NULL) return; {
FreeConsole(); hConsole = NULL; if (hConsole == NULL)
return;
FreeConsole();
hConsole = NULL;
} }
#endif #endif
static FILE* pfLog = NULL; static FILE* pfLog = NULL;
void __Log(const char *fmt, ...) void __Log(const char *fmt, ...)
{ {
char* Msg = (char*)alloca(strlen(fmt)+512); char* Msg = (char*)alloca(strlen(fmt)+512);
va_list ap; va_list ap;
@ -255,7 +171,8 @@ void __Log(const char *fmt, ...)
g_VideoInitialize.pLog(Msg, FALSE); g_VideoInitialize.pLog(Msg, FALSE);
if( pfLog == NULL ) pfLog = fopen("Logs/oglgfx.txt", "w"); if (pfLog == NULL)
pfLog = fopen("Logs/oglgfx.txt", "w");
if (pfLog != NULL) if (pfLog != NULL)
fwrite(Msg, strlen(Msg), 1, pfLog); fwrite(Msg, strlen(Msg), 1, pfLog);
@ -265,12 +182,10 @@ void __Log(const char *fmt, ...)
#else #else
//printf("%s", Msg); //printf("%s", Msg);
#endif #endif
} }
void __Log(int type, const char *fmt, ...) void __Log(int type, const char *fmt, ...)
{ {
char* Msg = (char*)alloca(strlen(fmt)+512); char* Msg = (char*)alloca(strlen(fmt)+512);
va_list ap; va_list ap;
@ -284,5 +199,4 @@ void __Log(int type, const char *fmt, ...)
DWORD tmp; DWORD tmp;
WriteConsole(hConsole, Msg, (DWORD)strlen(Msg), &tmp, 0); WriteConsole(hConsole, Msg, (DWORD)strlen(Msg), &tmp, 0);
#endif #endif
} }

View File

@ -67,17 +67,8 @@ inline unsigned long timeGetTime()
return (unsigned long)(t.time*1000+t.millitm); return (unsigned long)(t.time*1000+t.millitm);
} }
struct RECT
{
int left, top;
int right, bottom;
};
#endif // linux basic definitions #endif // linux basic definitions
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#ifndef GL_DEPTH24_STENCIL8_EXT // allows FBOs to support stencils #ifndef GL_DEPTH24_STENCIL8_EXT // allows FBOs to support stencils
#define GL_DEPTH_STENCIL_EXT 0x84F9 #define GL_DEPTH_STENCIL_EXT 0x84F9
#define GL_UNSIGNED_INT_24_8_EXT 0x84FA #define GL_UNSIGNED_INT_24_8_EXT 0x84FA
@ -85,8 +76,6 @@ struct RECT
#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 #define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
#endif #endif
extern float MValueX, MValueY;
#define ERROR_LOG __Log #define ERROR_LOG __Log
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
@ -107,11 +96,6 @@ extern float MValueX, MValueY;
#define GL_REPORT_ERRORD() #define GL_REPORT_ERRORD()
#endif #endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
extern int frameCount;
#define CONF_LOG 1 #define CONF_LOG 1
#define CONF_PRIMLOG 2 #define CONF_PRIMLOG 2
@ -145,19 +129,11 @@ struct Config
bool bDumpTextures; bool bDumpTextures;
char texDumpPath[280]; char texDumpPath[280];
//currently unused:
int iLog; // CONF_ bits int iLog; // CONF_ bits
int iSaveTargetId; int iSaveTargetId;
int iAdapter;
char psProfile[16]; //currently unused:
char vsProfile[16];
int iPostprocessEffect;
int iCompileDLsLevel; int iCompileDLsLevel;
bool bPreUpscale;
int iPreUpscaleFilter;
bool bTruform;
int iTruformLevel;
bool bOldCard;
bool bWireFrame; bool bWireFrame;
bool bShowShaderErrors; bool bShowShaderErrors;
}; };
@ -199,7 +175,6 @@ struct Statistics
int numDLPrims; int numDLPrims;
int numPrims; int numPrims;
int numShaderChanges; int numShaderChanges;
int numBadCommands; //hope this always is zero ;)
int numDListsCalled; int numDListsCalled;
}; };
@ -226,11 +201,6 @@ void __Log(const char *format, ...);
void __Log(int type, const char *format, ...); void __Log(int type, const char *format, ...);
void HandleGLError(); void HandleGLError();
void InitLUTs();
bool SaveTGA(const char* filename, int width, int height, void* pdata);
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);
bool SaveData(const char* filename, const char* pdata);
#if defined(_MSC_VER) && !defined(__x86_64__) && !defined(_M_X64) #if defined(_MSC_VER) && !defined(__x86_64__) && !defined(_M_X64)
void * memcpy_amd(void *dest, const void *src, size_t n); void * memcpy_amd(void *dest, const void *src, size_t n);
unsigned char memcmp_mmx(const void* src1, const void* src2, int cmpsize); unsigned char memcmp_mmx(const void* src1, const void* src2, int cmpsize);

View File

@ -0,0 +1,97 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Globals.h"
#include <stdio.h>
#include "ImageWrite.h"
#if defined(_MSC_VER)
#pragma pack(push, 1)
#endif
struct TGA_HEADER
{
u8 identsize; // size of ID field that follows 18 u8 header (0 usually)
u8 colourmaptype; // type of colour map 0=none, 1=has palette
u8 imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
s16 colourmapstart; // first colour map entry in palette
s16 colourmaplength; // number of colours in palette
u8 colourmapbits; // number of bits per palette entry 15,16,24,32
s16 xstart; // image x origin
s16 ystart; // image y origin
s16 width; // image width in pixels
s16 height; // image height in pixels
u8 bits; // image bits per pixel 8,16,24,32
u8 descriptor; // image descriptor bits (vh flip bits)
// pixel data follows header
};
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
bool SaveTGA(const char* filename, int width, int height, void* pdata)
{
TGA_HEADER hdr;
FILE* f = fopen(filename, "wb");
if (f == NULL)
return false;
_assert_(sizeof(TGA_HEADER) == 18 && sizeof(hdr) == 18);
memset(&hdr, 0, sizeof(hdr));
hdr.imagetype = 2;
hdr.bits = 32;
hdr.width = width;
hdr.height = height;
hdr.descriptor |= 8|(1<<5); // 8bit alpha, flip vertical
fwrite(&hdr, sizeof(hdr), 1, f);
fwrite(pdata, width * height * 4, 1, f);
fclose(f);
return true;
}
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height)
{
GL_REPORT_ERRORD();
std::vector<u32> data(width * height);
glBindTexture(textarget, tex);
glGetTexImage(textarget, 0, GL_BGRA, GL_UNSIGNED_BYTE, &data[0]);
GLenum err;
GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
return false;
}
return SaveTGA(filename, width, height, &data[0]);
}
bool SaveData(const char* filename, const char* data)
{
FILE *f = fopen(filename, "wb");
if (!f)
return false;
fwrite(data, strlen(data), 1, f);
fclose(f);
return true;
}

View File

@ -0,0 +1,25 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _IMAGEWRITE_H
#define _IMAGEWRITE_H
bool SaveTGA(const char* filename, int width, int height, void* pdata);
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);
bool SaveData(const char* filename, const char* pdata);
#endif // _IMAGEWRITE_H

View File

@ -28,8 +28,8 @@
#include "Profiler.h" #include "Profiler.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexManager.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "TextureMngr.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "Fifo.h" #include "Fifo.h"

View File

@ -40,7 +40,7 @@ void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask);
void WriteAlphaCompare(char *&p, int num, int comp); void WriteAlphaCompare(char *&p, int num, int comp);
bool WriteAlphaTest(char *&p); bool WriteAlphaTest(char *&p);
const float epsilon = 1.0f/255.0f; const float epsilon8bit = 1.0f / 255.0f;
static const char *tevKSelTableC[] = // KCSEL static const char *tevKSelTableC[] = // KCSEL
{ {
@ -680,7 +680,7 @@ void WriteStage(char *&p, int n, u32 texture_mask)
case TEVCMP_R8_EQ: case TEVCMP_R8_EQ:
case TEVCMP_RGB8_EQ: case TEVCMP_RGB8_EQ:
WRITE(p, " %s + (abs(%s.r - %s.r)<%f ? %s : float3(0.0f,0.0f,0.0f));\n", WRITE(p, " %s + (abs(%s.r - %s.r)<%f ? %s : float3(0.0f,0.0f,0.0f));\n",
tevCInputTable[cc.d],tevCInputTable2[cc.a], tevCInputTable2[cc.b],epsilon,tevCInputTable[cc.c]); tevCInputTable[cc.d], tevCInputTable2[cc.a], tevCInputTable2[cc.b], epsilon8bit, tevCInputTable[cc.c]);
break; break;
case TEVCMP_GR16_GT: // 16 bit compares: 255*g+r (probably used for ztextures, so make sure in ztextures, g is the most significant byte) case TEVCMP_GR16_GT: // 16 bit compares: 255*g+r (probably used for ztextures, so make sure in ztextures, g is the most significant byte)
@ -691,7 +691,7 @@ void WriteStage(char *&p, int n, u32 texture_mask)
case TEVCMP_GR16_EQ: case TEVCMP_GR16_EQ:
case TEVCMP_BGR24_EQ: case TEVCMP_BGR24_EQ:
WRITE(p, " %s + (abs(dot(%s.rgb - %s.rgb, comp%s))<%f ? %s : float3(0.0f,0.0f,0.0f));\n", WRITE(p, " %s + (abs(dot(%s.rgb - %s.rgb, comp%s))<%f ? %s : float3(0.0f,0.0f,0.0f));\n",
tevCInputTable[cc.d],tevCInputTable2[cc.a], tevCInputTable2[cc.b],cmp==TEVCMP_GR16_GT?"16":"24",epsilon,tevCInputTable[cc.c]); tevCInputTable[cc.d], tevCInputTable2[cc.a], tevCInputTable2[cc.b], cmp==TEVCMP_GR16_GT?"16":"24", epsilon8bit, tevCInputTable[cc.c]);
break; break;
default: default:
WRITE(p, "float3(0.0f,0.0f,0.0f);\n"); WRITE(p, "float3(0.0f,0.0f,0.0f);\n");
@ -724,7 +724,7 @@ void WriteStage(char *&p, int n, u32 texture_mask)
case TEVCMP_R8_EQ: case TEVCMP_R8_EQ:
case TEVCMP_A8_EQ: case TEVCMP_A8_EQ:
WRITE(p, " %s + (abs(%s.r - %s.r)<%f ? %s : 0)\n", WRITE(p, " %s + (abs(%s.r - %s.r)<%f ? %s : 0)\n",
tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b],epsilon,tevAInputTable[ac.c]); tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b],epsilon8bit,tevAInputTable[ac.c]);
break; break;
case TEVCMP_GR16_GT: // 16 bit compares: 255*g+r (probably used for ztextures, so make sure in ztextures, g is the most significant byte) case TEVCMP_GR16_GT: // 16 bit compares: 255*g+r (probably used for ztextures, so make sure in ztextures, g is the most significant byte)
@ -735,7 +735,7 @@ void WriteStage(char *&p, int n, u32 texture_mask)
case TEVCMP_GR16_EQ: case TEVCMP_GR16_EQ:
case TEVCMP_BGR24_EQ: case TEVCMP_BGR24_EQ:
WRITE(p, " %s + (abs(dot(%s.rgb - %s.rgb, comp%s))<%f ? %s : 0)\n", WRITE(p, " %s + (abs(dot(%s.rgb - %s.rgb, comp%s))<%f ? %s : 0)\n",
tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b],cmp==TEVCMP_GR16_GT?"16":"24",epsilon,tevAInputTable[ac.c]); tevAInputTable[ac.d],tevAInputTable2[ac.a], tevAInputTable2[ac.b],cmp==TEVCMP_GR16_GT?"16":"24",epsilon8bit,tevAInputTable[ac.c]);
break; break;
default: default:
WRITE(p, "0)\n"); WRITE(p, "0)\n");
@ -777,11 +777,11 @@ void WriteAlphaCompare(char *&p, int num, int comp)
case ALPHACMP_ALWAYS: WRITE(p, "(false)"); break; case ALPHACMP_ALWAYS: WRITE(p, "(false)"); break;
case ALPHACMP_NEVER: WRITE(p, "(true)"); break; case ALPHACMP_NEVER: WRITE(p, "(true)"); break;
case ALPHACMP_LEQUAL: WRITE(p, "(prev.a > %s)",alphaRef[num]); break; case ALPHACMP_LEQUAL: WRITE(p, "(prev.a > %s)",alphaRef[num]); break;
case ALPHACMP_LESS: WRITE(p,"(prev.a >= %s - %f)",alphaRef[num],epsilon*0.5f);break; case ALPHACMP_LESS: WRITE(p, "(prev.a >= %s - %f)",alphaRef[num],epsilon8bit*0.5f);break;
case ALPHACMP_GEQUAL: WRITE(p, "(prev.a < %s)",alphaRef[num]); break; case ALPHACMP_GEQUAL: WRITE(p, "(prev.a < %s)",alphaRef[num]); break;
case ALPHACMP_GREATER: WRITE(p,"(prev.a <= %s + %f)",alphaRef[num],epsilon*0.5f);break; case ALPHACMP_GREATER: WRITE(p, "(prev.a <= %s + %f)",alphaRef[num],epsilon8bit*0.5f);break;
case ALPHACMP_EQUAL: WRITE(p,"(abs(prev.a-%s)>%f)",alphaRef[num],epsilon*2); break; case ALPHACMP_EQUAL: WRITE(p, "(abs(prev.a-%s)>%f)",alphaRef[num],epsilon8bit*2); break;
case ALPHACMP_NEQUAL: WRITE(p,"(abs(prev.a-%s)<%f)",alphaRef[num],epsilon*2); break; case ALPHACMP_NEQUAL: WRITE(p, "(abs(prev.a-%s)<%f)",alphaRef[num],epsilon8bit*2); break;
} }
} }

View File

@ -18,6 +18,9 @@
#include "Globals.h" #include "Globals.h"
#include "Profiler.h" #include "Profiler.h"
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <cmath> #include <cmath>
#include "Common.h" #include "Common.h"
@ -89,7 +92,6 @@ void PixelShaderMngr::Init()
"END\n", C_COLORMATRIX+3, C_COLORMATRIX+2, C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+4); "END\n", C_COLORMATRIX+3, C_COLORMATRIX+2, C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+4);
glGenProgramsARB(1, &s_ColorMatrixProgram); glGenProgramsARB(1, &s_ColorMatrixProgram);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, s_ColorMatrixProgram); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, s_ColorMatrixProgram);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog); glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
GLenum err = GL_NO_ERROR; GLenum err = GL_NO_ERROR;
@ -334,7 +336,9 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
if (s_nIndTexMtxChanged) { if (s_nIndTexMtxChanged) {
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (s_nIndTexMtxChanged & (1 << i)) { if (s_nIndTexMtxChanged & (1 << i)) {
int scale = ((u32)bpmem.indmtx[i].col0.s0<<0)|((u32)bpmem.indmtx[i].col1.s1<<2)|((u32)bpmem.indmtx[i].col2.s2<<4); int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) |
((u32)bpmem.indmtx[i].col1.s1 << 2) |
((u32)bpmem.indmtx[i].col2.s2 << 4);
float fscale = powf(2.0f,(float)(scale - 17)) / 1024.0f; float fscale = powf(2.0f,(float)(scale - 17)) / 1024.0f;
// xyz - static matrix // xyz - static matrix
@ -394,8 +398,10 @@ void PixelShaderMngr::SetPSTextureDims(int texid)
void PixelShaderMngr::SetColorChanged(int type, int num) void PixelShaderMngr::SetColorChanged(int type, int num)
{ {
int r=bpmem.tevregs[num].low.a, a=bpmem.tevregs[num].low.b; int r = bpmem.tevregs[num].low.a;
int b=bpmem.tevregs[num].high.a, g=bpmem.tevregs[num].high.b; int a = bpmem.tevregs[num].low.b;
int b = bpmem.tevregs[num].high.a;
int g = bpmem.tevregs[num].high.b;
float *pf = &lastRGBAfull[type][num][0]; float *pf = &lastRGBAfull[type][num][0];
pf[0] = (float)r / 255.0f; pf[0] = (float)r / 255.0f;
pf[1] = (float)g / 255.0f; pf[1] = (float)g / 255.0f;

View File

@ -18,12 +18,16 @@
#include "Globals.h" #include "Globals.h"
#include <list> #include <list>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#ifdef _WIN32 #ifdef _WIN32
#include <mmsystem.h> #include <mmsystem.h>
#endif #endif
#include "GLInit.h" #include "GLInit.h"
#include "Profiler.h" #include "Profiler.h"
#include "ImageWrite.h"
#include "Render.h" #include "Render.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "BPStructs.h" #include "BPStructs.h"
@ -67,6 +71,8 @@ static Renderer::RenderMode s_RenderMode = Renderer::RM_Normal;
static int s_nCurTarget = 0; static int s_nCurTarget = 0;
bool g_bBlendLogicOp = false; 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); void HandleCgError(CGcontext ctx, CGerror err, void* appdata);
@ -376,7 +382,6 @@ void Renderer::ProcessMessages()
if (s_listMsgs.size() > 0) { if (s_listMsgs.size() > 0) {
int left = 25, top = 15; int left = 25, top = 15;
list<MESSAGE>::iterator it = s_listMsgs.begin(); list<MESSAGE>::iterator it = s_listMsgs.begin();
while (it != s_listMsgs.end()) while (it != s_listMsgs.end())
{ {
int time_left = (int)(it->dwTimeStamp - timeGetTime()); int time_left = (int)(it->dwTimeStamp - timeGetTime());
@ -761,7 +766,6 @@ void Renderer::SwapBuffers()
//p+=sprintf(p,"Num strip joins: %i\n",stats.numJoins); //p+=sprintf(p,"Num strip joins: %i\n",stats.numJoins);
p+=sprintf(p,"Num primitives: %i\n",stats.thisFrame.numPrims); p+=sprintf(p,"Num primitives: %i\n",stats.thisFrame.numPrims);
p+=sprintf(p,"Num primitives (DL): %i\n",stats.thisFrame.numDLPrims); p+=sprintf(p,"Num primitives (DL): %i\n",stats.thisFrame.numDLPrims);
p+=sprintf(p,"Num bad commands: %i%s\n",stats.thisFrame.numBadCommands,stats.thisFrame.numBadCommands?"!!!":"");
p+=sprintf(p,"Num XF loads: %i\n",stats.thisFrame.numXFLoads); p+=sprintf(p,"Num XF loads: %i\n",stats.thisFrame.numXFLoads);
p+=sprintf(p,"Num XF loads (DL): %i\n",stats.thisFrame.numXFLoadsInDL); p+=sprintf(p,"Num XF loads (DL): %i\n",stats.thisFrame.numXFLoadsInDL);
p+=sprintf(p,"Num CP loads: %i\n",stats.thisFrame.numCPLoads); p+=sprintf(p,"Num CP loads: %i\n",stats.thisFrame.numCPLoads);

View File

@ -20,9 +20,15 @@
#include "TextureMngr.h" #include "TextureMngr.h"
#include <Cg/cg.h>
#include <Cg/cgGL.h>
extern CGcontext g_cgcontext; extern CGcontext g_cgcontext;
extern CGprofile g_cgvProf, g_cgfProf; extern CGprofile g_cgvProf, g_cgfProf;
extern float MValueX, MValueY;
extern int frameCount;
class Renderer class Renderer
{ {
static void FlushZBufferAlphaToTarget(); static void FlushZBufferAlphaToTarget();

View File

@ -18,6 +18,8 @@ files = [
'rasterfont.cpp', 'rasterfont.cpp',
'Render.cpp', 'Render.cpp',
'TextureMngr.cpp', 'TextureMngr.cpp',
'ImageWrite.cpp',
'VertexManager.cpp',
'VertexLoader.cpp', 'VertexLoader.cpp',
'VertexLoader_Normal.cpp', 'VertexLoader_Normal.cpp',
'VertexShader.cpp', 'VertexShader.cpp',

View File

@ -30,6 +30,7 @@
#endif #endif
#include "Profiler.h" #include "Profiler.h"
#include "ImageWrite.h"
#include "Render.h" #include "Render.h"

View File

@ -16,16 +16,19 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h" #include "Globals.h"
#include <fstream> #include <fstream>
#include <assert.h> #include <assert.h>
#include "Common.h" #include "Common.h"
#include "ImageWrite.h"
#include "x64Emitter.h" #include "x64Emitter.h"
#include "ABI.h" #include "ABI.h"
#include "Profiler.h" #include "Profiler.h"
#include "StringUtil.h" #include "StringUtil.h"
#include "Render.h" #include "Render.h"
#include "VertexManager.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "DataReader.h" #include "DataReader.h"
@ -38,17 +41,7 @@
#include <fstream> #include <fstream>
#define MAX_BUFFER_SIZE 0x4000 extern void (*fnSetupVertexPointers)();
// internal state for loading vertices
static u32 s_prevvbstride, s_prevcomponents; // previous state set
static u8 *s_pBaseBufferPointer = NULL;
static GLuint s_vboBuffers[0x40] = {0};
static int s_nCurVBOIndex = 0; // current free buffer
static GLenum s_prevprimitive = 0; // current primitive type
static vector< pair<int, int> > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays
static void (*fnSetupVertexPointers)() = NULL;
//these don't need to be saved //these don't need to be saved
static float posScale; static float posScale;
@ -62,11 +55,18 @@ static int colIndex;
#define inline #define inline
#endif #endif
TVtxDesc VertexManager::s_GlobalVtxDesc;
float VertexManager::shiftLookup[32];
// ============================================================================== // ==============================================================================
// Direct // Direct
// ============================================================================== // ==============================================================================
static u8 s_curposmtx, s_curtexmtx[8]; static u8 s_curposmtx;
static int s_texmtxwrite = 0, s_texmtxread = 0; static u8 s_curtexmtx[8];
static int s_texmtxwrite = 0;
static int s_texmtxread = 0;
void LOADERDECL PosMtx_ReadDirect_UByte(void* _p) void LOADERDECL PosMtx_ReadDirect_UByte(void* _p)
{ {
@ -258,7 +258,6 @@ int VertexLoader::ComputeVertexSize()
return m_VertexSize; return m_VertexSize;
} }
// Note the use of CallCdeclFunction3I etc. // Note the use of CallCdeclFunction3I etc.
// This is a horrible hack that is necessary because Opengl32.dll is based way, way above the 32-bit address space // This is a horrible hack that is necessary because Opengl32.dll is based way, way above the 32-bit address space
// that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we want to grab // that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we want to grab
@ -668,8 +667,9 @@ void VertexLoader::WriteCall(void (LOADERDECL *func)(void *))
void VertexLoader::RunVertices(int primitive, int count) void VertexLoader::RunVertices(int primitive, int count)
{ {
ComputeVertexSize(); // HACK for underruns in Super Monkey Ball etc. !!!! DVSTARTPROFILE();
ComputeVertexSize(); // HACK for underruns in Super Monkey Ball etc. !!!! dirty handling must be wrong.
if (count <= 0) if (count <= 0)
return; return;
@ -683,17 +683,15 @@ void VertexLoader::RunVertices(int primitive, int count)
return; return;
} }
DVSTARTPROFILE();
ProcessFormat(); ProcessFormat();
fnSetupVertexPointers = (void (*)())(void*)m_compiledCode; fnSetupVertexPointers = (void (*)())(void*)m_compiledCode;
if (s_prevcomponents != m_components) { // Move this code into VertexManager?
if (VertexManager::s_prevcomponents != m_components) {
VertexManager::Flush(); VertexManager::Flush();
// matrices // matrices
if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents&VB_HAS_POSMTXIDX)) { if ((m_components & VB_HAS_POSMTXIDX) != (VertexManager::s_prevcomponents & VB_HAS_POSMTXIDX)) {
if (m_components & VB_HAS_POSMTXIDX) if (m_components & VB_HAS_POSMTXIDX)
glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
else else
@ -701,13 +699,13 @@ void VertexLoader::RunVertices(int primitive, int count)
} }
// normals // normals
if ((m_components & VB_HAS_NRM0) != (s_prevcomponents&VB_HAS_NRM0)) { if ((m_components & VB_HAS_NRM0) != (VertexManager::s_prevcomponents & VB_HAS_NRM0)) {
if (m_components & VB_HAS_NRM0) if (m_components & VB_HAS_NRM0)
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
else else
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
} }
if ((m_components & VB_HAS_NRM1) != (s_prevcomponents&VB_HAS_NRM1)) { if ((m_components & VB_HAS_NRM1) != (VertexManager::s_prevcomponents & VB_HAS_NRM1)) {
if (m_components & VB_HAS_NRM1) { if (m_components & VB_HAS_NRM1) {
glEnableVertexAttribArray(SHADER_NORM1_ATTRIB); glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
glEnableVertexAttribArray(SHADER_NORM2_ATTRIB); glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
@ -720,7 +718,7 @@ void VertexLoader::RunVertices(int primitive, int count)
// color // color
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
if ( (m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i)) ) { if ((m_components & (VB_HAS_COL0 << i)) != (VertexManager::s_prevcomponents & (VB_HAS_COL0 << i))) {
if (m_components & (VB_HAS_COL0 << 0)) if (m_components & (VB_HAS_COL0 << 0))
glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY); glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
else else
@ -730,8 +728,7 @@ void VertexLoader::RunVertices(int primitive, int count)
// tex // tex
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
if ((m_components&(VB_HAS_UV0<<i)) != (s_prevcomponents&(VB_HAS_UV0<<i))) { if ((m_components & (VB_HAS_UV0 << i)) != (VertexManager::s_prevcomponents & (VB_HAS_UV0 << i))) {
glClientActiveTexture(GL_TEXTURE0 + i); glClientActiveTexture(GL_TEXTURE0 + i);
if (m_components & (VB_HAS_UV0 << i)) if (m_components & (VB_HAS_UV0 << i))
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@ -740,8 +737,8 @@ void VertexLoader::RunVertices(int primitive, int count)
} }
} }
s_prevcomponents = m_components; VertexManager::s_prevcomponents = m_components;
s_prevvbstride = m_VBVertexStride; VertexManager::s_prevvbstride = m_VBVertexStride;
} }
PrepareRun(); PrepareRun();
@ -771,18 +768,18 @@ void VertexLoader::RunVertices(int primitive, int count)
} }
int startv = 0, extraverts = 0; int startv = 0, extraverts = 0;
for (int v = 0; v < count; v++) { for (int v = 0; v < count; v++)
{
if( (v % granularity) == 0 ) { if ((v % granularity) == 0)
{
if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) { if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) {
u8* plastptr = VertexManager::s_pCurBufferPointer; u8* plastptr = VertexManager::s_pCurBufferPointer;
if (v-startv > 0) if (v-startv > 0)
VertexManager::AddVertices(primitive, v-startv+extraverts); VertexManager::AddVertices(primitive, v-startv+extraverts);
VertexManager::Flush(); VertexManager::Flush();
// Why does this need to be so complicated?
switch (primitive) { switch (primitive) {
case 3: // triangle strip, copy last two vertices case 3: // triangle strip, copy last two vertices
// a little trick since we have to keep track of signs // a little trick since we have to keep track of signs
if (v & 1) { if (v & 1) {
memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-2*m_VBVertexStride, m_VBVertexStride); memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-2*m_VBVertexStride, m_VBVertexStride);
@ -812,29 +809,14 @@ void VertexLoader::RunVertices(int primitive, int count)
extraverts = 0; extraverts = 0;
break; break;
} }
startv = v; startv = v;
} }
} }
tcIndex = 0; tcIndex = 0;
colIndex = 0; colIndex = 0;
s_texmtxwrite = s_texmtxread = 0; s_texmtxwrite = s_texmtxread = 0;
// int pred_size = m_VertexSize;
//int start = GetBufferPosition();
//if (!m_numPipelineStates)
// PanicAlert("trying to draw with no pipeline");
for (int i = 0; i < m_numPipelineStates; i++) for (int i = 0; i < m_numPipelineStates; i++)
m_PipelineStates[i](&m_VtxAttr); m_PipelineStates[i](&m_VtxAttr);
//int end = GetBufferPosition();
//if (end - start != pred_size) {
// std::string vtx_summary;
// vtx_summary += StringFromFormat("Nrm d:%i f:%i e:%i 3:%i", m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3);
// PanicAlert((vtx_summary + "\nWTF %i %i").c_str(), end - start, pred_size);
//}
VertexManager::s_pCurBufferPointer += m_VBStridePad; VertexManager::s_pCurBufferPointer += m_VBStridePad;
PRIM_LOG("\n"); PRIM_LOG("\n");
@ -843,308 +825,3 @@ void VertexLoader::RunVertices(int primitive, int count)
if (startv < count) if (startv < count)
VertexManager::AddVertices(primitive, count-startv+extraverts); VertexManager::AddVertices(primitive, count-startv+extraverts);
} }
///////////////////
// VertexManager //
///////////////////
TVtxDesc VertexManager::s_GlobalVtxDesc;
u8* VertexManager::s_pCurBufferPointer=NULL;
float VertexManager::shiftLookup[32];
const GLenum c_primitiveType[8] =
{
GL_QUADS,
0, //nothing
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN,
GL_LINES,
GL_LINE_STRIP,
GL_POINTS
};
bool VertexManager::Init()
{
Destroy();
s_GlobalVtxDesc.Hex = 0;
s_prevcomponents = 0;
s_prevvbstride = 12; // just pos
s_prevprimitive = 0;
s_pBaseBufferPointer = (u8*)AllocateMemoryPages(MAX_BUFFER_SIZE);
s_pCurBufferPointer = s_pBaseBufferPointer;
for (u32 i = 0; i < ARRAYSIZE(shiftLookup); i++)
shiftLookup[i] = 1.0f / float(1 << i);
s_nCurVBOIndex = 0;
glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
for (u32 i = 0; i < ARRAYSIZE(s_vboBuffers); ++i) {
glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[i]);
glBufferData(GL_ARRAY_BUFFER, MAX_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
}
glEnableClientState(GL_VERTEX_ARRAY);
fnSetupVertexPointers = NULL;
GL_REPORT_ERRORD();
return true;
}
void VertexManager::Destroy()
{
FreeMemoryPages(s_pBaseBufferPointer, MAX_BUFFER_SIZE); s_pBaseBufferPointer = s_pCurBufferPointer = NULL;
glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
memset(s_vboBuffers, 0, sizeof(s_vboBuffers));
s_vStoredPrimitives.resize(0);
s_nCurVBOIndex = 0;
ResetBuffer();
}
void VertexManager::ResetBuffer()
{
s_nCurVBOIndex = (s_nCurVBOIndex+1)%ARRAYSIZE(s_vboBuffers);
s_pCurBufferPointer = s_pBaseBufferPointer;
s_vStoredPrimitives.resize(0);
}
void VertexManager::ResetComponents()
{
s_prevcomponents = 0;
s_prevvbstride = 12; // just pos
s_prevprimitive = 0;
glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
for (int i = 0; i < 8; ++i) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
int VertexManager::GetRemainingSize()
{
return MAX_BUFFER_SIZE - (int)(s_pCurBufferPointer-s_pBaseBufferPointer);
}
void VertexManager::AddVertices(int primitive, int numvertices)
{
_assert_( numvertices > 0 );
ADDSTAT(stats.thisFrame.numPrims, numvertices);
s_vStoredPrimitives.push_back(pair<int, int>(c_primitiveType[primitive], numvertices));
#ifdef _DEBUG
static const char *sprims[8] = {"quads", "nothing", "tris", "tstrip", "tfan", "lines", "lstrip", "points"};
PRIM_LOG("prim: %s, c=%d\n", sprims[primitive], numvertices);
#endif
}
void VertexManager::Flush()
{
if (s_vStoredPrimitives.size() == 0)
return;
_assert_( fnSetupVertexPointers != NULL );
_assert_( s_pCurBufferPointer != s_pBaseBufferPointer );
#ifdef _DEBUG
PRIM_LOG("frame%d:\ncomps=0x%x, texgen=%d, numchan=%d, dualtex=%d, ztex=%d, proj=%d, cole=%d, alpe=%d, ze=%d\n", g_Config.iSaveTargetId, s_prevcomponents, xfregs.numTexGens,
xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op, VertexShaderMngr::rawProjection[6]==0,
bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable);
for(int i = 0; i < xfregs.nNumChans; ++i) {
LitChannel* ch = &xfregs.colChans[i].color;
PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
ch = &xfregs.colChans[i].alpha;
PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
}
for(int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
if( tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff;
if( tinfo.texgentype != XF_TEXGEN_REGULAR ) tinfo.projection = 0;
PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d\n",
i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift,
xfregs.texcoords[i].postmtxinfo.index, xfregs.texcoords[i].postmtxinfo.normalize);
}
PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphafunc=0x%x\n", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,
bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alphaFunc.hex>>16)&0xff);
#endif
DVSTARTPROFILE();
GL_REPORT_ERRORD();
glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[s_nCurVBOIndex]);
glBufferData(GL_ARRAY_BUFFER, s_pCurBufferPointer-s_pBaseBufferPointer, s_pBaseBufferPointer, GL_STREAM_DRAW);
GL_REPORT_ERRORD();
// setup the pointers
fnSetupVertexPointers();
GL_REPORT_ERRORD();
// set the textures
{
DVProfileFunc _pf("VertexManager::Flush:textures");
u32 usedtextures = 0;
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages+1; ++i) {
if( bpmem.tevorders[i/2].getEnable(i&1) )
usedtextures |= 1<<bpmem.tevorders[i/2].getTexMap(i&1);
}
if( bpmem.genMode.numindstages > 0 ) {
for(u32 i = 0; i < (u32)bpmem.genMode.numtevstages+1; ++i) {
if( bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages ) {
usedtextures |= 1<<bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
}
}
}
u32 nonpow2tex = 0;
for (int i = 0; i < 8; i++) {
if (usedtextures&(1<<i)) {
glActiveTexture(GL_TEXTURE0+i);
FourTexUnits &tex = bpmem.tex[i>>2];
TextureMngr::TCacheEntry* tentry = TextureMngr::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, tex.texTlut[i&3].tlut_format);
if( tentry != NULL ) {
// texture loaded fine, set dims for pixel shader
if( tentry->isNonPow2 ) {
PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, tentry->mode.wrap_s, tentry->mode.wrap_t);
nonpow2tex |= 1<<i;
if( tentry->mode.wrap_s > 0 ) nonpow2tex |= 1<<(8+i);
if( tentry->mode.wrap_t > 0 ) nonpow2tex |= 1<<(16+i);
TextureMngr::EnableTexRECT(i);
}
// if texture is power of two, set to ones (since don't need scaling)
else
{
PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, 0, 0);
TextureMngr::EnableTex2D(i);
}
if( g_Config.iLog & CONF_PRIMLOG ) {
// save the textures
char strfile[255];
sprintf(strfile, "frames/tex%.3d_%d.tga", g_Config.iSaveTargetId, i);
SaveTexture(strfile, tentry->isNonPow2?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D, tentry->texture, tentry->w, tentry->h);
}
}
else {
ERROR_LOG("error loading tex\n");
TextureMngr::DisableStage(i); // disable since won't be used
}
}
else {
TextureMngr::DisableStage(i); // disable since won't be used
}
}
PixelShaderMngr::SetTexturesUsed(nonpow2tex);
}
FRAGMENTSHADER* ps = PixelShaderMngr::GetShader();
VERTEXSHADER* vs = VertexShaderMngr::GetShader(s_prevcomponents);
_assert_( ps != NULL && vs != NULL );
bool bRestoreBuffers = false;
if( Renderer::GetZBufferTarget() ) {
if( bpmem.zmode.updateenable ) {
if( !bpmem.blendmode.colorupdate ) {
Renderer::SetRenderMode(bpmem.blendmode.alphaupdate?Renderer::RM_ZBufferAlpha:Renderer::RM_ZBufferOnly);
}
}
else {
Renderer::SetRenderMode(Renderer::RM_Normal);
// remove temporarily
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
bRestoreBuffers = true;
}
}
else
Renderer::SetRenderMode(Renderer::RM_Normal);
// set global constants
VertexShaderMngr::SetConstants(*vs);
PixelShaderMngr::SetConstants(*ps);
// finally bind
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid);
PRIM_LOG("\n");
int offset = 0;
vector< pair<int, int> >::iterator it;
for (it = s_vStoredPrimitives.begin(); it != s_vStoredPrimitives.end(); ++it) {
glDrawArrays(it->first, offset, it->second);
offset += it->second;
}
#ifdef _DEBUG
if( g_Config.iLog & CONF_PRIMLOG ) {
// save the shaders
char strfile[255];
sprintf(strfile, "frames/ps%.3d.txt", g_Config.iSaveTargetId);
std::ofstream fps(strfile);
fps << ps->strprog.c_str();
sprintf(strfile, "frames/vs%.3d.txt", g_Config.iSaveTargetId);
ofstream fvs(strfile);
fvs << vs->strprog.c_str();
}
if( g_Config.iLog & CONF_SAVETARGETS ) {
char str[128];
sprintf(str, "frames/targ%.3d.tga", g_Config.iSaveTargetId);
Renderer::SaveRenderTarget(str, 0);
}
#endif
g_Config.iSaveTargetId++;
GL_REPORT_ERRORD();
if( bRestoreBuffers ) {
GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
glDrawBuffers(2, s_drawbuffers);
SetColorMask();
}
ResetBuffer();
}
void VertexManager::LoadCPReg(u32 SubCmd, u32 Value)
{
switch (SubCmd & 0xF0)
{
case 0x30:
VertexShaderMngr::SetTexMatrixChangedA(Value);
break;
case 0x40:
VertexShaderMngr::SetTexMatrixChangedB(Value);
break;
case 0x50:
s_GlobalVtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits
s_GlobalVtxDesc.Hex |= Value;
break;
case 0x60:
s_GlobalVtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits
s_GlobalVtxDesc.Hex |= (u64)Value << 17;
break;
case 0x70: g_VertexLoaders[SubCmd & 7].SetVAT_group0(Value); _assert_((SubCmd & 0x0F) < 8); break;
case 0x80: g_VertexLoaders[SubCmd & 7].SetVAT_group1(Value); _assert_((SubCmd & 0x0F) < 8); break;
case 0x90: g_VertexLoaders[SubCmd & 7].SetVAT_group2(Value); _assert_((SubCmd & 0x0F) < 8); break;
case 0xA0: arraybases[SubCmd & 0xF] = Value & 0xFFFFFFFF; break;
case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break;
}
}

View File

@ -32,7 +32,8 @@ using namespace std;
#define LOADERDECL __cdecl #define LOADERDECL __cdecl
typedef void (LOADERDECL *TPipelineFunction)(void*); typedef void (LOADERDECL *TPipelineFunction)(void*);
/// Use to manage loading and setting vertex buffer data for OpenGL // There are 8 of these. Most games only use the first, and just reconfigure it all the time
// as needed, unfortunately.
class VertexLoader class VertexLoader
{ {
public: public:
@ -97,10 +98,10 @@ private:
//common for all loaders //common for all loaders
TVtxDesc m_VtxDesc; TVtxDesc m_VtxDesc;
// seup the pipeline with this vertex fmt
void SetupColor(int num, int _iMode, int _iFormat, int _iElements); void SetupColor(int num, int _iMode, int _iFormat, int _iElements);
void SetupTexCoord(int num, int _iMode, int _iFormat, int _iElements, int _iFrac); void SetupTexCoord(int num, int _iMode, int _iFormat, int _iElements, int _iFrac);
// The 3 possible values (0, 1, 2) should be documented here.
int m_AttrDirty; int m_AttrDirty;
public: public:
@ -186,38 +187,6 @@ public:
}; };
}; };
/// Methods to manage and cache the global state of vertex streams and flushing streams
/// Also handles processing the CP registers
class VertexManager
{
static TVtxDesc s_GlobalVtxDesc;
public:
enum Collection
{
C_NOTHING=0,
C_TRIANGLES=1,
C_LINES=2,
C_POINTS=3
};
static bool Init();
static void Destroy();
static void ResetBuffer();
static void ResetComponents();
static void AddVertices(int primitive, int numvertices);
static void Flush(); // flushes the current buffer
static int GetRemainingSize();
static TVtxDesc &GetVtxDesc() {return s_GlobalVtxDesc; }
static void LoadCPReg(u32 SubCmd, u32 Value);
static u8* s_pCurBufferPointer;
static float shiftLookup[32];
};
extern VertexLoader g_VertexLoaders[8]; extern VertexLoader g_VertexLoaders[8];
#endif #endif

View File

@ -15,11 +15,9 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
//__________________________________________________________________________________________________
// F|RES 2003-2005
//
#include "Globals.h" #include "Globals.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexManager.h"
#include "VertexLoader_Normal.h" #include "VertexLoader_Normal.h"
#define LOG_NORM8() PRIM_LOG("norm: %f %f %f, ", ((s8*)VertexManager::s_pCurBufferPointer)[-3]/127.0f, ((s8*)VertexManager::s_pCurBufferPointer)[-2]/127.0f, ((s8*)VertexManager::s_pCurBufferPointer)[-1]/127.0f); #define LOG_NORM8() PRIM_LOG("norm: %f %f %f, ", ((s8*)VertexManager::s_pCurBufferPointer)[-3]/127.0f, ((s8*)VertexManager::s_pCurBufferPointer)[-2]/127.0f, ((s8*)VertexManager::s_pCurBufferPointer)[-1]/127.0f);
@ -30,9 +28,7 @@ u8 VertexLoader_Normal::m_sizeTable[NUM_NRM_TYPE][NUM_NRM_FORMAT][NUM_NRM_EL
TPipelineFunction VertexLoader_Normal::m_funcTable[NUM_NRM_TYPE][NUM_NRM_FORMAT][NUM_NRM_ELEMENTS]; TPipelineFunction VertexLoader_Normal::m_funcTable[NUM_NRM_TYPE][NUM_NRM_FORMAT][NUM_NRM_ELEMENTS];
bool VertexLoader_Normal::index3; bool VertexLoader_Normal::index3;
// __________________________________________________________________________________________________
// Init
//
void VertexLoader_Normal::Init(void) void VertexLoader_Normal::Init(void)
{ {
// size table // size table

View File

@ -0,0 +1,325 @@
#include "Globals.h"
#include "MemoryUtil.h"
#include "Profiler.h"
#include "Render.h"
#include "ImageWrite.h"
#include "BPMemory.h"
#include "TextureMngr.h"
#include "PixelShaderManager.h"
#include "VertexShaderManager.h"
#include "VertexLoader.h"
#include "VertexManager.h"
#define MAX_BUFFER_SIZE 0x4000
static GLuint s_vboBuffers[0x40] = {0};
static int s_nCurVBOIndex = 0; // current free buffer
static GLenum s_prevprimitive = 0; // current primitive type
static u8 *s_pBaseBufferPointer = NULL;
static vector< pair<int, int> > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays
u8* VertexManager::s_pCurBufferPointer = NULL;
u32 VertexManager::s_prevvbstride;
u32 VertexManager::s_prevcomponents; // previous state set
const GLenum c_primitiveType[8] =
{
GL_QUADS,
0, //nothing
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN,
GL_LINES,
GL_LINE_STRIP,
GL_POINTS
};
// internal state for loading vertices
void (*fnSetupVertexPointers)() = NULL;
bool VertexManager::Init()
{
Destroy();
s_GlobalVtxDesc.Hex = 0;
s_prevcomponents = 0;
s_prevvbstride = 12; // just pos
s_prevprimitive = 0;
s_pBaseBufferPointer = (u8*)AllocateMemoryPages(MAX_BUFFER_SIZE);
s_pCurBufferPointer = s_pBaseBufferPointer;
for (u32 i = 0; i < ARRAYSIZE(shiftLookup); i++)
shiftLookup[i] = 1.0f / float(1 << i);
s_nCurVBOIndex = 0;
glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
for (u32 i = 0; i < ARRAYSIZE(s_vboBuffers); ++i) {
glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[i]);
glBufferData(GL_ARRAY_BUFFER, MAX_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
}
glEnableClientState(GL_VERTEX_ARRAY);
fnSetupVertexPointers = NULL;
GL_REPORT_ERRORD();
return true;
}
void VertexManager::Destroy()
{
FreeMemoryPages(s_pBaseBufferPointer, MAX_BUFFER_SIZE); s_pBaseBufferPointer = s_pCurBufferPointer = NULL;
glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
memset(s_vboBuffers, 0, sizeof(s_vboBuffers));
s_vStoredPrimitives.resize(0);
s_nCurVBOIndex = 0;
ResetBuffer();
}
void VertexManager::ResetBuffer()
{
s_nCurVBOIndex = (s_nCurVBOIndex+1)%ARRAYSIZE(s_vboBuffers);
s_pCurBufferPointer = s_pBaseBufferPointer;
s_vStoredPrimitives.resize(0);
}
void VertexManager::ResetComponents()
{
s_prevcomponents = 0;
s_prevvbstride = 12; // just pos
s_prevprimitive = 0;
glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
for (int i = 0; i < 8; ++i) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
int VertexManager::GetRemainingSize()
{
return MAX_BUFFER_SIZE - (int)(s_pCurBufferPointer-s_pBaseBufferPointer);
}
void VertexManager::AddVertices(int primitive, int numvertices)
{
_assert_( numvertices > 0 );
ADDSTAT(stats.thisFrame.numPrims, numvertices);
s_vStoredPrimitives.push_back(pair<int, int>(c_primitiveType[primitive], numvertices));
#ifdef _DEBUG
static const char *sprims[8] = {"quads", "nothing", "tris", "tstrip", "tfan", "lines", "lstrip", "points"};
PRIM_LOG("prim: %s, c=%d\n", sprims[primitive], numvertices);
#endif
}
void VertexManager::Flush()
{
if (s_vStoredPrimitives.size() == 0)
return;
_assert_( fnSetupVertexPointers != NULL );
_assert_( s_pCurBufferPointer != s_pBaseBufferPointer );
#ifdef _DEBUG
PRIM_LOG("frame%d:\ncomps=0x%x, texgen=%d, numchan=%d, dualtex=%d, ztex=%d, proj=%d, cole=%d, alpe=%d, ze=%d\n", g_Config.iSaveTargetId, s_prevcomponents, xfregs.numTexGens,
xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op, VertexShaderMngr::rawProjection[6]==0,
bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable);
for (int i = 0; i < xfregs.nNumChans; ++i) {
LitChannel* ch = &xfregs.colChans[i].color;
PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
ch = &xfregs.colChans[i].alpha;
PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
}
for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff;
if (tinfo.texgentype != XF_TEXGEN_REGULAR ) tinfo.projection = 0;
PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d\n",
i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift,
xfregs.texcoords[i].postmtxinfo.index, xfregs.texcoords[i].postmtxinfo.normalize);
}
PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphafunc=0x%x\n", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,
bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alphaFunc.hex>>16)&0xff);
#endif
DVSTARTPROFILE();
GL_REPORT_ERRORD();
glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[s_nCurVBOIndex]);
glBufferData(GL_ARRAY_BUFFER, s_pCurBufferPointer-s_pBaseBufferPointer, s_pBaseBufferPointer, GL_STREAM_DRAW);
GL_REPORT_ERRORD();
// setup the pointers
fnSetupVertexPointers();
GL_REPORT_ERRORD();
// set the textures
{
DVProfileFunc _pf("VertexManager::Flush:textures");
u32 usedtextures = 0;
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
if (bpmem.tevorders[i/2].getEnable(i & 1))
usedtextures |= 1<<bpmem.tevorders[i/2].getTexMap(i & 1);
}
if (bpmem.genMode.numindstages > 0) {
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) {
usedtextures |= 1<<bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
}
}
}
u32 nonpow2tex = 0;
for (int i = 0; i < 8; i++) {
if (usedtextures & (1 << i)) {
glActiveTexture(GL_TEXTURE0+i);
FourTexUnits &tex = bpmem.tex[i>>2];
TextureMngr::TCacheEntry* tentry = TextureMngr::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, tex.texTlut[i&3].tlut_format);
if (tentry != NULL) {
// texture loaded fine, set dims for pixel shader
if (tentry->isNonPow2) {
PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, tentry->mode.wrap_s, tentry->mode.wrap_t);
nonpow2tex |= 1<<i;
if (tentry->mode.wrap_s > 0 ) nonpow2tex |= 1<<(8+i);
if (tentry->mode.wrap_t > 0 ) nonpow2tex |= 1<<(16+i);
TextureMngr::EnableTexRECT(i);
}
// if texture is power of two, set to ones (since don't need scaling)
else
{
PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, 0, 0);
TextureMngr::EnableTex2D(i);
}
if (g_Config.iLog & CONF_PRIMLOG) {
// save the textures
char strfile[255];
sprintf(strfile, "frames/tex%.3d_%d.tga", g_Config.iSaveTargetId, i);
SaveTexture(strfile, tentry->isNonPow2?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D, tentry->texture, tentry->w, tentry->h);
}
}
else {
ERROR_LOG("error loading tex\n");
TextureMngr::DisableStage(i); // disable since won't be used
}
}
else {
TextureMngr::DisableStage(i); // disable since won't be used
}
}
PixelShaderMngr::SetTexturesUsed(nonpow2tex);
}
FRAGMENTSHADER* ps = PixelShaderMngr::GetShader();
VERTEXSHADER* vs = VertexShaderMngr::GetShader(s_prevcomponents);
_assert_( ps != NULL && vs != NULL );
bool bRestoreBuffers = false;
if (Renderer::GetZBufferTarget()) {
if (bpmem.zmode.updateenable) {
if (!bpmem.blendmode.colorupdate) {
Renderer::SetRenderMode(bpmem.blendmode.alphaupdate?Renderer::RM_ZBufferAlpha:Renderer::RM_ZBufferOnly);
}
}
else {
Renderer::SetRenderMode(Renderer::RM_Normal);
// remove temporarily
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
bRestoreBuffers = true;
}
}
else
Renderer::SetRenderMode(Renderer::RM_Normal);
// set global constants
VertexShaderMngr::SetConstants(*vs);
PixelShaderMngr::SetConstants(*ps);
// finally bind
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid);
#ifdef _DEBUG
PRIM_LOG("\n");
#endif
int offset = 0;
vector< pair<int, int> >::iterator it;
for (it = s_vStoredPrimitives.begin(); it != s_vStoredPrimitives.end(); ++it) {
glDrawArrays(it->first, offset, it->second);
offset += it->second;
}
#ifdef _DEBUG
if (g_Config.iLog & CONF_PRIMLOG) {
// save the shaders
char strfile[255];
sprintf(strfile, "frames/ps%.3d.txt", g_Config.iSaveTargetId);
std::ofstream fps(strfile);
fps << ps->strprog.c_str();
sprintf(strfile, "frames/vs%.3d.txt", g_Config.iSaveTargetId);
ofstream fvs(strfile);
fvs << vs->strprog.c_str();
}
if (g_Config.iLog & CONF_SAVETARGETS) {
char str[128];
sprintf(str, "frames/targ%.3d.tga", g_Config.iSaveTargetId);
Renderer::SaveRenderTarget(str, 0);
}
#endif
g_Config.iSaveTargetId++;
GL_REPORT_ERRORD();
if (bRestoreBuffers) {
GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
glDrawBuffers(2, s_drawbuffers);
SetColorMask();
}
ResetBuffer();
}
void VertexManager::LoadCPReg(u32 SubCmd, u32 Value)
{
switch (SubCmd & 0xF0)
{
case 0x30:
VertexShaderMngr::SetTexMatrixChangedA(Value);
break;
case 0x40:
VertexShaderMngr::SetTexMatrixChangedB(Value);
break;
case 0x50:
s_GlobalVtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits
s_GlobalVtxDesc.Hex |= Value;
break;
case 0x60:
s_GlobalVtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits
s_GlobalVtxDesc.Hex |= (u64)Value << 17;
break;
case 0x70: g_VertexLoaders[SubCmd & 7].SetVAT_group0(Value); _assert_((SubCmd & 0x0F) < 8); break;
case 0x80: g_VertexLoaders[SubCmd & 7].SetVAT_group1(Value); _assert_((SubCmd & 0x0F) < 8); break;
case 0x90: g_VertexLoaders[SubCmd & 7].SetVAT_group2(Value); _assert_((SubCmd & 0x0F) < 8); break;
case 0xA0: arraybases[SubCmd & 0xF] = Value & 0xFFFFFFFF; break;
case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break;
}
}

View File

@ -0,0 +1,60 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _VERTEXMANAGER_H
#define _VERTEXMANAGER_H
#include "CPMemory.h"
// Methods to manage and cache the global state of vertex streams and flushing streams
// Also handles processing the CP registers
class VertexManager
{
static TVtxDesc s_GlobalVtxDesc;
public:
enum Collection
{
C_NOTHING=0,
C_TRIANGLES=1,
C_LINES=2,
C_POINTS=3
};
static bool Init();
static void Destroy();
static void ResetBuffer();
static void ResetComponents();
static void AddVertices(int primitive, int numvertices);
static void Flush(); // flushes the current buffer
static int GetRemainingSize();
static TVtxDesc &GetVtxDesc() {return s_GlobalVtxDesc; }
static void LoadCPReg(u32 SubCmd, u32 Value);
// TODO - don't expose these like this.
static u32 s_prevvbstride;
static u32 s_prevcomponents; // previous state set
static u8* s_pCurBufferPointer;
static float shiftLookup[32];
};
#endif // _VERTEXMANAGER_H

View File

@ -284,11 +284,11 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
} }
// zero left over channels // zero left over channels
for(int i = xfregs.nNumChans; i < 2; ++i) WRITE(p, "o.colors[%d] = 0;\n", i); for (int i = xfregs.nNumChans; i < 2; ++i)
WRITE(p, "o.colors[%d] = 0;\n", i);
// transform texcoords // transform texcoords
for (int i = 0; i < xfregs.numTexGens; ++i) { for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo& texinfo = xfregs.texcoords[i].texmtxinfo; TexMtxInfo& texinfo = xfregs.texcoords[i].texmtxinfo;
WRITE(p, "{\n"); WRITE(p, "{\n");

View File

@ -19,10 +19,16 @@
#include "Globals.h" #include "Globals.h"
#include "Profiler.h" #include "Profiler.h"
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <math.h> #include <math.h>
#include "Render.h" #include "Render.h"
#include "VertexShader.h" #include "VertexShader.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "VertexManager.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPMemory.h" #include "BPMemory.h"
#include "XFMemory.h" #include "XFMemory.h"
@ -339,11 +345,8 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
2 * rawViewport[0], 2 * rawViewport[1], 2 * rawViewport[0], 2 * rawViewport[1],
(rawViewport[5] - rawViewport[2]) / 16777215.0f, rawViewport[5] / 16777215.0f);*/ (rawViewport[5] - rawViewport[2]) / 16777215.0f, rawViewport[5] / 16777215.0f);*/
// =======================================================================================
// Keep aspect ratio at 4:3 // Keep aspect ratio at 4:3
// -------------
// rawViewport[0] = 320, rawViewport[1] = -240 // rawViewport[0] = 320, rawViewport[1] = -240
// -------------
int scissorXOff = bpmem.scissorOffset.x * 2 - 342; int scissorXOff = bpmem.scissorOffset.x * 2 - 342;
int scissorYOff = bpmem.scissorOffset.y * 2 - 342; int scissorYOff = bpmem.scissorOffset.y * 2 - 342;
float fourThree = 4.0f/3.0f; float fourThree = 4.0f/3.0f;

View File

@ -27,6 +27,8 @@
#include "GUI/ConfigDlg.h" #include "GUI/ConfigDlg.h"
#include "LookUpTables.h"
#include "ImageWrite.h"
#include "Render.h" #include "Render.h"
#include "GLInit.h" #include "GLInit.h"
#include "Fifo.h" #include "Fifo.h"
@ -34,6 +36,7 @@
#include "TextureMngr.h" #include "TextureMngr.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexManager.h"
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "XFB.h" #include "XFB.h"
@ -45,12 +48,9 @@
SVideoInitialize g_VideoInitialize; SVideoInitialize g_VideoInitialize;
#define VERSION_STRING "0.1" #define VERSION_STRING "0.1"
// =======================================================================================
// Create debugging window. We can't use Show() here as usual because then DLL_PROCESS_DETACH will // Create debugging window. We can't use Show() here as usual because then DLL_PROCESS_DETACH will
// be called immediately. And if we use ShowModal() we block the main video window from appearing. // be called immediately. And if we use ShowModal() we block the main video window from appearing.
// So I've made a separate function called DoDllDebugger() that creates the window. // So I've made a separate function called DoDllDebugger() that creates the window.
// -------------------
CDebugger* m_frame; CDebugger* m_frame;
void DllDebugger(HWND _hParent) void DllDebugger(HWND _hParent)
{ {
@ -69,8 +69,6 @@ void DoDllDebugger()
m_frame = new CDebugger(NULL); m_frame = new CDebugger(NULL);
m_frame->Show(); m_frame->Show();
} }
// ===================
void GetDllInfo (PLUGIN_INFO* _PluginInfo) void GetDllInfo (PLUGIN_INFO* _PluginInfo)
{ {
@ -164,13 +162,10 @@ void DllConfig(HWND _hParent)
XFree(modes); XFree(modes);
frame.ShowModal(); frame.ShowModal();
#else #else
//TODO //TODO
#endif #endif
} }
void Video_Initialize(SVideoInitialize* _pVideoInitialize) void Video_Initialize(SVideoInitialize* _pVideoInitialize)
{ {
if (_pVideoInitialize == NULL) if (_pVideoInitialize == NULL)
@ -197,7 +192,6 @@ void Video_Initialize(SVideoInitialize* _pVideoInitialize)
Renderer::AddMessage("Dolphin OpenGL Video Plugin v" VERSION_STRING ,5000); Renderer::AddMessage("Dolphin OpenGL Video Plugin v" VERSION_STRING ,5000);
} }
void Video_DoState(unsigned char **ptr, int mode) { void Video_DoState(unsigned char **ptr, int mode) {
// Clear all caches // Clear all caches
@ -208,9 +202,7 @@ void Video_DoState(unsigned char **ptr, int mode) {
//PanicAlert("Saving/Loading state from OpenGL"); //PanicAlert("Saving/Loading state from OpenGL");
} }
// ======================================================================================= // This is called after Video_Initialize() from the Core
// This is run after Video_Initialize() from the Core
// --------------
void Video_Prepare(void) void Video_Prepare(void)
{ {
OpenGL_MakeCurrent(); OpenGL_MakeCurrent();
@ -230,8 +222,6 @@ void Video_Prepare(void)
PixelShaderMngr::Init(); PixelShaderMngr::Init();
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
// ==============
void Video_Shutdown(void) void Video_Shutdown(void)
{ {
@ -255,7 +245,6 @@ void Video_EnterLoop()
Fifo_EnterLoop(g_VideoInitialize); Fifo_EnterLoop(g_VideoInitialize);
} }
void DebugLog(const char* _fmt, ...) void DebugLog(const char* _fmt, ...)
{ {
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
@ -271,7 +260,6 @@ void DebugLog(const char* _fmt, ...)
#endif #endif
} }
bool ScreenShot(TCHAR *File) bool ScreenShot(TCHAR *File)
{ {
char str[64]; char str[64];
@ -292,7 +280,6 @@ bool ScreenShot(TCHAR *File)
return false; return false;
} }
BOOL Video_Screenshot(TCHAR* _szFilename) BOOL Video_Screenshot(TCHAR* _szFilename)
{ {
if (ScreenShot(_szFilename)) if (ScreenShot(_szFilename))
@ -301,7 +288,6 @@ BOOL Video_Screenshot(TCHAR* _szFilename)
return FALSE; return FALSE;
} }
void Video_UpdateXFB(u8* _pXFB, u32 _dwWidth, u32 _dwHeight, s32 _dwYOffset) void Video_UpdateXFB(u8* _pXFB, u32 _dwWidth, u32 _dwHeight, s32 _dwYOffset)
{ {
if(g_Config.bUseXFB) if(g_Config.bUseXFB)