More GFX plugin cleanup, still no visible changes.

New right-click popup menu in game list - allow editing patch files easily.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@31 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2008-07-20 12:26:32 +00:00
parent c7795c41b7
commit 461077b1a1
52 changed files with 509 additions and 805 deletions

View File

@ -12,40 +12,8 @@
#include "main.h" //for the plugin interface
//BP state
BPMemory bpmem;
bool textureChanged[8];
#define BPMEM_GENMODE 0x00
#define BPMEM_IND_MTX 0x06
#define BPMEM_RAS1_SS0 0x25 // ind tex coord scale 0
#define BPMEM_RAS1_SS1 0x26 // ind tex coord scale 1
#define BPMEM_ZMODE 0x40
#define BPMEM_BLENDMODE 0x41
#define BPMEM_CONSTANTALPHA 0x42
#define BPMEM_ALPHACOMPARE 0xF3
#define BPMEM_LINEPTWIDTH 0x22
#define BPMEM_TEXINVALIDATE 0x66
#define BPMEM_SCISSORTL 0x20
#define BPMEM_SCISSORBR 0x21
#define BPMEM_SCISSOROFFSET 0x59
#define BPMEM_CLEARBBOX1 0x55 // let's hope not many games use bboxes..
#define BPMEM_CLEARBBOX2 0x56 // TODO(ector): add something that watches bboxes
#define BPMEM_TEXMODE0_1 0x80
#define BPMEM_TEXMODE0_2 0xA0
#define BPMEM_FOGPARAM0 0xEE
#define BPMEM_FOGBMAGNITUDE 0xEF
#define BPMEM_FOGBEXPONENT 0xF0
#define BPMEM_FOGPARAM3 0xF1
#define BPMEM_FOGCOLOR 0xF2
#define BPMEM_ZTEX1 0xF4
#define BPMEM_ZTEX2 0xF5
#define BPMEM_DRAWDONE 0x45
#define BPMEM_PE_TOKEN_ID 0x47
#define BPMEM_PE_TOKEN_INT_ID 0x48
// State translation lookup tables
const D3DBLEND d3dSrcFactors[8] =
{
@ -107,7 +75,6 @@ const D3DTEXTUREADDRESS d3dClamps[4] =
D3DTADDRESS_WRAP //reserved
};
void BPInit()
{
memset(&bpmem, 0, sizeof(bpmem));

View File

@ -9,7 +9,6 @@ void BPInit();
size_t BPSaveLoadState(char *ptr, BOOL save);
//bool BPWritten(int addr, int changes);
void LoadBPReg(u32 value0);
void ActivateTextures();
#endif

View File

@ -6,9 +6,6 @@
#include "VertexHandler.h"
#include "VertexLoader.h"
TMatrixIndexA MatrixIndexA;
TMatrixIndexB MatrixIndexB;
// PROBLEM - matrix switching within vbuffers may be stateful!
void CPUpdateMatricesA()
@ -65,10 +62,10 @@ void LoadCPReg(u32 SubCmd, u32 Value)
size_t CPSaveLoadState(char *ptr, BOOL save)
{
BEGINSAVELOAD;
SAVELOAD(arraybases,16*sizeof(u32));
SAVELOAD(arraystrides,16*sizeof(u32));
SAVELOAD(&MatrixIndexA,sizeof(TMatrixIndexA));
SAVELOAD(&MatrixIndexB,sizeof(TMatrixIndexB));
SAVELOAD(arraybases, 16 * sizeof(u32));
SAVELOAD(arraystrides, 16 * sizeof(u32));
SAVELOAD(&MatrixIndexA, sizeof(TMatrixIndexA));
SAVELOAD(&MatrixIndexB, sizeof(TMatrixIndexB));
if (!save)
{
CPUpdateMatricesA();

View File

@ -5,11 +5,6 @@
#include "CPMemory.h"
#include "XFMemory.h"
extern TMatrixIndexA MatrixIndexA;
extern TMatrixIndexB MatrixIndexB;
extern u32 arraybases[16];
extern u32 arraystrides[16];
void CPUpdateMatricesA();
void CPUpdateMatricesB();
size_t CPSaveLoadState(char *ptr, BOOL save);

View File

@ -50,29 +50,6 @@ namespace D3D
return vShader;
}
LPDIRECT3DVERTEXSHADER9 LoadVShader(const char *filename)
{
//alloc a temp buffer for code
char *temp = new char[65536];
//open and read the file
FILE *f = fopen(filename,"rb");
if (!f)
{
MessageBox(0,"FATAL ERROR Vertex Shader file not found",filename,0);
return 0;
}
fseek(f,0,SEEK_END);
int len = ftell(f);
fseek(f,0,SEEK_SET);
fread(temp,len,1,f);
fclose(f);
LPDIRECT3DVERTEXSHADER9 vShader = CompileVShader(temp,len);
//kill off our temp code buffer
delete [] temp;
//return the compiled shader, or null
return vShader;
}
LPDIRECT3DPIXELSHADER9 CompilePShader(const char *code, int len)
{
@ -111,26 +88,4 @@ namespace D3D
return pShader;
}
LPDIRECT3DPIXELSHADER9 LoadPShader(const char *filename)
{
//open and read the file
FILE *f = fopen(filename,"rb");
if (!f)
{
MessageBox(0,"FATAL ERROR Pixel Shader file not found",filename,0);
return 0;
}
fseek(f,0,SEEK_END);
int len = ftell(f);
char *temp = new char[len];
fseek(f,0,SEEK_SET);
fread(temp,len,1,f);
fclose(f);
LPDIRECT3DPIXELSHADER9 pShader = CompilePShader(temp,len);
//kill off our temp code buffer
delete [] temp;
//return the compiled shader, or null
return pShader;
}
}

View File

@ -5,7 +5,5 @@
namespace D3D
{
LPDIRECT3DVERTEXSHADER9 CompileVShader(const char *code, int len);
LPDIRECT3DVERTEXSHADER9 LoadVShader(const char *filename);
LPDIRECT3DPIXELSHADER9 CompilePShader(const char *code, int len);
LPDIRECT3DPIXELSHADER9 LoadPShader(const char *filename);
}

View File

@ -29,7 +29,7 @@ public:
int count;
DecodedVArray();
~DecodedVArray();
void SetComponents(u32 comps) {components = comps; vertexSize=ComputeVertexSize(components);}
void SetComponents(u32 comps) {components = comps; vertexSize = ComputeVertexSize(components);}
u32 GetComponents() const {return components;}
void Create(int _size, int pmcount, int tmcount, int nrmcount, int colcount, int tccount);
void Zero();

View File

@ -1,3 +1,20 @@
// 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 <stdio.h>
#include <stdlib.h>
@ -31,7 +48,7 @@ int FAKE_GetFifoSize()
{
if (size < readptr)
{
DebugBreak();
PanicAlert("GFX Fifo underrun encountered.");
}
return (size - readptr);
}
@ -70,6 +87,11 @@ u32 FAKE_ReadFifo32()
return val;
}
void FAKE_SkipFifo(u32 skip)
{
readptr += skip;
}
void Video_SendFifoData(BYTE *_uData)
{
memcpy(videoBuffer + size, _uData, 32);
@ -78,7 +100,7 @@ void Video_SendFifoData(BYTE *_uData)
{
if (FAKE_GetFifoSize() > readptr)
{
MessageBox(NULL, "out of bounds", "video-plugin", MB_OK);
PanicAlert("FIFO out of bounds", "video-plugin", MB_OK);
exit(1);
}

View File

@ -152,8 +152,14 @@ bool FifoCommandRunnable(void)
}
else
{
char szTemp[512];
sprintf(szTemp, "Error: Unknown Opcode (0x%x)", Cmd);
char szTemp[1024];
sprintf(szTemp, "GFX: Unknown Opcode (0x%x).\n"
"This means one of the following:\n"
"* The emulated GPU got desynced, disabling dual core can help\n"
"* Command stream corrupted by some spurious memory bug\n"
"* This really is an unknown opcode (unlikely)\n\n"
"* Some other sort of bug\n\n"
"Dolphin will now likely crash or hang. Enjoy.", Cmd);
MessageBox(NULL, szTemp, "Video-Plugin", MB_OK);
g_VideoInitialize.pLog(szTemp, TRUE);
}

View File

@ -1,10 +1,7 @@
#include "Globals.h"
#include "D3DShader.h"
#include "PixelShader.h"
#include "BPStructs.h"
#include "XFStructs.h"
#include "W32Util/Misc.h"
#include "Utils.h"
/*
old tev->pixelshader notes
@ -239,32 +236,6 @@ const char *alphaRef[2] =
};
//I hope we don't get too many hash collisions :p
//all these magic numbers are primes, it should help a bit
tevhash GetCurrentTEV()
{
u32 hash = bpmem.genMode.numindstages + bpmem.genMode.numtevstages*11 + bpmem.genMode.numtexgens*8*17;
for (int i = 0; i < (int)bpmem.genMode.numtevstages+1; i++)
{
hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13);
hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3);
hash = _rotl(hash,9) ^ xfregs.texcoords[i].texmtxinfo.projection*451;
}
for (int i = 0; i < (int)bpmem.genMode.numtevstages/2+1; i++)
{
hash = _rotl(hash,13) ^ (bpmem.tevorders[i].hex*7);
}
for (int i = 0; i < 8; i++)
{
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap1;
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap2;
}
hash ^= bpmem.dstalpha.enable ^ 0xc0debabe;
hash = _rotl(hash,4) ^ bpmem.alphaFunc.comp0*7;
hash = _rotl(hash,4) ^ bpmem.alphaFunc.comp1*13;
hash = _rotl(hash,4) ^ bpmem.alphaFunc.logic*11;
return hash;
}
char text[65536];
#define WRITE p+=sprintf
@ -290,12 +261,8 @@ void BuildSwapModeTable()
}
}
LPDIRECT3DPIXELSHADER9 GeneratePixelShader()
const char *GeneratePixelShader()
{
DVSTARTPROFILE();
BuildSwapModeTable();
int numStages = bpmem.genMode.numtevstages + 1;
int numTexgen = bpmem.genMode.numtexgens;
@ -332,14 +299,9 @@ LPDIRECT3DPIXELSHADER9 GeneratePixelShader()
WRITE(p,"float4 c0=color0,c1=color1,c2=color2,prev=float4(0.0f,0.0f,0.0f,0.0f),textemp,rastemp,konsttemp;\n");
WRITE(p,"\n");
//WRITE(p, "return 1;}\n");
//return D3D::CompilePShader(text,(int)(p-text));
for (int i = 0; i < numStages; i++)
WriteStage(p,i); //build the equation for this stage
//WRITE(p, "prev = textemp;\n");
//WRITE(p, "prev = float4(uv[0].x,uv[0].y,0,1);\n");
WriteAlphaTest(p);
if (bpmem.dstalpha.enable)
@ -350,18 +312,7 @@ LPDIRECT3DPIXELSHADER9 GeneratePixelShader()
WRITE(p,"}\n");
WRITE(p,"\0");
//#ifndef TEASER
/*
FILE *f=fopen("D:\\dlistlogs.txt","a");
fprintf(f,"===========================================\n");
fprintf(f,"%s",text);
fclose(f);
*/
//W32Util::CopyTextToClipboard(0,text);
//#endif
//MessageBox(0,text,0,0);
return D3D::CompilePShader(text,(int)(p-text));
return text;
}
void WriteStage(char *&p, int n)

View File

@ -1,11 +1,9 @@
#pragma once
#include "Common.h"
#include "D3DShader.h"
typedef u32 tevhash;
tevhash GetCurrentTEV();
LPDIRECT3DPIXELSHADER9 GeneratePixelShader();
const char *GeneratePixelShader();
#define PS_CONST_COLORS 0
#define PS_CONST_KCOLORS 4

View File

@ -2,6 +2,37 @@
#include "Utils.h"
#include "Globals.h"
#include "ShaderManager.h"
#include "BPMemory.h"
#include "XFMemory.h"
//I hope we don't get too many hash collisions :p
//all these magic numbers are primes, it should help a bit
tevhash GetCurrentTEV()
{
u32 hash = bpmem.genMode.numindstages + bpmem.genMode.numtevstages*11 + bpmem.genMode.numtexgens*8*17;
for (int i = 0; i < (int)bpmem.genMode.numtevstages+1; i++)
{
hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13);
hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3);
hash = _rotl(hash,9) ^ xfregs.texcoords[i].texmtxinfo.projection*451;
}
for (int i = 0; i < (int)bpmem.genMode.numtevstages/2+1; i++)
{
hash = _rotl(hash,13) ^ (bpmem.tevorders[i].hex*7);
}
for (int i = 0; i < 8; i++)
{
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap1;
hash = _rotl(hash,3) ^ bpmem.tevksel[i].swap2;
}
hash ^= bpmem.dstalpha.enable ^ 0xc0debabe;
hash = _rotl(hash,4) ^ bpmem.alphaFunc.comp0*7;
hash = _rotl(hash,4) ^ bpmem.alphaFunc.comp1*13;
hash = _rotl(hash,4) ^ bpmem.alphaFunc.logic*11;
return hash;
}
PShaderCache::PSCache PShaderCache::pshaders;
VShaderCache::VSCache VShaderCache::vshaders;
@ -47,8 +78,8 @@ void PShaderCache::SetShader()
return;
}
LPDIRECT3DPIXELSHADER9 shader = GeneratePixelShader();
const char *code = GeneratePixelShader();
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePShader(code, strlen(code));
if (shader)
{
//Make an entry in the table

View File

@ -6,6 +6,9 @@
#include "PixelShader.h"
#include "VertexShader.h"
typedef u32 tevhash;
tevhash GetCurrentTEV();
class PShaderCache

View File

@ -141,7 +141,13 @@ void TextureCache::Load(int stage, DWORD address, int width, int height, int for
int bs = TexDecoder_GetBlockWidthInTexels(format)-1; //TexelSizeInNibbles(format)*width*height/16;
int expandedWidth = (width+bs) & (~bs);
D3DFORMAT dfmt = TexDecoder_Decode(temp,ptr,expandedWidth,height,format, tlutaddr, tlutfmt);
PC_TexFormat pcfmt = TexDecoder_Decode(temp,ptr,expandedWidth,height,format, tlutaddr, tlutfmt);
D3DFORMAT d3d_fmt;
switch (pcfmt) {
case PC_TEX_FMT_BGRA32:
d3d_fmt = D3DFMT_A8R8G8B8;
break;
}
//Make an entry in the table
TCacheEntry entry;
@ -154,7 +160,7 @@ void TextureCache::Load(int stage, DWORD address, int width, int height, int for
entry.addr = address;
entry.isRenderTarget=false;
entry.isNonPow2 = ((width&(width-1)) || (height&(height-1)));
entry.texture = D3D::CreateTexture2D((BYTE*)temp,width,height,expandedWidth,dfmt);
entry.texture = D3D::CreateTexture2D((BYTE*)temp, width, height, expandedWidth, d3d_fmt);
entry.frameCount = frameCount;
entry.w=width;
entry.h=height;

View File

@ -1,447 +0,0 @@
#include "stdafx.h"
#include "D3DBase.h"
#include "main.h"
#include "Utils.h"
#include "BPStructs.h"
#include "TextureDecoder.h"
#include "OpcodeDecoding.h"
// TRAM
u8 texMem[TMEM_SIZE];
//////////////////////////////////////////////////////////////////////////
// Gamecube texture decoder
//////////////////////////////////////////////////////////////////////////
// Decodes all known Gamecube texture formats.
// TODO - speedup
// by ector
//////////////////////////////////////////////////////////////////////////
int TexDecoder_GetTexelSizeInNibbles(int format)
{
switch(format) {
case GX_TF_I4: return 1;
case GX_TF_I8: return 2;
case GX_TF_IA4: return 2;
case GX_TF_IA8: return 4;
case GX_TF_RGB565: return 4;
case GX_TF_RGB5A3: return 4;
case GX_TF_RGBA8: return 8;
case GX_TF_C4: return 1;
case GX_TF_C8: return 2;
case GX_TF_C14X2: return 4;
case GX_TF_CMPR: return 1;
default: return 1;
}
}
int TexDecoder_GetBlockWidthInTexels(int format)
{
switch(format) {
case GX_TF_I4: return 8;
case GX_TF_I8: return 8;
case GX_TF_IA4: return 8;
case GX_TF_IA8: return 4;
case GX_TF_RGB565: return 4;
case GX_TF_RGB5A3: return 4;
case GX_TF_RGBA8: return 4;
case GX_TF_C4: return 8;
case GX_TF_C8: return 8;
case GX_TF_C14X2: return 4;
case GX_TF_CMPR: return 8;
default:return 8;
}
}
//returns bytes
int TexDecoder_GetPaletteSize(int format)
{
switch (format) {
case GX_TF_C4: return 16*2;
case GX_TF_C8: return 256*2;
case GX_TF_C14X2: return 16384*2;
default:
return 0;
}
}
inline u32 decode565(u16 val)
{
int r,g,b,a;
r=lut5to8[(val>>11)&0x1f];
g=lut6to8[(val>>5 )&0x3f];
b=lut5to8[(val )&0x1f];
a=0xFF;
return (a<<24) | (r<<16) | (g<<8) | b;
}
inline u32 decodeIA8(u16 val)
{
int a=val>>8;
int r,g,b;
r=g=b=val&0xFF;
return (a<<24) | (r<<16) | (g<<8) | b;
}
inline u32 decode5A3(u16 val)
{
int r,g,b,a;
if ((val&0x8000))
{
r=lut5to8[(val>>10)&0x1f];
g=lut5to8[(val>>5 )&0x1f];
b=lut5to8[(val )&0x1f];
a=0xFF;
}
else
{
a=lut3to8[(val>>12)&0x7];
r=lut4to8[(val>>8 )&0xf];
g=lut4to8[(val>>4 )&0xf];
b=lut4to8[(val )&0xf];
}
return (a<<24) | (r<<16) | (g<<8) | b;
}
struct DXTBlock
{
u16 color1;
u16 color2;
u8 lines[4];
};
inline int expand8888(const int j)
{
int i = j | (j<<8);
return i|(i<<16);
}
void decodebytesI4(u32 *dst, u8 *src, int numbytes)
{
for (int x=0; x<numbytes; x++)
{
int val = src[x];
*dst++ = expand8888(lut4to8[val>>4]);
*dst++ = expand8888(lut4to8[val&15]);
}
}
void decodebytesI8(u32 *dst, u8 *src, int numbytes)
{
for (int x=0; x<numbytes; x++)
*dst++ = expand8888(src[x]); //asm bswap loop?
}
void decodebytesC4(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlutfmt)
{
u16 *tlut = (u16*)(texMem+tlutaddr);
for (int x=0; x<numbytes; x++)
{
int val = src[x];
switch(tlutfmt) {
case 0:
*dst++ = decodeIA8(_byteswap_ushort(tlut[(val>>4)]));
*dst++ = decodeIA8(_byteswap_ushort(tlut[(val&15)]));
break;
case 1:
*dst++ = decode565(_byteswap_ushort(tlut[(val>>4)]));
*dst++ = decode565(_byteswap_ushort(tlut[(val&15)]));
break;
case 2:
*dst++ = decode5A3(_byteswap_ushort(tlut[(val>>4)]));
*dst++ = decode5A3(_byteswap_ushort(tlut[(val&15)]));
break;
case 3: //ERROR
*dst++ = 0xFFFF00FF;
*dst++ = 0xFFFF00FF;
break;
}
}
}
void decodebytesC8(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlutfmt)
{
u16 *tlut = (u16*)(texMem+tlutaddr);
for (int x=0; x<numbytes; x++)
{
int val = src[x];
switch(tlutfmt) {
case 0:
*dst++ = decodeIA8(_byteswap_ushort(tlut[val]));
break;
case 1:
*dst++ = decode565(_byteswap_ushort(tlut[val]));
break;
case 2:
*dst++ = decode5A3(_byteswap_ushort(tlut[val]));
break;
case 3: //ERROR
*dst++ = 0xFFFF00FF;
break;
}
}
}
void decodebytesC14X2(u32 *dst, u16 *src, int numpixels, int tlutaddr, int tlutfmt)
{
u16 *tlut = (u16*)(texMem+tlutaddr);
for (int x=0; x<numpixels; x++)
{
int val = _byteswap_ushort(src[x]);
switch(tlutfmt) {
case 0:
*dst++ = decodeIA8(_byteswap_ushort(tlut[(val&0x3FFF)]));
break;
case 1:
*dst++ = decode565(_byteswap_ushort(tlut[(val&0x3FFF)]));
break;
case 2:
*dst++ = decode5A3(_byteswap_ushort(tlut[(val&0x3FFF)]));
break;
case 3: //ERROR
*dst++ = 0xFFFF00FF;
break;
}
}
}
void decodebytesRGB565(u32 *dst, u16 *src, int numpixels)
{
for (int x=0; x<numpixels; x++)
*dst++ = decode565(_byteswap_ushort(src[x]));
}
void decodebytesIA4(u32 *dst, u8 *src, int numbytes)
{
for (int x=0; x<numbytes; x++)
{
int val = src[x];
int a = lut4to8[val>>4];
int r = lut4to8[val&15];
*dst++ = (a<<24) | (r<<16) | (r<<8) | r;
}
}
inline void decodebytesIA8(u32 *dst, u16 *src, int numpixels)
{
for (int x=0; x<numpixels; x++)
*dst++ = decodeIA8(_byteswap_ushort(src[x]));
}
inline void decodebytesRGB5A3(u32 *dst, u16 *src, int numpixels)
{
for (int x=0; x<numpixels; x++)
*dst++ = decode5A3(_byteswap_ushort(src[x]));
}
void decodebytesARGB8pass1(u32 *dst, u16 *src, int numpixels)
{
for (int x=0; x<numpixels; x++)
{
int val = _byteswap_ushort(src[x]);
int a=val&0xFF;
val>>=8;
*dst++ = (a<<16) | (val<<24);
}
}
void decodebytesARGB8pass2(u32 *dst, u16 *src, int numpixels)
{
for (int x=0; x<numpixels; x++)
{
int val = _byteswap_ushort(src[x]);
int a=val&0xFF;
val>>=8;
*dst++ |= (val<<8) | (a<<0);
}
}
inline u32 makecol(int r,int g,int b,int a)
{
return ((a&255)<<24)|((r&255)<<16)|((g&255)<<8)|((b&255));
}
//this needs to be FAST, used by some games realtime video
//TODO: port to ASM or intrinsics
void decodeDXTBlock(u32 *dst, DXTBlock *src, int pitch)
{
u16 c1 = _byteswap_ushort(src->color1);
u16 c2 = _byteswap_ushort(src->color2);
int blue1 = lut5to8[c1&0x1F];
int blue2 = lut5to8[c2&0x1F];
int green1 = lut6to8[(c1>>5)&0x3F];
int green2 = lut6to8[(c2>>5)&0x3F];
int red1 = lut5to8[(c1>>11)&0x1F];
int red2 = lut5to8[(c2>>11)&0x1F];
int colors[4];
if (c1>c2)
{
colors[0]=makecol(red1,green1,blue1,255);
colors[1]=makecol(red2,green2,blue2,255);
colors[2]=makecol(red1+(red2-red1)/3,green1+(green2-green1)/3,blue1+(blue2-blue1)/3,255);
colors[3]=makecol(red2+(red1-red2)/3,green2+(green1-green2)/3,blue2+(blue1-blue2)/3,255);
}
else
{
colors[0]=makecol(red1,green1,blue1,255);
colors[1]=makecol(red2,green2,blue2,255);
colors[2]=makecol((red1+red2)/2,(green1+green2)/2,(blue1+blue2)/2,255);
colors[3]=makecol(0,0,0,0); //transparent
}
for (int y=0; y<4; y++)
{
int val = src->lines[y];
for (int x=0; x<4; x++)
{
dst[x] = colors[(val>>6)&3];
val<<=2;
}
dst+=pitch;
}
}
//switch endianness, unswizzle
//TODO: to save memory, don't blindly convert everything to argb8888
//also ARGB order needs to be swapped later, to accommodate modern hardware better
//need to add DXT support too
D3DFORMAT TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texformat, int tlutaddr, int tlutfmt)
{
DVSTARTPROFILE();
switch (texformat)
{
case GX_TF_C4:
{
for (int y=0; y<height; y+=8)
for (int x=0; x<width; x+=8)
for (int iy=0; iy<8; iy++, src+=4)
decodebytesC4((u32*)dst+(y+iy)*width+x,src,4,tlutaddr,tlutfmt);
}
return D3DFMT_A8R8G8B8;
case GX_TF_I4:
{
for (int y=0; y<height; y+=8)
for (int x=0; x<width; x+=8)
for (int iy=0; iy<8; iy++, src+=4)
decodebytesI4((u32*)dst+(y+iy)*width+x,src,4);
}
return D3DFMT_A8R8G8B8;
case GX_TF_C8:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=8)
for (int iy=0; iy<4; iy++, src+=8)
decodebytesC8((u32*)dst+(y+iy)*width+x,src,8,tlutaddr,tlutfmt);
}
return D3DFMT_A8R8G8B8;
case GX_TF_I8:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=8)
for (int iy=0; iy<4; iy++, src+=8)
decodebytesI8((u32*)dst+(y+iy)*width+x,src,8);
}
return D3DFMT_A8R8G8B8;
case GX_TF_IA4:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=8)
for (int iy=0; iy<4; iy++, src+=8)
decodebytesIA4((u32*)dst+(y+iy)*width+x,src,8);
}
return D3DFMT_A8R8G8B8;
case GX_TF_IA8:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=4)
for (int iy=0; iy<4; iy++,src+=8)
decodebytesIA8((u32*)dst+(y+iy)*width+x,(u16*)src,4);
}
return D3DFMT_A8R8G8B8;
case GX_TF_C14X2:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=4)
for (int iy=0; iy<4; iy++,src+=8)
decodebytesC14X2((u32*)dst+(y+iy)*width+x,(u16*)src,4,tlutaddr,tlutfmt);
}
return D3DFMT_A8R8G8B8;
case GX_TF_RGB565:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=4)
for (int iy=0; iy<4; iy++,src+=8)
decodebytesRGB565((u32*)dst+(y+iy)*width+x,(u16*)src,4);
}
return D3DFMT_A8R8G8B8;
case GX_TF_RGB5A3:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=4)
for (int iy=0; iy<4; iy++,src+=8)
decodebytesRGB5A3((u32*)dst+(y+iy)*width+x,(u16*)src,4);
}
return D3DFMT_A8R8G8B8;
case GX_TF_RGBA8:
{
for (int y=0; y<height; y+=4)
for (int x=0; x<width; x+=4)
{
for (int iy=0; iy<4; iy++,src+=8)
decodebytesARGB8pass1((u32*)dst+(y+iy)*width+x,(u16*)src,4);
for (int iy=0; iy<4; iy++,src+=8)
decodebytesARGB8pass2((u32*)dst+(y+iy)*width+x,(u16*)src,4);
}
}
return D3DFMT_A8R8G8B8;
case GX_TF_CMPR:
{
// 11111111 22222222 55555555 66666666
// 33333333 44444444 77777777 88888888
for (int y=0; y<height; y+=8)
for (int x=0; x<width; x+=8)
{
decodeDXTBlock((u32*)dst+y*width+x,(DXTBlock*)src,width);src+=sizeof(DXTBlock);
decodeDXTBlock((u32*)dst+y*width+x+4,(DXTBlock*)src,width);src+=sizeof(DXTBlock);
decodeDXTBlock((u32*)dst+(y+4)*width+x,(DXTBlock*)src,width);src+=sizeof(DXTBlock);
decodeDXTBlock((u32*)dst+(y+4)*width+x+4,(DXTBlock*)src,width);src+=sizeof(DXTBlock);
}
/*
int rowlen = width/2;
int numBigBlockRows = height/8;
int numBigBlocksPerRow = width/8;
int numSmallBlocksPerRow = width/4;
int numSmallBlockRows = height/4;
int smallBlockSize = 8;
for (int y=0; y<height/8; y+=8)
{
for (int x=0; x<width/8; x+=8)
{
memcpy(dst+y*2*numSmallBlocksPerRow*smallBlockSize+x*2*smallBlockSize,src,smallBlockSize); src+=smallBlockSize;
memcpy(dst+y*2*numSmallBlocksPerRow*smallBlockSize+(x*2+1)*smallBlockSize,src,smallBlockSize); src+=smallBlockSize;
memcpy(dst+(y*2+1)*numSmallBlocksPerRow*smallBlockSize+x*2*smallBlockSize,src,smallBlockSize); src+=smallBlockSize;
memcpy(dst+(y*2+1)*numSmallBlocksPerRow*smallBlockSize+(x*2+1)*smallBlockSize,src,smallBlockSize); src+=smallBlockSize;
}
}*/
}
return D3DFMT_A8R8G8B8;
// return D3DFMT_DXT1;
}
return D3DFMT_UNKNOWN;
}

View File

@ -1,61 +0,0 @@
#ifndef _TEXTUREDECODER_H
#define _TEXTUREDECODER_H
#include "Common.h"
#include "D3DBase.h"
enum
{
TMEM_SIZE = 1024*1024,
HALFTMEM_SIZE = 512*1024
};
extern u8 texMem[TMEM_SIZE];
enum TextureFormat
{
GX_TF_I4 = 0x0,
GX_TF_I8 = 0x1,
GX_TF_IA4 = 0x2,
GX_TF_IA8 = 0x3,
GX_TF_RGB565 = 0x4,
GX_TF_RGB5A3 = 0x5,
GX_TF_RGBA8 = 0x6,
GX_TF_C4 = 0x8,
GX_TF_C8 = 0x9,
GX_TF_C14X2 = 0xA,
GX_TF_CMPR = 0xE,
_GX_TF_CTF = 0x20, // copy-texture-format only (simply means linear?)
_GX_TF_ZTF = 0x10, // Z-texture-format
// these formats are also valid when copying targets
GX_CTF_R4 = 0x0 | _GX_TF_CTF,
GX_CTF_RA4 = 0x2 | _GX_TF_CTF,
GX_CTF_RA8 = 0x3 | _GX_TF_CTF,
GX_CTF_YUVA8 = 0x6 | _GX_TF_CTF,
GX_CTF_A8 = 0x7 | _GX_TF_CTF,
GX_CTF_R8 = 0x8 | _GX_TF_CTF,
GX_CTF_G8 = 0x9 | _GX_TF_CTF,
GX_CTF_B8 = 0xA | _GX_TF_CTF,
GX_CTF_RG8 = 0xB | _GX_TF_CTF,
GX_CTF_GB8 = 0xC | _GX_TF_CTF,
GX_TF_Z8 = 0x1 | _GX_TF_ZTF,
GX_TF_Z16 = 0x3 | _GX_TF_ZTF,
GX_TF_Z24X8 = 0x6 | _GX_TF_ZTF,
GX_CTF_Z4 = 0x0 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8M = 0x9 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8L = 0xA | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z16L = 0xC | _GX_TF_ZTF | _GX_TF_CTF,
};
int TexDecoder_GetTexelSizeInNibbles(int format);
int TexDecoder_GetBlockWidthInTexels(int format);
int TexDecoder_GetPaletteSize(int fmt);
D3DFORMAT TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texformat, int tlutaddr, int tlutfmt);
#endif

View File

@ -1,6 +1,24 @@
#pragma once
// Copyright (C) 2003-2008 Dolphin Project.
#include "Utils.h"
// 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 _VERTEXLOADERCOLOR_H
#define _VERTEXLOADERCOLOR_H
#include "LookUpTables.h"
#define RSHIFT 16
#define GSHIFT 8
@ -204,3 +222,4 @@ void LOADERDECL Color_ReadIndex16_32b_8888(void* _p)
_SetCol(_Read32(iAddress));
}
#endif