mirror of
https://github.com/aap/librw.git
synced 2025-12-19 00:49:50 +00:00
fixed sky mipmap stream write; experimented with software pipeline
This commit is contained in:
@@ -383,6 +383,7 @@ rasterCreateTexture(Raster *raster)
|
||||
}else
|
||||
format = formatInfo[(raster->format >> 8) & 0xF].d3dformat;
|
||||
natras->format = format;
|
||||
raster->depth = formatInfo[(raster->format >> 8) & 0xF].depth;
|
||||
natras->hasAlpha = formatInfo[(raster->format >> 8) & 0xF].hasAlpha;
|
||||
levels = Raster::calculateNumLevels(raster->width, raster->height);
|
||||
natras->texture = createTexture(raster->width, raster->height,
|
||||
|
||||
@@ -1064,6 +1064,9 @@ Device renderdevice = {
|
||||
d3d::showRaster,
|
||||
d3d::setRwRenderState,
|
||||
d3d::getRwRenderState,
|
||||
d3d::im2DRenderLine,
|
||||
d3d::im2DRenderTriangle,
|
||||
d3d::im2DRenderPrimitive,
|
||||
d3d::im2DRenderIndexedPrimitive,
|
||||
d3d::im3DTransform,
|
||||
d3d::im3DRenderIndexed,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "../rwengine.h"
|
||||
#include "rwd3d.h"
|
||||
#include "rwd3d9.h"
|
||||
#include "rwd3dimpl.h"
|
||||
|
||||
namespace rw {
|
||||
namespace d3d {
|
||||
@@ -56,6 +57,73 @@ closeIm2D(void)
|
||||
deleteObject(im2dindbuf);
|
||||
}
|
||||
|
||||
static Im2DVertex tmpprimbuf[3];
|
||||
|
||||
void
|
||||
im2DRenderLine(void *vertices, int32 numVertices, int32 vert1, int32 vert2)
|
||||
{
|
||||
Im2DVertex *verts = (Im2DVertex*)vertices;
|
||||
tmpprimbuf[0] = verts[vert1];
|
||||
tmpprimbuf[1] = verts[vert2];
|
||||
im2DRenderPrimitive(PRIMTYPELINELIST, tmpprimbuf, 2);
|
||||
}
|
||||
|
||||
void
|
||||
im2DRenderTriangle(void *vertices, int32 numVertices, int32 vert1, int32 vert2, int32 vert3)
|
||||
{
|
||||
Im2DVertex *verts = (Im2DVertex*)vertices;
|
||||
tmpprimbuf[0] = verts[vert1];
|
||||
tmpprimbuf[1] = verts[vert2];
|
||||
tmpprimbuf[2] = verts[vert3];
|
||||
im2DRenderPrimitive(PRIMTYPETRILIST, tmpprimbuf, 3);
|
||||
}
|
||||
|
||||
void
|
||||
im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
|
||||
{
|
||||
if(numVertices > NUMVERTICES){
|
||||
// TODO: error
|
||||
return;
|
||||
}
|
||||
uint8 *lockedvertices = lockVertices(im2dvertbuf, 0, numVertices*sizeof(Im2DVertex), D3DLOCK_NOSYSLOCK);
|
||||
memcpy(lockedvertices, vertices, numVertices*sizeof(Im2DVertex));
|
||||
unlockVertices(im2dvertbuf);
|
||||
|
||||
d3ddevice->SetStreamSource(0, im2dvertbuf, 0, sizeof(Im2DVertex));
|
||||
d3ddevice->SetVertexDeclaration(im2ddecl);
|
||||
setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
setTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
|
||||
setTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
||||
setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
setTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
|
||||
|
||||
d3d::flushCache();
|
||||
|
||||
uint32 primCount = 0;
|
||||
switch(primType){
|
||||
case PRIMTYPELINELIST:
|
||||
primCount = numVertices/2;
|
||||
break;
|
||||
case PRIMTYPEPOLYLINE:
|
||||
primCount = numVertices-1;
|
||||
break;
|
||||
case PRIMTYPETRILIST:
|
||||
primCount = numVertices/3;
|
||||
break;
|
||||
case PRIMTYPETRISTRIP:
|
||||
primCount = numVertices-2;
|
||||
break;
|
||||
case PRIMTYPETRIFAN:
|
||||
primCount = numVertices-2;
|
||||
break;
|
||||
case PRIMTYPEPOINTLIST:
|
||||
primCount = numVertices;
|
||||
break;
|
||||
}
|
||||
d3ddevice->DrawPrimitive((D3DPRIMITIVETYPE)primTypeMap[primType], 0, primCount);
|
||||
}
|
||||
|
||||
void
|
||||
im2DRenderIndexedPrimitive(PrimitiveType primType,
|
||||
void *vertices, int32 numVertices, void *indices, int32 numIndices)
|
||||
|
||||
@@ -32,10 +32,16 @@ struct Im3DVertex
|
||||
void setY(float32 y) { this->position.y = y; }
|
||||
void setZ(float32 z) { this->position.z = z; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { this->color = D3DCOLOR_ARGB(a, r, g, b); }
|
||||
RGBA getColor(void) { return makeRGBA(this->color>>16 & 0xFF, this->color>>8 & 0xFF,
|
||||
this->color & 0xFF, this->color>>24 & 0xFF); }
|
||||
void setU(float32 u) { this->u = u; }
|
||||
void setV(float32 v) { this->v = v; }
|
||||
|
||||
float getX(void) { return this->position.x; }
|
||||
float getY(void) { return this->position.y; }
|
||||
float getZ(void) { return this->position.z; }
|
||||
RGBA getColor(void) { return makeRGBA(this->color>>16 & 0xFF, this->color>>8 & 0xFF,
|
||||
this->color & 0xFF, this->color>>24 & 0xFF); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
struct Im2DVertex
|
||||
@@ -53,6 +59,15 @@ struct Im2DVertex
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { this->color = D3DCOLOR_ARGB(a, r, g, b); }
|
||||
void setU(float32 u, float recipZ) { this->u = u; }
|
||||
void setV(float32 v, float recipZ) { this->v = v; }
|
||||
|
||||
float getScreenX(void) { return this->x; }
|
||||
float getScreenY(void) { return this->y; }
|
||||
float getScreenZ(void) { return this->z; }
|
||||
float getCameraZ(void) { return this->w; }
|
||||
RGBA getColor(void) { return makeRGBA(this->color>>16 & 0xFF, this->color>>8 & 0xFF,
|
||||
this->color & 0xFF, this->color>>24 & 0xFF); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
void setD3dMaterial(D3DMATERIAL9 *mat9);
|
||||
|
||||
@@ -4,6 +4,12 @@ namespace d3d {
|
||||
#ifdef RW_D3D9
|
||||
void openIm2D(void);
|
||||
void closeIm2D(void);
|
||||
void im2DRenderLine(void *vertices, int32 numVertices,
|
||||
int32 vert1, int32 vert2);
|
||||
void im2DRenderTriangle(void *vertices, int32 numVertices,
|
||||
int32 vert1, int32 vert2, int32 vert3);
|
||||
void im2DRenderPrimitive(PrimitiveType primType,
|
||||
void *vertices, int32 numVertices);
|
||||
void im2DRenderIndexedPrimitive(PrimitiveType primType,
|
||||
void *vertices, int32 numVertices, void *indices, int32 numIndices);
|
||||
|
||||
|
||||
@@ -209,6 +209,9 @@ void showRaster(Raster*) { }
|
||||
void setRenderState(int32, void*) { }
|
||||
void *getRenderState(int32) { return 0; }
|
||||
|
||||
void im2DRenderLine(void*, int32, int32, int32) { }
|
||||
void im2DRenderTriangle(void*, int32, int32, int32, int32) { }
|
||||
void im2DRenderPrimitive(PrimitiveType, void*, int32) { }
|
||||
void im2DRenderIndexedPrimitive(PrimitiveType, void*, int32, void*, int32) { }
|
||||
|
||||
void im3DTransform(void *vertices, int32 numVertices, Matrix *world) { }
|
||||
@@ -268,6 +271,9 @@ Device renderdevice = {
|
||||
null::showRaster,
|
||||
null::setRenderState,
|
||||
null::getRenderState,
|
||||
null::im2DRenderLine,
|
||||
null::im2DRenderTriangle,
|
||||
null::im2DRenderPrimitive,
|
||||
null::im2DRenderIndexedPrimitive,
|
||||
null::im3DTransform,
|
||||
null::im3DRenderIndexed,
|
||||
|
||||
@@ -859,6 +859,9 @@ Device renderdevice = {
|
||||
gl3::showRaster,
|
||||
gl3::setRenderState,
|
||||
gl3::getRenderState,
|
||||
gl3::im2DRenderLine,
|
||||
gl3::im2DRenderTriangle,
|
||||
gl3::im2DRenderPrimitive,
|
||||
gl3::im2DRenderIndexedPrimitive,
|
||||
gl3::im3DTransform,
|
||||
gl3::im3DRenderIndexed,
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#ifdef RW_OPENGL
|
||||
#include <GL/glew.h>
|
||||
#include "rwgl3.h"
|
||||
#include "rwgl3impl.h"
|
||||
#include "rwgl3shader.h"
|
||||
|
||||
namespace rw {
|
||||
@@ -73,6 +74,53 @@ closeIm2D(void)
|
||||
im2dShader = nil;
|
||||
}
|
||||
|
||||
static Im2DVertex tmpprimbuf[3];
|
||||
|
||||
void
|
||||
im2DRenderLine(void *vertices, int32 numVertices, int32 vert1, int32 vert2)
|
||||
{
|
||||
Im2DVertex *verts = (Im2DVertex*)vertices;
|
||||
tmpprimbuf[0] = verts[vert1];
|
||||
tmpprimbuf[1] = verts[vert2];
|
||||
im2DRenderPrimitive(PRIMTYPELINELIST, tmpprimbuf, 2);
|
||||
}
|
||||
|
||||
void
|
||||
im2DRenderTriangle(void *vertices, int32 numVertices, int32 vert1, int32 vert2, int32 vert3)
|
||||
{
|
||||
Im2DVertex *verts = (Im2DVertex*)vertices;
|
||||
tmpprimbuf[0] = verts[vert1];
|
||||
tmpprimbuf[1] = verts[vert2];
|
||||
tmpprimbuf[2] = verts[vert3];
|
||||
im2DRenderPrimitive(PRIMTYPETRILIST, tmpprimbuf, 3);
|
||||
}
|
||||
|
||||
void
|
||||
im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
|
||||
{
|
||||
GLfloat xform[4];
|
||||
Camera *cam;
|
||||
cam = (Camera*)engine->currentCamera;
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex),
|
||||
vertices, GL_DYNAMIC_DRAW);
|
||||
|
||||
xform[0] = 2.0f/cam->frameBuffer->width;
|
||||
xform[1] = -2.0f/cam->frameBuffer->height;
|
||||
xform[2] = -1.0f;
|
||||
xform[3] = 1.0f;
|
||||
|
||||
im2dShader->use();
|
||||
setAttribPointers(im2dattribDesc, 3);
|
||||
|
||||
glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform);
|
||||
|
||||
flushCache();
|
||||
glDrawArrays(primTypeMap[primType], 0, numVertices);
|
||||
disableAttribPointers(im2dattribDesc, 3);
|
||||
}
|
||||
|
||||
void
|
||||
im2DRenderIndexedPrimitive(PrimitiveType primType,
|
||||
void *vertices, int32 numVertices,
|
||||
|
||||
@@ -96,9 +96,15 @@ struct Im3DVertex
|
||||
void setZ(float32 z) { this->position.z = z; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
void setU(float32 u) { this->u = u; }
|
||||
void setV(float32 v) { this->v = v; }
|
||||
|
||||
float getX(void) { return this->position.x; }
|
||||
float getY(void) { return this->position.y; }
|
||||
float getZ(void) { return this->position.z; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
struct Im2DVertex
|
||||
@@ -116,6 +122,14 @@ struct Im2DVertex
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
void setU(float32 u, float recipz) { this->u = u; }
|
||||
void setV(float32 v, float recipz) { this->v = v; }
|
||||
|
||||
float getScreenX(void) { return this->x; }
|
||||
float getScreenY(void) { return this->y; }
|
||||
float getScreenZ(void) { return this->z; }
|
||||
float getCameraZ(void) { return this->w; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
void setAttribPointers(AttribDesc *attribDescs, int32 numAttribs);
|
||||
|
||||
@@ -6,6 +6,12 @@ namespace gl3 {
|
||||
extern uint32 im2DVbo, im2DIbo;
|
||||
void openIm2D(void);
|
||||
void closeIm2D(void);
|
||||
void im2DRenderLine(void *vertices, int32 numVertices,
|
||||
int32 vert1, int32 vert2);
|
||||
void im2DRenderTriangle(void *vertices, int32 numVertices,
|
||||
int32 vert1, int32 vert2, int32 vert3);
|
||||
void im2DRenderPrimitive(PrimitiveType primType,
|
||||
void *vertices, int32 numVertices);
|
||||
void im2DRenderIndexedPrimitive(PrimitiveType primType,
|
||||
void *vertices, int32 numVertices, void *indices, int32 numIndices);
|
||||
|
||||
|
||||
@@ -1454,7 +1454,7 @@ unswizzle16to4(uint8 *dst, uint8 *src, int32 w, int32 h)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
expandPSMT4(uint8 *dst, uint8 *src, int32 w, int32 h, int32 srcw)
|
||||
{
|
||||
int32 x, y;
|
||||
@@ -1465,7 +1465,7 @@ expandPSMT4(uint8 *dst, uint8 *src, int32 w, int32 h, int32 srcw)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
copyPSMT8(uint8 *dst, uint8 *src, int32 w, int32 h, int32 srcw)
|
||||
{
|
||||
int32 x, y;
|
||||
@@ -1620,7 +1620,7 @@ createNativeRaster(void *object, int32 offset, int32)
|
||||
Ps2Raster *raster = PLUGINOFFSET(Ps2Raster, object, offset);
|
||||
raster->tex0 = 0;
|
||||
raster->paletteBase = 0;
|
||||
raster->kl = 0xFC0;
|
||||
raster->kl = defaultMipMapKL;
|
||||
raster->tex1low = 0;
|
||||
raster->unk2 = 0;
|
||||
raster->miptbp1 = 0;
|
||||
@@ -1668,8 +1668,10 @@ static Stream*
|
||||
writeMipmap(Stream *stream, int32, void *object, int32 offset, int32)
|
||||
{
|
||||
Texture *tex = (Texture*)object;
|
||||
if(tex->raster)
|
||||
return nil;
|
||||
if(tex->raster){
|
||||
stream->writeI32(defaultMipMapKL);
|
||||
return stream;
|
||||
}
|
||||
Ps2Raster *raster = PLUGINOFFSET(Ps2Raster, tex->raster, offset);
|
||||
stream->writeI32(raster->kl);
|
||||
return stream;
|
||||
@@ -1873,6 +1875,10 @@ streamExt.mipmapVal);
|
||||
calcTEX1(raster, &tex1, tex->filterAddressing & 0xF);
|
||||
// printTEX1(tex1);
|
||||
|
||||
// TODO: GTA SA LD_OTB.txd loses here
|
||||
assert(natras->pixelSize >= streamExt.pixelSize);
|
||||
assert(natras->paletteSize >= streamExt.paletteSize);
|
||||
|
||||
natras->tex0 = streamExt.tex0;
|
||||
natras->paletteBase = streamExt.paletteOffset;
|
||||
natras->tex1low = streamExt.tex1low;
|
||||
|
||||
@@ -220,5 +220,8 @@ Texture *readNativeTexture(Stream *stream);
|
||||
void writeNativeTexture(Texture *tex, Stream *stream);
|
||||
uint32 getSizeNativeTexture(Texture *tex);
|
||||
|
||||
void expandPSMT4(uint8 *dst, uint8 *src, int32 w, int32 h, int32 srcw);
|
||||
void copyPSMT8(uint8 *dst, uint8 *src, int32 w, int32 h, int32 srcw);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,25 @@ namespace im2d {
|
||||
float32 GetNearZ(void) { return engine->device.zNear; }
|
||||
float32 GetFarZ(void) { return engine->device.zFar; }
|
||||
void
|
||||
RenderLine(void *verts, int32 numVerts, int32 vert1, int32 vert2)
|
||||
{
|
||||
engine->device.im2DRenderLine(verts, numVerts, vert1, vert2);
|
||||
}
|
||||
void
|
||||
RenderTriangle(void *verts, int32 numVerts, int32 vert1, int32 vert2, int32 vert3)
|
||||
{
|
||||
engine->device.im2DRenderTriangle(verts, numVerts, vert1, vert2, vert3);
|
||||
}
|
||||
void
|
||||
RenderIndexedPrimitive(PrimitiveType type, void *verts, int32 numVerts, void *indices, int32 numIndices)
|
||||
{
|
||||
engine->device.im2DRenderIndexedPrimitive(type, verts, numVerts, indices, numIndices);
|
||||
}
|
||||
void
|
||||
RenderPrimitive(PrimitiveType type, void *verts, int32 numVerts)
|
||||
{
|
||||
engine->device.im2DRenderPrimitive(type, verts, numVerts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,10 @@ struct Device
|
||||
void (*setRenderState)(int32 state, void *value);
|
||||
void *(*getRenderState)(int32 state);
|
||||
|
||||
// TODO: render line
|
||||
// TODO: render triangle
|
||||
// TODO: render primitive
|
||||
void (*im2DRenderLine)(void*, int32, int32, int32);
|
||||
void (*im2DRenderTriangle)(void*, int32, int32, int32, int32);
|
||||
void (*im2DRenderPrimitive)(PrimitiveType,
|
||||
void*, int32);
|
||||
void (*im2DRenderIndexedPrimitive)(PrimitiveType,
|
||||
void*, int32, void*, int32);
|
||||
|
||||
@@ -163,6 +164,9 @@ namespace null {
|
||||
void rasterFromImage(Raster*, Image*);
|
||||
Image *rasterToImage(Raster*);
|
||||
|
||||
void im2DRenderLine(void*, int32, int32, int32);
|
||||
void im2DRenderTriangle(void*, int32, int32, int32, int32);
|
||||
void im2DRenderPrimitive(PrimitiveType, void*, int32);
|
||||
void im2DRenderIndexedPrimitive(PrimitiveType,
|
||||
void*, int32, void*, int32);
|
||||
|
||||
|
||||
@@ -68,7 +68,10 @@ namespace im2d {
|
||||
|
||||
float32 GetNearZ(void);
|
||||
float32 GetFarZ(void);
|
||||
void RenderLine(void *verts, int32 numVerts, int32 vert1, int32 vert2);
|
||||
void RenderTriangle(void *verts, int32 numVerts, int32 vert1, int32 vert2, int32 vert3);
|
||||
void RenderIndexedPrimitive(PrimitiveType, void *verts, int32 numVerts, void *indices, int32 numIndices);
|
||||
void RenderPrimitive(PrimitiveType type, void *verts, int32 numVerts);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user