fixed sky mipmap stream write; experimented with software pipeline

This commit is contained in:
aap
2018-12-17 21:23:41 +01:00
parent b1c3c1dca8
commit c62c1464d7
19 changed files with 1817 additions and 231 deletions

View File

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

View File

@@ -1064,6 +1064,9 @@ Device renderdevice = {
d3d::showRaster,
d3d::setRwRenderState,
d3d::getRwRenderState,
d3d::im2DRenderLine,
d3d::im2DRenderTriangle,
d3d::im2DRenderPrimitive,
d3d::im2DRenderIndexedPrimitive,
d3d::im3DTransform,
d3d::im3DRenderIndexed,

View File

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

View File

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

View File

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