Some cleanup, extracted XFB convert code into VideoCommon, added non-activated support to gl plugin. + a minor bugfix with no effects seen so far in gl plugin :P

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@209 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-08-14 21:34:39 +00:00
parent 1aedd4891c
commit b4d7ce0197
15 changed files with 196 additions and 212 deletions

View File

@ -117,62 +117,21 @@ typedef union _LARGE_INTEGER
#endif
#if !defined (_MSC_VER) && !defined (HAVE_ALIGNED_MALLOC)
// declare linux equivalents
extern __forceinline void* gc_aligned_malloc(size_t size, size_t align)
{
char* p = (char*)malloc(size + align);
int off = 2 + align - ((s64)(p + 2) % align);
p += off;
*(u16*)(p - 2) = off;
return(p);
}
extern __forceinline void gc_aligned_free(void* pmem)
{
if (pmem != NULL)
{
char* p = (char*)pmem;
free(p - (int)*(u16*)(p - 2));
}
}
#define _aligned_malloc gc_aligned_malloc
#define _aligned_free gc_aligned_free
#endif
#if defined (_M_IX86) && defined (_WIN32)
#define HWCALL __cdecl
#else
#define HWCALL
#endif
// Hacks
#ifndef SAFE_DELETE
#define SAFE_DELETE(ptr) if (ptr){delete ptr; ptr = 0;}
#endif
// Common defines
// TODO(ector,fires): turn into inline function?
#undef min
#undef max
template<class T>
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>
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
@ -183,39 +142,25 @@ inline u8 swap8(u8 _data) {return(_data);}
#ifdef _WIN32
inline u16 swap16(u16 _data) {return(_byteswap_ushort(_data));}
inline u32 swap32(u32 _data) {return(_byteswap_ulong(_data));}
inline u64 swap64(u64 _data) {return(_byteswap_uint64(_data));}
#elif __linux__
}
#include <byteswap.h>
namespace Common
{
inline u16 swap16(u16 _data) {return(bswap_16(_data));}
inline u32 swap32(u32 _data) {return(bswap_32(_data));}
inline u64 swap64(u64 _data) {return(bswap_64(_data));}
#else
inline u16 swap16(u16 data) {return((data >> 8) | (data << 8));}
inline u32 swap32(u32 data) {return((swap16(data) << 16) | swap16(data >> 16));}
inline u64 swap64(u64 data) {return(((u64)swap32(data) << 32) | swap32(data >> 32));}
#endif
} // end of namespace Common
// Utility functions
@ -231,36 +176,35 @@ extern void __Log(int logNumber, const char* text, ...);
class LogTypes
{
public:
enum LOG_TYPE
{
MASTER_LOG,
BOOT,
PIXELENGINE,
COMMANDPROCESSOR,
VIDEOINTERFACE,
SERIALINTERFACE,
PERIPHERALINTERFACE,
MEMMAP,
DSPINTERFACE,
STREAMINGINTERFACE,
DVDINTERFACE,
GPFIFO,
EXPANSIONINTERFACE,
AUDIO_INTERFACE,
GEKKO,
HLE,
DSPHLE,
VIDEO,
AUDIO,
DYNA_REC,
OSREPORT,
CONSOLE,
WII_IOB,
WII_IPC,
WII_IPC_HLE,
NUMBER_OF_LOGS
};
enum LOG_TYPE
{
MASTER_LOG,
BOOT,
PIXELENGINE,
COMMANDPROCESSOR,
VIDEOINTERFACE,
SERIALINTERFACE,
PERIPHERALINTERFACE,
MEMMAP,
DSPINTERFACE,
STREAMINGINTERFACE,
DVDINTERFACE,
GPFIFO,
EXPANSIONINTERFACE,
AUDIO_INTERFACE,
GEKKO,
HLE,
DSPHLE,
VIDEO,
AUDIO,
DYNA_REC,
OSREPORT,
CONSOLE,
WII_IOB,
WII_IPC,
WII_IPC_HLE,
NUMBER_OF_LOGS
};
};
typedef bool (*PanicAlertHandler)(const char* text, bool yes_no);
@ -268,7 +212,6 @@ void RegisterPanicAlertHandler(PanicAlertHandler handler);
void Host_UpdateLogDisplay();
// Logging macros
#ifdef LOGGING
@ -297,7 +240,6 @@ void Host_UpdateLogDisplay();
#endif
#ifdef _WIN32
#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
#define _assert_msg_(_t_, _a_, _fmt_, ...)\

View File

@ -5,6 +5,7 @@ files = ["BPMemory.cpp",
"LookUpTables.cpp",
"TextureDecoder.cpp",
"XFMemory.cpp",
"XFBConvert.cpp",
]
env_common = env.Copy(CXXFLAGS = " -fPIC ")

View File

@ -0,0 +1,59 @@
// 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 "XFBConvert.h"
#include "Common.h"
// TODO: Convert this thing into wicked fast SSE2.
namespace {
int bound(int i)
{
return (i>255)?255:((i<0)?0:i);
}
void yuv2rgb(int y, int u, int v, int &r, int &g, int &b)
{
b = bound((76283*(y - 16) + 132252*(u - 128))>>16);
g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u?
r = bound((76283*(y - 16) + 104595*(v - 128))>>16);
}
} // namespace
void ConvertXFB(u32 *dst, const u8* _pXFB, int width, int height)
{
const unsigned char *src = _pXFB;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, src += 4)
{
int Y1 = src[0];
int U = src[1];
int Y2 = src[2];
int V = src[3];
int r, g, b;
yuv2rgb(Y1,U,V, r,g,b);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b);
yuv2rgb(Y2,U,V, r,g,b);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b);
}
}
}

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 _XFB_CONVERT
#define _XFB_CONVERT
#include "Common.h"
void ConvertXFB(u32 *dst, const u8* _pXFB, int width, int height);
#endif

View File

@ -413,6 +413,10 @@
RelativePath=".\Src\LookUpTables.h"
>
</File>
<File
RelativePath=".\Src\SConscript"
>
</File>
<File
RelativePath=".\Src\TextureDecoder.cpp"
>
@ -421,6 +425,14 @@
RelativePath=".\Src\TextureDecoder.h"
>
</File>
<File
RelativePath=".\Src\XFBConvert.cpp"
>
</File>
<File
RelativePath=".\Src\XFBConvert.h"
>
</File>
<File
RelativePath=".\Src\XFMemory.cpp"
>

View File

@ -36,7 +36,7 @@ CDSPHandler::CDSPHandler()
CDSPHandler::~CDSPHandler()
{
SAFE_DELETE(m_pUCode);
delete m_pUCode;
}
@ -90,13 +90,13 @@ void CDSPHandler::SendMailToDSP(u32 _uMail)
IUCode* CDSPHandler::GetUCode()
{
return(m_pUCode);
return m_pUCode;
}
void CDSPHandler::SetUCode(u32 _crc)
{
SAFE_DELETE(m_pUCode);
delete m_pUCode;
m_MailHandler.Clear();
m_pUCode = UCodeFactory(_crc, m_MailHandler);

View File

@ -33,22 +33,18 @@ class CDSPHandler
IUCode* GetUCode();
void SetUCode(u32 _crc);
CMailHandler& AccessMailHandler() {return(m_MailHandler);}
static CDSPHandler& GetInstance()
{
return(*m_pInstance);
}
static void Destroy()
{
SAFE_DELETE(m_pInstance);
delete m_pInstance;
}
static CDSPHandler& CreateInstance()
{
if (m_pInstance == NULL)
@ -59,7 +55,6 @@ class CDSPHandler
return(*m_pInstance);
}
private:
CDSPHandler();

View File

@ -1565,14 +1565,6 @@
RelativePath=".\Src\Vec3.h"
>
</File>
<File
RelativePath=".\Src\XFB.cpp"
>
</File>
<File
RelativePath=".\Src\XFB.h"
>
</File>
</Files>
<Globals>
</Globals>

View File

@ -1,43 +0,0 @@
#include "XFB.h"
#include "Common.h"
// __________________________________________________________________________________________________
// Video_UpdateXFB
//
// TODO(ector): Write protect XFB. As soon as something pokes there,
// switch to a mode where we actually display the XFB on top of the 3D.
// If no writes have happened within 5 frames, revert to normal mode.
int bound(int i)
{
return (i>255)?255:((i<0)?0:i);
}
void yuv2rgb(int y, int u, int v, int &r, int &g, int &b)
{
b = bound((76283*(y - 16) + 132252*(u - 128))>>16);
g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u?
r = bound((76283*(y - 16) + 104595*(v - 128))>>16);
}
void ConvertXFB(int *dst, const u8* _pXFB, int width, int height)
{
const unsigned char *src = _pXFB;
for (int y=0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int Y1 = *src++;
int U = *src++;
int Y2 = *src++;
int V = *src++;
int r,g,b;
yuv2rgb(Y1,U,V,r,g,b);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b);
yuv2rgb(Y2,U,V,r,g,b);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b);
}
}
}

View File

@ -1,7 +0,0 @@
#ifndef _XFB_H
#define _XFB_H
#include "Common.h"
void ConvertXFB(int *dst, const u8* _pXFB, int width, int height);
#endif

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="Plugin_VideoOGL"
ProjectGUID="{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}"
RootNamespace="Plugin_VideoOGL"
@ -821,6 +821,14 @@
RelativePath=".\Src\rasterfont.h"
>
</File>
<File
RelativePath=".\Src\TextureMngr.cpp"
>
</File>
<File
RelativePath=".\Src\TextureMngr.h"
>
</File>
<File
RelativePath=".\Src\VertexShader.cpp"
>
@ -1040,14 +1048,6 @@
RelativePath=".\Src\Render.h"
>
</File>
<File
RelativePath=".\Src\TextureMngr.cpp"
>
</File>
<File
RelativePath=".\Src\TextureMngr.h"
>
</File>
<File
RelativePath=".\Src\XFB.cpp"
>

View File

@ -100,13 +100,7 @@ struct RECT
// several macros
// PLEASE DO NOT USE THE FOLLOWING SAFE*
// They only encourage sloppy coding, and hides bugs.
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(x) if( (x) != NULL ) { delete[] (x); (x) = NULL; }
#endif
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(x) if( (x) != NULL ) { (x)->Release(); (x) = NULL; }
#endif
// They only encourage sloppy coding, and hide bugs.
#define SAFE_RELEASE_CGPROG(x) { if( (x) != NULL ) { cgDestroyProgram(x); x = NULL; } }
#define SAFE_RELEASE_PROG(x) { if( (x) != 0 ) { glDeleteProgramsARB(1, &(x)); x = 0; } }
#define SAFE_RELEASE_TEX(x) { if( (x) != 0 ) { glDeleteTextures(1, &(x)); x = 0; } }
@ -269,8 +263,6 @@ unsigned char memcmp_mmx(const void* src1, const void* src2, int cmpsize);
#define memcmp_gc memcmp
#endif
//#define RAM_MASK 0x1FFFFFF
#include "main.h"
inline u8 *Memory_GetPtr(u32 _uAddress)

View File

@ -27,6 +27,7 @@
#include "VertexShader.h"
#include "PixelShaderManager.h"
#include "VertexLoader.h"
#include "XFB.h"
#ifdef _WIN32
#include "OS\Win32.h"
@ -52,6 +53,7 @@ static bool s_bOutputCgErrors = true;
static int nZBufferRender = 0; // if > 0, then using zbuffer render
static u32 s_uFramebuffer = 0;
static u32 s_RenderTargets[1] = {0}, s_DepthTarget = 0, s_ZBufferTarget = 0;
static bool s_bATIDrawBuffers = false, s_bHaveStencilBuffer = false;
static Renderer::RenderMode s_RenderMode = Renderer::RM_Normal;
static int s_nCurTarget = 0;
@ -273,26 +275,29 @@ bool Renderer::Create2()
if (!Initialize())
return false;
XFB_Init();
return glGetError() == GL_NO_ERROR && bSuccess;
}
void Renderer::Shutdown(void)
{
SAFE_DELETE(s_pfont);
delete s_pfont;
s_pfont = 0;
if( g_cgcontext != 0 ) {
XFB_Shutdown();
if (g_cgcontext != 0) {
cgDestroyContext(g_cgcontext);
g_cgcontext = 0;
}
if( s_RenderTargets[0] ) {
if (s_RenderTargets[0]) {
glDeleteTextures(ARRAYSIZE(s_RenderTargets), (GLuint *)s_RenderTargets);
memset(s_RenderTargets, 0, sizeof(s_RenderTargets));
}
if( s_DepthTarget ) {
if (s_DepthTarget) {
glDeleteRenderbuffersEXT(1, (GLuint *)&s_DepthTarget); s_DepthTarget = 0;
}
if (s_uFramebuffer != 0) {
glDeleteFramebuffersEXT( 1, (GLuint *)&s_uFramebuffer);
s_uFramebuffer = 0;
@ -550,7 +555,7 @@ void Renderer::FlushZBufferAlphaToTarget()
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(-1,-1);
glTexCoord2f(0, (float)(GetTargetHeight()<<g_AAy)); glVertex2f(-1,1);
glTexCoord2f((float)(GetTargetWidth()<<g_AAx), (float)(GetTargetWidth()<<g_AAy)); glVertex2f(1,1);
glTexCoord2f((float)(GetTargetWidth()<<g_AAx), (float)(GetTargetHeight()<<g_AAy)); glVertex2f(1,1);
glTexCoord2f((float)(GetTargetWidth()<<g_AAx), 0); glVertex2f(1,-1);
glEnd();

View File

@ -15,48 +15,56 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
// Preliminary non-working code.
#include "Common.h"
#include "Globals.h"
#include "Render.h"
#include "TextureMngr.h"
#include "XFBConvert.h"
// __________________________________________________________________________________________________
// Video_UpdateXFB
//
enum {
XFB_WIDTH = 640,
XFB_HEIGHT = 480,
};
// TODO(ector): Write protect XFB. As soon as something pokes there,
// switch to a mode where we actually display the XFB on top of the 3D.
// If no writes have happened within 5 frames, revert to normal mode.
static GLuint xfb_texture;
static u8 *xfb_buffer;
// Also, write a crazy SSE2 optimized version of this :P
int bound(int i)
void XFB_Init()
{
return (i>255)?255:((i<0)?0:i);
xfb_buffer = new u8[XFB_WIDTH * XFB_HEIGHT * 4];
memset(xfb_buffer, 0, XFB_WIDTH * XFB_HEIGHT * 4);
glGenTextures(1, &xfb_texture);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, xfb_texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 4, XFB_WIDTH, XFB_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, xfb_buffer);
}
void yuv2rgb(int y, int u, int v, int &r, int &g, int &b)
void XFB_Draw(u8 *xfb_in_ram)
{
b = bound((76283*(y - 16) + 132252*(u - 128))>>16);
g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u?
r = bound((76283*(y - 16) + 104595*(v - 128))>>16);
Renderer::ResetGLState();
ConvertXFB((u32 *)xfb_buffer, xfb_in_ram, XFB_WIDTH, XFB_HEIGHT);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, xfb_texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 4, XFB_WIDTH, XFB_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, xfb_buffer);
TextureMngr::EnableTexRECT(0);
for (int i = 1; i < 8; ++i)
TextureMngr::DisableStage(i);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(-1,-1);
glTexCoord2f(0, XFB_WIDTH); glVertex2f(-1,1);
glTexCoord2f(XFB_WIDTH, XFB_HEIGHT); glVertex2f(1,1);
glTexCoord2f(XFB_WIDTH, 0); glVertex2f(1,-1);
glEnd();
Renderer::RestoreGLState();
}
void ConvertXFB(int *dst, const u8* _pXFB, int width, int height)
void XFB_Shutdown()
{
const unsigned char *src = _pXFB;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int Y1 = *src++;
int U = *src++;
int Y2 = *src++;
int V = *src++;
int r,g,b;
yuv2rgb(Y1, U, V, r, g, b);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b);
yuv2rgb(Y2, U, V, r, g, b);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b);
}
}
glDeleteTextures(1, &xfb_texture);
xfb_texture = 0;
delete [] xfb_buffer;
xfb_buffer = 0;
}

View File

@ -18,5 +18,8 @@
#ifndef _XFB_H
#define _XFB_H
void XFB_Init();
void XFB_Draw(u8 *xfb_in_ram);
void XFB_Shutdown();
#endif