started work on (ps2) pipelines

This commit is contained in:
aap 2015-07-11 23:48:11 +02:00
parent 34f0e5550b
commit e9f638db05
17 changed files with 205 additions and 32 deletions

View File

@ -6,7 +6,7 @@ BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/')
BUILDDIR=build-$(BUILD) BUILDDIR=build-$(BUILD)
SRCDIR=src SRCDIR=src
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
geometry.cpp plugins.cpp\ geometry.cpp plugins.cpp pipeline.cpp\
ps2.cpp ogl.cpp\ ps2.cpp ogl.cpp\
image.cpp gtaplg.cpp) image.cpp gtaplg.cpp)
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))

View File

@ -6,7 +6,7 @@ BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/')
BUILDDIR=build-$(BUILD) BUILDDIR=build-$(BUILD)
SRCDIR=src SRCDIR=src
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
geometry.cpp plugins.cpp\ geometry.cpp plugins.cpp pipeline.cpp\
ps2.cpp ogl.cpp\ ps2.cpp ogl.cpp\
image.cpp gtaplg.cpp) image.cpp gtaplg.cpp)
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))

View File

@ -7,7 +7,7 @@ BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/')
BUILDDIR=build-$(BUILD) BUILDDIR=build-$(BUILD)
SRCDIR=src SRCDIR=src
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
geometry.cpp plugins.cpp\ geometry.cpp plugins.cpp pipeline.cpp\
ps2.cpp ogl.cpp\ ps2.cpp ogl.cpp\
image.cpp gtaplg.cpp) image.cpp gtaplg.cpp)
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))

1
rw.h
View File

@ -1,5 +1,6 @@
#include "src/rwbase.h" #include "src/rwbase.h"
#include "src/rwplugin.h" #include "src/rwplugin.h"
#include "src/rwpipeline.h"
#include "src/rwobjects.h" #include "src/rwobjects.h"
#include "src/rwps2.h" #include "src/rwps2.h"
#include "src/rwogl.h" #include "src/rwogl.h"

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
using namespace std; using namespace std;

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
using namespace std; using namespace std;

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "gtaplg.h" #include "gtaplg.h"

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
using namespace std; using namespace std;

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwogl.h" #include "rwogl.h"

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwps2.h" #include "rwps2.h"
#include "rwogl.h" #include "rwogl.h"
@ -540,17 +541,20 @@ getSizeSkin(void *object, int32 offset, int32)
} }
static void static void
skinRights(void *object, int32, int32, uint32 data) skinRights(void *object, int32, int32, uint32)
{ {
((Atomic*)object)->pipeline = skinGlobals.pipeline; ((Atomic*)object)->pipeline = skinGlobals.pipelines[platformIdx[platform]];
} }
void void
registerSkinPlugin(void) registerSkinPlugin(void)
{ {
skinGlobals.pipeline = new Pipeline; Pipeline *defpipe = new Pipeline(PLATFORM_NULL);
skinGlobals.pipeline->pluginID = ID_SKIN; defpipe->pluginID = ID_SKIN;
skinGlobals.pipeline->pluginData = 1; defpipe->pluginData = 1;
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
skinGlobals.pipelines[i] = defpipe;
skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN, skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
createSkin, createSkin,
@ -589,7 +593,8 @@ readAtomicMatFX(Stream *stream, int32, void *object, int32 offset, int32)
stream->read(&flag, 4); stream->read(&flag, 4);
*PLUGINOFFSET(int32, object, offset) = flag; *PLUGINOFFSET(int32, object, offset) = flag;
if(flag) if(flag)
((Atomic*)object)->pipeline = matFXGlobals.pipeline; ((Atomic*)object)->pipeline =
matFXGlobals.pipelines[platformIdx[rw::platform]];
} }
static void static void
@ -873,9 +878,11 @@ getSizeMaterialMatFX(void *object, int32 offset, int32)
void void
registerMatFXPlugin(void) registerMatFXPlugin(void)
{ {
matFXGlobals.pipeline = new Pipeline; Pipeline *defpipe = new Pipeline(PLATFORM_NULL);
matFXGlobals.pipeline->pluginID = ID_MATFX; defpipe->pluginID = ID_MATFX;
matFXGlobals.pipeline->pluginData = 0; defpipe->pluginData = 0;
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
matFXGlobals.pipelines[i] = defpipe;
matFXGlobals.atomicOffset = matFXGlobals.atomicOffset =
Atomic::registerPlugin(sizeof(int32), ID_MATFX, Atomic::registerPlugin(sizeof(int32), ID_MATFX,

View File

@ -7,6 +7,7 @@
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwps2.h" #include "rwps2.h"
@ -146,6 +147,7 @@ fixDmaOffsets(InstanceData *inst)
void void
unfixDmaOffsets(InstanceData *inst) unfixDmaOffsets(InstanceData *inst)
{ {
(void)inst;
#ifdef RW_PS2 #ifdef RW_PS2
if(inst->arePointersFixed != 2) if(inst->arePointersFixed != 2)
return; return;
@ -181,6 +183,129 @@ unfixDmaOffsets(InstanceData *inst)
#endif #endif
} }
// Pipeline
enum PS2Attribs {
AT_V2_32 = 0x64000000,
AT_V2_16 = 0x65000000,
AT_V2_8 = 0x66000000,
AT_V3_32 = 0x68000000,
AT_V3_16 = 0x69000000,
AT_V3_8 = 0x6A000000,
AT_V4_32 = 0x6C000000,
AT_V4_16 = 0x6D000000,
AT_V4_8 = 0x6E000000,
AT_UNSGN = 0x00004000,
AT_RW = 0x6
};
enum PS2AttibTypes {
AT_XYZ = 0,
AT_UV = 1,
AT_UV2 = 2,
AT_RGBA = 3,
AT_NORMAL = 4
};
PipeAttribute attribXYZ = {
"XYZ",
AT_V3_32
};
PipeAttribute attribUV = {
"UV",
AT_V2_32
};
PipeAttribute attribUV2 = {
"UV2",
AT_V4_32
};
PipeAttribute attribRGBA = {
"RGBA",
AT_V4_8 | AT_UNSGN
};
PipeAttribute attribNormal = {
"Normal",
AT_V3_8 // RW has V4_8 but uses V3_8, wtf?
};
PipeAttribute attribWeights = {
"Weights",
AT_V4_32 | AT_RW
};
Pipeline::Pipeline(uint32 platform)
: rw::Pipeline(platform) { }
void
Pipeline::setTriBufferSizes(uint32 inputStride,
uint32 stripCount, uint32 listCount)
{
this->inputStride = inputStride;
this->triListCount = listCount/12*12;
PipeAttribute *a;
for(uint i = 0; i < nelem(this->attribs); i++){
a = this->attribs[i];
if(a && a->attrib & AT_RW)
goto brokenout;
}
this->triStripCount = stripCount/4*4;
return;
brokenout:
this->triStripCount = (stripCount-2)/4*4+2;
}
Pipeline*
makeDefaultPipeline(void)
{
Pipeline *pipe = new Pipeline(PLATFORM_PS2);
pipe->attribs[AT_XYZ] = &attribXYZ;
pipe->attribs[AT_UV] = &attribUV;
pipe->attribs[AT_RGBA] = &attribRGBA;
pipe->attribs[AT_NORMAL] = &attribNormal;
uint32 vertCount = Pipeline::getVertCount(VU_Lights, 4, 3, 2);
pipe->setTriBufferSizes(4, vertCount, vertCount/3);
pipe->vifOffset = pipe->inputStride*vertCount;
return pipe;
}
Pipeline*
makeSkinPipeline(void)
{
Pipeline *pipe = new Pipeline(PLATFORM_PS2);
pipe->attribs[AT_XYZ] = &attribXYZ;
pipe->attribs[AT_UV] = &attribUV;
pipe->attribs[AT_RGBA] = &attribRGBA;
pipe->attribs[AT_NORMAL] = &attribNormal;
pipe->attribs[AT_NORMAL+1] = &attribWeights;
uint32 vertCount = Pipeline::getVertCount(VU_Lights-0x100, 5, 3, 2);
pipe->setTriBufferSizes(5, vertCount, vertCount/3);
pipe->vifOffset = pipe->inputStride*vertCount;
return pipe;
}
void
dumpPipeline(rw::Pipeline *rwpipe)
{
if(rwpipe->platform != PLATFORM_PS2)
return;
Pipeline *pipe = (Pipeline*)rwpipe;
PipeAttribute *a;
for(uint i = 0; i < nelem(pipe->attribs); i++){
a = pipe->attribs[i];
if(a)
printf("%d %s: %x\n", i, a->name, a->attrib);
}
printf("stride: %x\n", pipe->inputStride);
printf("triSCount: %x\n", pipe->triStripCount);
printf("triLCount: %x\n", pipe->triListCount);
printf("vifOffset: %x\n", pipe->vifOffset);
}
// Skin // Skin
void void

View File

@ -12,8 +12,17 @@ using namespace std;
namespace rw { namespace rw {
int platformIdx[10] = { 0, -1, 1, -1, 2, 3, -1, -1, 4, 5 };
int version = 0x36003; int version = 0x36003;
int build = 0xFFFF; int build = 0xFFFF;
#ifdef RW_PS2
int platform = PLATFORM_PS2;
#elseif RW_OPENGL
int platform = PLATFORM_OPENGL;
#else
int platform = PLATFORM_NULL;
#endif
char *debugFile = NULL; char *debugFile = NULL;
int32 int32
@ -219,14 +228,12 @@ StreamFile::close(void)
uint32 uint32
StreamFile::write(const void *data, uint32 length) StreamFile::write(const void *data, uint32 length)
{ {
//printf("write %d bytes @ %x\n", length, this->tell());
return fwrite(data, length, 1, this->file); return fwrite(data, length, 1, this->file);
} }
uint32 uint32
StreamFile::read(void *data, uint32 length) StreamFile::read(void *data, uint32 length)
{ {
//printf("read %d bytes @ %x\n", length, this->tell());
return fread(data, length, 1, this->file); return fread(data, length, 1, this->file);
} }
@ -255,7 +262,6 @@ writeChunkHeader(Stream *s, int32 type, int32 size)
int32 type, size; int32 type, size;
uint32 id; uint32 id;
} buf = { type, size, libraryIDPack(version, build) }; } buf = { type, size, libraryIDPack(version, build) };
//printf("- write chunk %x @ %x\n", buf.type, s->tell());
s->write(&buf, 12); s->write(&buf, 12);
return true; return true;
} }
@ -290,7 +296,6 @@ findChunk(Stream *s, uint32 type, uint32 *length, uint32 *version)
*length = header.length; *length = header.length;
if(version) if(version)
*version = header.version; *version = header.version;
//printf("- chunk %x @ %x\n", header.type, s->tell()-12);
return true; return true;
} }
s->seek(header.length); s->seek(header.length);

View File

@ -32,6 +32,8 @@ typedef int32 bool32;
typedef uint8 byte; typedef uint8 byte;
typedef uint32 uint; typedef uint32 uint;
#define nelem(A) (sizeof(A) / sizeof A[0])
class Stream class Stream
{ {
public: public:
@ -93,13 +95,21 @@ public:
enum Platform enum Platform
{ {
PLATFORM_NULL = 0,
// D3D7
PLATFORM_OGL = 2, PLATFORM_OGL = 2,
// MAC
PLATFORM_PS2 = 4, PLATFORM_PS2 = 4,
PLATFORM_XBOX = 5, PLATFORM_XBOX = 5,
// GAMECUBE
// SOFTRAS
PLATFORM_D3D8 = 8, PLATFORM_D3D8 = 8,
PLATFORM_D3D9 = 9 PLATFORM_D3D9 = 9,
NUM_PLATFORMS = 6
}; };
extern int platformIdx[10];
enum PluginID enum PluginID
{ {
// Core // Core
@ -134,6 +144,7 @@ enum PluginID
extern int version; extern int version;
extern int build; extern int build;
extern int platform;
extern char *debugFile; extern char *debugFile;
inline uint32 inline uint32

View File

@ -1,12 +1,5 @@
namespace rw { namespace rw {
// TODO: mostly a stub right now
struct Pipeline
{
uint32 pluginID;
uint32 pluginData;
};
struct Object struct Object
{ {
uint8 type; uint8 type;
@ -233,7 +226,7 @@ struct MatFXGlobals
{ {
int32 atomicOffset; int32 atomicOffset;
int32 materialOffset; int32 materialOffset;
Pipeline *pipeline; Pipeline *pipelines[NUM_PLATFORMS];
}; };
extern MatFXGlobals matFXGlobals; extern MatFXGlobals matFXGlobals;
void registerMatFXPlugin(void); void registerMatFXPlugin(void);
@ -330,7 +323,7 @@ struct Skin
struct SkinGlobals struct SkinGlobals
{ {
int32 offset; int32 offset;
Pipeline *pipeline; Pipeline *pipelines[NUM_PLATFORMS];
}; };
extern SkinGlobals skinGlobals; extern SkinGlobals skinGlobals;
void registerSkinPlugin(void); void registerSkinPlugin(void);

View File

@ -19,6 +19,10 @@ struct InstanceDataHeader : rw::InstanceDataHeader
InstanceData *instanceMeshes; InstanceData *instanceMeshes;
}; };
enum {
VU_Lights = 0x3d0
};
void *destroyNativeData(void *object, int32, int32); void *destroyNativeData(void *object, int32, int32);
void readNativeData(Stream *stream, int32 len, void *object, int32, int32); void readNativeData(Stream *stream, int32 len, void *object, int32, int32);
void writeNativeData(Stream *stream, int32 len, void *object, int32, int32); void writeNativeData(Stream *stream, int32 len, void *object, int32, int32);
@ -31,6 +35,27 @@ void sizedebug(InstanceData *inst);
// only RW_PS2 // only RW_PS2
void fixDmaOffsets(InstanceData *inst); void fixDmaOffsets(InstanceData *inst);
void unfixDmaOffsets(InstanceData *inst); void unfixDmaOffsets(InstanceData *inst);
//
struct Pipeline : rw::Pipeline
{
uint32 vifOffset;
uint32 inputStride;
uint32 triStripCount, triListCount;
static uint32 getVertCount(uint32 top, uint32 inAttribs,
uint32 outAttribs, uint32 outBufs) {
return (top-outBufs)/(inAttribs*2+outAttribs*outBufs);
}
Pipeline(uint32 platform);
void setTriBufferSizes(uint32 inputStride,
uint32 stripCount, uint32 listCount);
};
Pipeline *makeDefaultPipeline(void);
Pipeline *makeSkinPipeline(void);
void dumpPipeline(rw::Pipeline *pipe);
// Skin plugin // Skin plugin

View File

@ -4,11 +4,11 @@ OBJ = $(patsubst %.cpp, $(BUILDDIR)/%.o, $(SRC))
DEP = $(patsubst %.cpp, $(BUILDDIR)/%.d, $(SRC)) DEP = $(patsubst %.cpp, $(BUILDDIR)/%.d, $(SRC))
RWDIR=$(HOME)/src/librw RWDIR=$(HOME)/src/librw
#LDLIBS=-pthread -lX11 -lXrandr -lXi -lXxf86vm -lGL -lGLEW -lm LDLIBS=-pthread -lX11 -lXrandr -lXi -lXxf86vm -lGL -lGLEW -lm
#STATICLIBS= $(RWDIR)/librw-opengl.a /usr/local/lib/libglfw3.a STATICLIBS= $(RWDIR)/librw-opengl.a /usr/local/lib/libglfw3.a
LDLIBS=-pthread -lGL -lGLEW -lglfw #LDLIBS=-pthread -lGL -lGLEW -lglfw
STATICLIBS=$(RWDIR)/librw-opengl.a #STATICLIBS=$(RWDIR)/librw-opengl.a
CFLAGS=-g -I$(RWDIR) -Wall -Wextra CFLAGS=-g -I$(RWDIR) -Wall -Wextra

View File

@ -42,15 +42,16 @@ renderAtomic(rw::Atomic *atomic)
uint64 offset = 0; uint64 offset = 0;
for(uint32 i = 0; i < meshHeader->numMeshes; i++){ for(uint32 i = 0; i < meshHeader->numMeshes; i++){
Mesh *mesh = &meshHeader->mesh[i]; Mesh *mesh = &meshHeader->mesh[i];
Material *mat = mesh->material;
float color[4]; float color[4];
uint8 *col = mesh->material->color; uint8 *col = mat->color;
color[0] = col[0] / 255.0f; color[0] = col[0] / 255.0f;
color[1] = col[1] / 255.0f; color[1] = col[1] / 255.0f;
color[2] = col[2] / 255.0f; color[2] = col[2] / 255.0f;
color[3] = col[3] / 255.0f; color[3] = col[3] / 255.0f;
glUniform4fv(glGetUniformLocation(program, "matColor"), glUniform4fv(glGetUniformLocation(program, "matColor"),
1, color); 1, color);
rw::gl::Texture *tex =(rw::gl::Texture*)mesh->material->texture; rw::gl::Texture *tex =(rw::gl::Texture*)mat->texture;
if(tex) if(tex)
tex->bind(0); tex->bind(0);
else else