mirror of https://github.com/aap/librw.git
started work on (ps2) pipelines
This commit is contained in:
parent
34f0e5550b
commit
e9f638db05
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/')
|
|||
BUILDDIR=build-$(BUILD)
|
||||
SRCDIR=src
|
||||
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
|
||||
geometry.cpp plugins.cpp\
|
||||
geometry.cpp plugins.cpp pipeline.cpp\
|
||||
ps2.cpp ogl.cpp\
|
||||
image.cpp gtaplg.cpp)
|
||||
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))
|
||||
|
|
|
@ -6,7 +6,7 @@ BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/')
|
|||
BUILDDIR=build-$(BUILD)
|
||||
SRCDIR=src
|
||||
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
|
||||
geometry.cpp plugins.cpp\
|
||||
geometry.cpp plugins.cpp pipeline.cpp\
|
||||
ps2.cpp ogl.cpp\
|
||||
image.cpp gtaplg.cpp)
|
||||
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))
|
||||
|
|
|
@ -7,7 +7,7 @@ BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/')
|
|||
BUILDDIR=build-$(BUILD)
|
||||
SRCDIR=src
|
||||
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
|
||||
geometry.cpp plugins.cpp\
|
||||
geometry.cpp plugins.cpp pipeline.cpp\
|
||||
ps2.cpp ogl.cpp\
|
||||
image.cpp gtaplg.cpp)
|
||||
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))
|
||||
|
|
1
rw.h
1
rw.h
|
@ -1,5 +1,6 @@
|
|||
#include "src/rwbase.h"
|
||||
#include "src/rwplugin.h"
|
||||
#include "src/rwpipeline.h"
|
||||
#include "src/rwobjects.h"
|
||||
#include "src/rwps2.h"
|
||||
#include "src/rwogl.h"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
#include "gtaplg.h"
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
#include "rwogl.h"
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
#include "rwps2.h"
|
||||
#include "rwogl.h"
|
||||
|
@ -540,17 +541,20 @@ getSizeSkin(void *object, int32 offset, int32)
|
|||
}
|
||||
|
||||
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
|
||||
registerSkinPlugin(void)
|
||||
{
|
||||
skinGlobals.pipeline = new Pipeline;
|
||||
skinGlobals.pipeline->pluginID = ID_SKIN;
|
||||
skinGlobals.pipeline->pluginData = 1;
|
||||
Pipeline *defpipe = new Pipeline(PLATFORM_NULL);
|
||||
defpipe->pluginID = ID_SKIN;
|
||||
defpipe->pluginData = 1;
|
||||
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
|
||||
skinGlobals.pipelines[i] = defpipe;
|
||||
|
||||
|
||||
skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
|
||||
createSkin,
|
||||
|
@ -589,7 +593,8 @@ readAtomicMatFX(Stream *stream, int32, void *object, int32 offset, int32)
|
|||
stream->read(&flag, 4);
|
||||
*PLUGINOFFSET(int32, object, offset) = flag;
|
||||
if(flag)
|
||||
((Atomic*)object)->pipeline = matFXGlobals.pipeline;
|
||||
((Atomic*)object)->pipeline =
|
||||
matFXGlobals.pipelines[platformIdx[rw::platform]];
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -873,9 +878,11 @@ getSizeMaterialMatFX(void *object, int32 offset, int32)
|
|||
void
|
||||
registerMatFXPlugin(void)
|
||||
{
|
||||
matFXGlobals.pipeline = new Pipeline;
|
||||
matFXGlobals.pipeline->pluginID = ID_MATFX;
|
||||
matFXGlobals.pipeline->pluginData = 0;
|
||||
Pipeline *defpipe = new Pipeline(PLATFORM_NULL);
|
||||
defpipe->pluginID = ID_MATFX;
|
||||
defpipe->pluginData = 0;
|
||||
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
|
||||
matFXGlobals.pipelines[i] = defpipe;
|
||||
|
||||
matFXGlobals.atomicOffset =
|
||||
Atomic::registerPlugin(sizeof(int32), ID_MATFX,
|
||||
|
|
125
src/ps2.cpp
125
src/ps2.cpp
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "rwbase.h"
|
||||
#include "rwplugin.h"
|
||||
#include "rwpipeline.h"
|
||||
#include "rwobjects.h"
|
||||
#include "rwps2.h"
|
||||
|
||||
|
@ -146,6 +147,7 @@ fixDmaOffsets(InstanceData *inst)
|
|||
void
|
||||
unfixDmaOffsets(InstanceData *inst)
|
||||
{
|
||||
(void)inst;
|
||||
#ifdef RW_PS2
|
||||
if(inst->arePointersFixed != 2)
|
||||
return;
|
||||
|
@ -181,6 +183,129 @@ unfixDmaOffsets(InstanceData *inst)
|
|||
#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
|
||||
|
||||
void
|
||||
|
|
|
@ -12,8 +12,17 @@ using namespace std;
|
|||
|
||||
namespace rw {
|
||||
|
||||
int platformIdx[10] = { 0, -1, 1, -1, 2, 3, -1, -1, 4, 5 };
|
||||
|
||||
int version = 0x36003;
|
||||
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;
|
||||
|
||||
int32
|
||||
|
@ -219,14 +228,12 @@ StreamFile::close(void)
|
|||
uint32
|
||||
StreamFile::write(const void *data, uint32 length)
|
||||
{
|
||||
//printf("write %d bytes @ %x\n", length, this->tell());
|
||||
return fwrite(data, length, 1, this->file);
|
||||
}
|
||||
|
||||
uint32
|
||||
StreamFile::read(void *data, uint32 length)
|
||||
{
|
||||
//printf("read %d bytes @ %x\n", length, this->tell());
|
||||
return fread(data, length, 1, this->file);
|
||||
}
|
||||
|
||||
|
@ -255,7 +262,6 @@ writeChunkHeader(Stream *s, int32 type, int32 size)
|
|||
int32 type, size;
|
||||
uint32 id;
|
||||
} buf = { type, size, libraryIDPack(version, build) };
|
||||
//printf("- write chunk %x @ %x\n", buf.type, s->tell());
|
||||
s->write(&buf, 12);
|
||||
return true;
|
||||
}
|
||||
|
@ -290,7 +296,6 @@ findChunk(Stream *s, uint32 type, uint32 *length, uint32 *version)
|
|||
*length = header.length;
|
||||
if(version)
|
||||
*version = header.version;
|
||||
//printf("- chunk %x @ %x\n", header.type, s->tell()-12);
|
||||
return true;
|
||||
}
|
||||
s->seek(header.length);
|
||||
|
|
13
src/rwbase.h
13
src/rwbase.h
|
@ -32,6 +32,8 @@ typedef int32 bool32;
|
|||
typedef uint8 byte;
|
||||
typedef uint32 uint;
|
||||
|
||||
#define nelem(A) (sizeof(A) / sizeof A[0])
|
||||
|
||||
class Stream
|
||||
{
|
||||
public:
|
||||
|
@ -93,13 +95,21 @@ public:
|
|||
|
||||
enum Platform
|
||||
{
|
||||
PLATFORM_NULL = 0,
|
||||
// D3D7
|
||||
PLATFORM_OGL = 2,
|
||||
// MAC
|
||||
PLATFORM_PS2 = 4,
|
||||
PLATFORM_XBOX = 5,
|
||||
// GAMECUBE
|
||||
// SOFTRAS
|
||||
PLATFORM_D3D8 = 8,
|
||||
PLATFORM_D3D9 = 9
|
||||
PLATFORM_D3D9 = 9,
|
||||
NUM_PLATFORMS = 6
|
||||
};
|
||||
|
||||
extern int platformIdx[10];
|
||||
|
||||
enum PluginID
|
||||
{
|
||||
// Core
|
||||
|
@ -134,6 +144,7 @@ enum PluginID
|
|||
|
||||
extern int version;
|
||||
extern int build;
|
||||
extern int platform;
|
||||
extern char *debugFile;
|
||||
|
||||
inline uint32
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
namespace rw {
|
||||
|
||||
// TODO: mostly a stub right now
|
||||
struct Pipeline
|
||||
{
|
||||
uint32 pluginID;
|
||||
uint32 pluginData;
|
||||
};
|
||||
|
||||
struct Object
|
||||
{
|
||||
uint8 type;
|
||||
|
@ -233,7 +226,7 @@ struct MatFXGlobals
|
|||
{
|
||||
int32 atomicOffset;
|
||||
int32 materialOffset;
|
||||
Pipeline *pipeline;
|
||||
Pipeline *pipelines[NUM_PLATFORMS];
|
||||
};
|
||||
extern MatFXGlobals matFXGlobals;
|
||||
void registerMatFXPlugin(void);
|
||||
|
@ -330,7 +323,7 @@ struct Skin
|
|||
struct SkinGlobals
|
||||
{
|
||||
int32 offset;
|
||||
Pipeline *pipeline;
|
||||
Pipeline *pipelines[NUM_PLATFORMS];
|
||||
};
|
||||
extern SkinGlobals skinGlobals;
|
||||
void registerSkinPlugin(void);
|
||||
|
|
25
src/rwps2.h
25
src/rwps2.h
|
@ -19,6 +19,10 @@ struct InstanceDataHeader : rw::InstanceDataHeader
|
|||
InstanceData *instanceMeshes;
|
||||
};
|
||||
|
||||
enum {
|
||||
VU_Lights = 0x3d0
|
||||
};
|
||||
|
||||
void *destroyNativeData(void *object, int32, int32);
|
||||
void readNativeData(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
|
||||
void fixDmaOffsets(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
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ OBJ = $(patsubst %.cpp, $(BUILDDIR)/%.o, $(SRC))
|
|||
DEP = $(patsubst %.cpp, $(BUILDDIR)/%.d, $(SRC))
|
||||
RWDIR=$(HOME)/src/librw
|
||||
|
||||
#LDLIBS=-pthread -lX11 -lXrandr -lXi -lXxf86vm -lGL -lGLEW -lm
|
||||
#STATICLIBS= $(RWDIR)/librw-opengl.a /usr/local/lib/libglfw3.a
|
||||
LDLIBS=-pthread -lX11 -lXrandr -lXi -lXxf86vm -lGL -lGLEW -lm
|
||||
STATICLIBS= $(RWDIR)/librw-opengl.a /usr/local/lib/libglfw3.a
|
||||
|
||||
LDLIBS=-pthread -lGL -lGLEW -lglfw
|
||||
STATICLIBS=$(RWDIR)/librw-opengl.a
|
||||
#LDLIBS=-pthread -lGL -lGLEW -lglfw
|
||||
#STATICLIBS=$(RWDIR)/librw-opengl.a
|
||||
|
||||
CFLAGS=-g -I$(RWDIR) -Wall -Wextra
|
||||
|
||||
|
|
|
@ -42,15 +42,16 @@ renderAtomic(rw::Atomic *atomic)
|
|||
uint64 offset = 0;
|
||||
for(uint32 i = 0; i < meshHeader->numMeshes; i++){
|
||||
Mesh *mesh = &meshHeader->mesh[i];
|
||||
Material *mat = mesh->material;
|
||||
float color[4];
|
||||
uint8 *col = mesh->material->color;
|
||||
uint8 *col = mat->color;
|
||||
color[0] = col[0] / 255.0f;
|
||||
color[1] = col[1] / 255.0f;
|
||||
color[2] = col[2] / 255.0f;
|
||||
color[3] = col[3] / 255.0f;
|
||||
glUniform4fv(glGetUniformLocation(program, "matColor"),
|
||||
1, color);
|
||||
rw::gl::Texture *tex =(rw::gl::Texture*)mesh->material->texture;
|
||||
rw::gl::Texture *tex =(rw::gl::Texture*)mat->texture;
|
||||
if(tex)
|
||||
tex->bind(0);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue