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

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