implemented im3d for gl3 and d3d

This commit is contained in:
aap
2017-08-29 10:12:56 +02:00
parent b7f643a632
commit d00ab2f526
41 changed files with 1447 additions and 761 deletions

View File

@ -43,7 +43,7 @@ printScreen(const char *s, float32 x, float32 y)
vert->setScreenX(x);
vert->setScreenY(y);
vert->setScreenZ(rw::GetNearZ());
vert->setScreenZ(rw::im2d::GetNearZ());
vert->setCameraZ(cam->nearPlane);
vert->setRecipCameraZ(1.0f/cam->nearPlane);
vert->setColor(255, 255, 255, 255);
@ -53,7 +53,7 @@ printScreen(const char *s, float32 x, float32 y)
vert->setScreenX(x+curfont->glyphwidth);
vert->setScreenY(y);
vert->setScreenZ(rw::GetNearZ());
vert->setScreenZ(rw::im2d::GetNearZ());
vert->setCameraZ(cam->nearPlane);
vert->setRecipCameraZ(1.0f/cam->nearPlane);
vert->setColor(255, 255, 255, 255);
@ -63,7 +63,7 @@ printScreen(const char *s, float32 x, float32 y)
vert->setScreenX(x);
vert->setScreenY(y+curfont->glyphheight);
vert->setScreenZ(rw::GetNearZ());
vert->setScreenZ(rw::im2d::GetNearZ());
vert->setCameraZ(cam->nearPlane);
vert->setRecipCameraZ(1.0f/cam->nearPlane);
vert->setColor(255, 255, 255, 255);
@ -73,7 +73,7 @@ printScreen(const char *s, float32 x, float32 y)
vert->setScreenX(x+curfont->glyphwidth);
vert->setScreenY(y+curfont->glyphheight);
vert->setScreenZ(rw::GetNearZ());
vert->setScreenZ(rw::im2d::GetNearZ());
vert->setCameraZ(cam->nearPlane);
vert->setRecipCameraZ(1.0f/cam->nearPlane);
vert->setColor(255, 255, 255, 255);
@ -95,7 +95,7 @@ printScreen(const char *s, float32 x, float32 y)
s++;
}
engine->imtexture = curfont->tex;
rw::engine->device.im2DRenderIndexedPrimitive(rw::PRIMTYPETRILIST,
im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
vertices, curVert, indices, curIndex);
}

View File

@ -14,6 +14,9 @@ rw::Texture *tex;
rw::EngineStartParams engineStartParams;
void tlTest(rw::Clump *clump);
void genIm3DTransform(void *vertices, rw::int32 numVertices, rw::Matrix *xform);
void genIm3DRenderIndexed(rw::PrimitiveType prim, void *indices, rw::int32 numIndices);
void genIm3DEnd(void);
void initFont(void);
void printScreen(const char *s, float x, float y);
@ -241,7 +244,7 @@ im2dtest(void)
{ 0.0f, 480.0f, 0, 0, 255, 128, 0.0f, 1.0f },
{ 640.0f, 480.0f, 0, 255, 255, 128, 1.0f, 1.0f },
};
static Im2DVertex verts[4];
Im2DVertex verts[4];
static short indices[] = {
0, 1, 2, 3
};
@ -249,7 +252,7 @@ im2dtest(void)
for(i = 0; i < 4; i++){
verts[i].setScreenX(vs[i].x);
verts[i].setScreenY(vs[i].y);
verts[i].setScreenZ(rw::GetNearZ());
verts[i].setScreenZ(rw::im2d::GetNearZ());
verts[i].setCameraZ(Scene.camera->nearPlane);
verts[i].setRecipCameraZ(1.0f/Scene.camera->nearPlane);
verts[i].setColor(vs[i].r, vs[i].g, vs[i].b, vs[i].a);
@ -259,10 +262,58 @@ im2dtest(void)
rw::engine->imtexture = tex;
rw::SetRenderState(rw::VERTEXALPHA, 1);
rw::engine->device.im2DRenderIndexedPrimitive(rw::PRIMTYPETRISTRIP,
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRISTRIP,
&verts, 4, &indices, 4);
}
void
im3dtest(void)
{
using namespace rw::RWDEVICE;
int i;
static struct
{
float x, y, z;
rw::uint8 r, g, b, a;
float u, v;
} vs[8] = {
{ -1.0f, -1.0f, -1.0f, 255, 0, 0, 128, 0.0f, 0.0f },
{ -1.0f, 1.0f, -1.0f, 0, 255, 0, 128, 0.0f, 1.0f },
{ 1.0f, -1.0f, -1.0f, 0, 0, 255, 128, 1.0f, 0.0f },
{ 1.0f, 1.0f, -1.0f, 255, 0, 255, 128, 1.0f, 1.0f },
{ -1.0f, -1.0f, 1.0f, 255, 0, 0, 128, 0.0f, 0.0f },
{ -1.0f, 1.0f, 1.0f, 0, 255, 0, 128, 0.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f, 0, 0, 255, 128, 1.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 255, 0, 255, 128, 1.0f, 1.0f },
};
Im3DVertex verts[8];
static short indices[2*6] = {
0, 1, 2, 2, 1, 3,
4, 5, 6, 6, 5, 7
};
for(i = 0; i < 8; i++){
verts[i].setX(vs[i].x);
verts[i].setY(vs[i].y);
verts[i].setZ(vs[i].z);
verts[i].setColor(vs[i].r, vs[i].g, vs[i].b, vs[i].a);
verts[i].setU(vs[i].u);
verts[i].setV(vs[i].v);
}
rw::engine->imtexture = tex;
/*
genIm3DTransform(verts, 8, nil);
genIm3DRenderIndexed(rw::PRIMTYPETRILIST, indices, 12);
genIm3DEnd();
*/
rw::im3d::Transform(verts, 8, nil);
rw::im3d::RenderIndexed(rw::PRIMTYPETRILIST, indices, 12);
rw::im3d::End();
}
void
Draw(float timeDelta)
{
@ -271,9 +322,10 @@ Draw(float timeDelta)
camera->update();
camera->m_rwcam->beginUpdate();
Scene.clump->render();
im2dtest();
// Scene.clump->render();
// im2dtest();
// tlTest(Scene.clump);
im3dtest();
printScreen("Hello, World!", 10, 10);
camera->m_rwcam->endUpdate();

View File

@ -5,6 +5,7 @@ using namespace rw;
//
// This is a test to implement T&L in software and render with Im2D
//
#define MAX_LIGHTS 8
@ -90,7 +91,7 @@ drawAtomic(Atomic *a)
im2dverts[i].setV(texcoords[i].v);
}
for(int32 i = 0; i < mh->numMeshes; i++){
for(int32 j = 0; j < m[i].numIndices; j++){
for(uint32 j = 0; j < m[i].numIndices; j++){
int32 idx = m[i].indices[j];
RGBA col;
RGBAf colf, color;
@ -116,7 +117,7 @@ drawAtomic(Atomic *a)
}
engine->imtexture = m[i].material->texture;
rw::engine->device.im2DRenderIndexedPrimitive(rw::PRIMTYPETRILIST,
im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
im2dverts, g->numVertices, m[i].indices, m[i].numIndices);
}
@ -132,3 +133,60 @@ tlTest(Clump *clump)
drawAtomic(a);
}
}
static RWDEVICE::Im2DVertex *clipverts;
static int32 numClipverts;
void
genIm3DTransform(void *vertices, int32 numVertices, Matrix *world)
{
using namespace RWDEVICE;
Im3DVertex *objverts;
V3d pos;
Matrix xform;
Camera *cam;
int32 i;
objverts = (Im3DVertex*)vertices;
cam = (Camera*)engine->currentCamera;
int32 width = cam->frameBuffer->width;
int32 height = cam->frameBuffer->height;
xform = cam->viewMatrix;
if(world)
xform.transform(world, COMBINEPRECONCAT);
clipverts = rwNewT(Im2DVertex, numVertices, MEMDUR_EVENT);
numClipverts = numVertices;
for(i = 0; i < numVertices; i++){
V3d::transformPoints(&pos, &objverts[i].position, 1, &xform);
float32 recipZ = 1.0f/pos.z;
RGBA c = objverts[i].getColor();
clipverts[i].setScreenX(pos.x * recipZ * width);
clipverts[i].setScreenY((pos.y * recipZ * height));
clipverts[i].setScreenZ(recipZ * cam->zScale + cam->zShift);
clipverts[i].setCameraZ(pos.z);
clipverts[i].setRecipCameraZ(recipZ);
clipverts[i].setColor(c.red, c.green, c.blue, c.alpha);
clipverts[i].setU(objverts[i].u);
clipverts[i].setV(objverts[i].v);
}
}
void
genIm3DRenderIndexed(PrimitiveType prim, void *indices, int32 numIndices)
{
im2d::RenderIndexedPrimitive(prim, clipverts, numClipverts, indices, numIndices);
}
void
genIm3DEnd(void)
{
rwFree(clipverts);
clipverts = nil;
numClipverts = 0;
}