using proper types
This commit is contained in:
parent
9a26a380a8
commit
4653f7e81e
@ -378,7 +378,7 @@ defaultInstanceCB(Geometry *geo, InstanceData *inst)
|
||||
}
|
||||
|
||||
for(int32 i = 0; i < geo->numTexCoordSets; i++){
|
||||
instV2d(VERT_FLOAT2, dst, &geo->texCoords[i][2*inst->minVert],
|
||||
instTexCoords(VERT_FLOAT2, dst, &geo->texCoords[i][2*inst->minVert],
|
||||
inst->numVertices, inst->stride);
|
||||
dst += 8;
|
||||
}
|
||||
@ -409,7 +409,7 @@ defaultUninstanceCB(Geometry *geo, InstanceData *inst)
|
||||
}
|
||||
|
||||
for(int32 i = 0; i < geo->numTexCoordSets; i++){
|
||||
uninstV2d(VERT_FLOAT2, &geo->texCoords[i][2*inst->minVert], src,
|
||||
uninstTexCoords(VERT_FLOAT2, &geo->texCoords[i][2*inst->minVert], src,
|
||||
inst->numVertices, inst->stride);
|
||||
src += 8;
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
for(int32 n = 0; n < geo->numTexCoordSets; n++){
|
||||
for(i = 0; dcl[i].usage != D3DDECLUSAGE_TEXCOORD || dcl[i].usageIndex != n; i++)
|
||||
;
|
||||
instV2d(vertFormatMap[dcl[i].type], verts + dcl[i].offset,
|
||||
instTexCoords(vertFormatMap[dcl[i].type], verts + dcl[i].offset,
|
||||
geo->texCoords[n],
|
||||
header->totalNumVertex,
|
||||
header->vertexStream[dcl[i].stream].stride);
|
||||
@ -554,7 +554,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
for(int32 n = 0; n < geo->numTexCoordSets; n++){
|
||||
for(i = 0; dcl[i].usage != D3DDECLUSAGE_TEXCOORD || dcl[i].usageIndex != n; i++)
|
||||
;
|
||||
uninstV2d(vertFormatMap[dcl[i].type],
|
||||
uninstTexCoords(vertFormatMap[dcl[i].type],
|
||||
geo->texCoords[n],
|
||||
verts[dcl[i].stream] + dcl[i].offset,
|
||||
header->totalNumVertex,
|
||||
|
@ -321,7 +321,7 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
sel = (fmt >> (i*4 + 8)) & 0xF;
|
||||
if(sel == 0)
|
||||
break;
|
||||
instV2d(v2dFormatMap[sel], dst, geo->texCoords[i],
|
||||
instTexCoords(v2dFormatMap[sel], dst, geo->texCoords[i],
|
||||
header->numVertices, header->stride);
|
||||
dst += sel == 4 ? 4 : 2*vertexFormatSizes[sel];
|
||||
}
|
||||
@ -360,7 +360,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
sel = (fmt >> (i*4 + 8)) & 0xF;
|
||||
if(sel == 0)
|
||||
break;
|
||||
uninstV2d(v2dFormatMap[sel], geo->texCoords[i], src,
|
||||
uninstTexCoords(v2dFormatMap[sel], geo->texCoords[i], src,
|
||||
header->numVertices, header->stride);
|
||||
src += sel == 4 ? 4 : 2*vertexFormatSizes[sel];
|
||||
}
|
||||
|
@ -40,11 +40,11 @@ Geometry::create(int32 numVerts, int32 numTris, uint32 flags)
|
||||
geo->triangles = nil;
|
||||
if(!(geo->flags & NATIVE) && geo->numVertices){
|
||||
if(geo->flags & PRELIT)
|
||||
geo->colors = new uint8[4*geo->numVertices];
|
||||
geo->colors = new RGBA[geo->numVertices];
|
||||
if((geo->flags & TEXTURED) || (geo->flags & TEXTURED2))
|
||||
for(int32 i = 0; i < geo->numTexCoordSets; i++)
|
||||
geo->texCoords[i] =
|
||||
new float32[2*geo->numVertices];
|
||||
new TexCoords[geo->numVertices];
|
||||
geo->triangles = new Triangle[geo->numTriangles];
|
||||
}
|
||||
geo->morphTargets = new MorphTarget[1];
|
||||
@ -54,9 +54,9 @@ Geometry::create(int32 numVerts, int32 numTris, uint32 flags)
|
||||
m->vertices = nil;
|
||||
m->normals = nil;
|
||||
if(!(geo->flags & NATIVE) && geo->numVertices){
|
||||
m->vertices = new float32[3*geo->numVertices];
|
||||
m->vertices = new V3d[geo->numVertices];
|
||||
if(geo->flags & NORMALS)
|
||||
m->normals = new float32[3*geo->numVertices];
|
||||
m->normals = new V3d[geo->numVertices];
|
||||
}
|
||||
geo->matList.init();
|
||||
geo->meshHeader = nil;
|
||||
@ -275,9 +275,9 @@ Geometry::addMorphTargets(int32 n)
|
||||
m->vertices = nil;
|
||||
m->normals = nil;
|
||||
if(!(this->flags & NATIVE)){
|
||||
m->vertices = new float32[3*this->numVertices];
|
||||
m->vertices = new V3d[this->numVertices];
|
||||
if(this->flags & NORMALS)
|
||||
m->normals = new float32[3*this->numVertices];
|
||||
m->normals = new V3d[this->numVertices];
|
||||
}
|
||||
}
|
||||
this->numMorphTargets += n;
|
||||
@ -290,15 +290,15 @@ Geometry::calculateBoundingSphere(void)
|
||||
MorphTarget *m = &this->morphTargets[i];
|
||||
V3d min { 1000000.0f, 1000000.0f, 1000000.0f };
|
||||
V3d max { -1000000.0f, -1000000.0f, -1000000.0f };
|
||||
float32 *v = m->vertices;
|
||||
V3d *v = m->vertices;
|
||||
for(int32 j = 0; j < this->numVertices; j++){
|
||||
if(v[0] > max.x) max.x = v[0];
|
||||
if(v[0] < min.x) min.x = v[0];
|
||||
if(v[1] > max.y) max.y = v[1];
|
||||
if(v[1] < min.y) min.y = v[1];
|
||||
if(v[2] > max.z) max.z = v[2];
|
||||
if(v[2] < min.z) min.z = v[2];
|
||||
v += 3;
|
||||
if(v->x > max.x) max.x = v->x;
|
||||
if(v->x < min.x) min.x = v->x;
|
||||
if(v->y > max.y) max.y = v->y;
|
||||
if(v->y < min.y) min.y = v->y;
|
||||
if(v->z > max.z) max.z = v->z;
|
||||
if(v->z < min.z) min.z = v->z;
|
||||
v++;
|
||||
}
|
||||
m->boundingSphere.center = scale(add(min, max), 1/2.0f);
|
||||
max = sub(max, m->boundingSphere.center);
|
||||
@ -322,15 +322,15 @@ void
|
||||
Geometry::allocateData(void)
|
||||
{
|
||||
if(this->flags & PRELIT)
|
||||
this->colors = new uint8[4*this->numVertices];
|
||||
this->colors = new RGBA[this->numVertices];
|
||||
if((this->flags & TEXTURED) || (this->flags & TEXTURED2))
|
||||
for(int32 i = 0; i < this->numTexCoordSets; i++)
|
||||
this->texCoords[i] =
|
||||
new float32[2*this->numVertices];
|
||||
new TexCoords[this->numVertices];
|
||||
MorphTarget *m = this->morphTargets;
|
||||
m->vertices = new float32[3*this->numVertices];
|
||||
m->vertices = new V3d[this->numVertices];
|
||||
if(this->flags & NORMALS)
|
||||
m->normals = new float32[3*this->numVertices];
|
||||
m->normals = new V3d[this->numVertices];
|
||||
// TODO: morph targets (who cares anyway?)
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
for(int32 n = 0; n < geo->numTexCoordSets; n++){
|
||||
for(a = attribs; a->index != ATTRIB_TEXCOORDS0+n; a++)
|
||||
;
|
||||
instV2d(VERT_FLOAT2, verts + a->offset,
|
||||
instTexCoords(VERT_FLOAT2, verts + a->offset,
|
||||
geo->texCoords[n],
|
||||
header->totalNumVertex, a->stride);
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ skinInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
for(int32 n = 0; n < geo->numTexCoordSets; n++){
|
||||
for(a = attribs; a->index != ATTRIB_TEXCOORDS0+n; a++)
|
||||
;
|
||||
instV2d(VERT_FLOAT2, verts + a->offset,
|
||||
instTexCoords(VERT_FLOAT2, verts + a->offset,
|
||||
geo->texCoords[n],
|
||||
header->totalNumVertex, a->stride);
|
||||
}
|
||||
@ -390,8 +390,9 @@ skinInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
// Weights
|
||||
for(a = attribs; a->index != ATTRIB_WEIGHTS; a++)
|
||||
;
|
||||
float *w = skin->weights;
|
||||
instV4d(VERT_FLOAT4, verts + a->offset,
|
||||
skin->weights,
|
||||
(V4d*)w,
|
||||
header->totalNumVertex, a->stride);
|
||||
|
||||
// Indices
|
||||
@ -399,7 +400,7 @@ skinInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
||||
;
|
||||
// not really colors of course but what the heck
|
||||
instColor(VERT_RGBA, verts + a->offset,
|
||||
skin->indices,
|
||||
(RGBA*)skin->indices,
|
||||
header->totalNumVertex, a->stride);
|
||||
|
||||
glGenBuffers(1, &header->vbo);
|
||||
|
@ -395,20 +395,20 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
||||
a[i].stride = offset;
|
||||
|
||||
uint8 *p = header->data + a->offset;
|
||||
float32 *vert = geo->morphTargets->vertices;
|
||||
V3d *vert = geo->morphTargets->vertices;
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
packattrib(p, vert, a);
|
||||
vert += 3;
|
||||
packattrib(p, (float32*)vert, a);
|
||||
vert++;
|
||||
p += a->stride;
|
||||
}
|
||||
a++;
|
||||
|
||||
if(geo->numTexCoordSets){
|
||||
p = header->data + a->offset;
|
||||
float32 *texcoord = geo->texCoords[0];
|
||||
TexCoords *texcoord = geo->texCoords[0];
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
packattrib(p, texcoord, a, 512.0f);
|
||||
texcoord += 2;
|
||||
packattrib(p, (float32*)texcoord, a, 512.0f);
|
||||
texcoord++;
|
||||
p += a->stride;
|
||||
}
|
||||
a++;
|
||||
@ -416,10 +416,10 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
||||
|
||||
if(geo->flags & Geometry::NORMALS){
|
||||
p = header->data + a->offset;
|
||||
float32 *norm = geo->morphTargets->normals;
|
||||
V3d *norm = geo->morphTargets->normals;
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
packattrib(p, norm, a);
|
||||
norm += 3;
|
||||
packattrib(p, (float32*)norm, a);
|
||||
norm++;
|
||||
p += a->stride;
|
||||
}
|
||||
a++;
|
||||
@ -428,15 +428,15 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
||||
if(geo->flags & Geometry::PRELIT){
|
||||
// TODO: this seems too complicated
|
||||
p = header->data + a->offset;
|
||||
uint8 *color = geo->colors;
|
||||
RGBA *color = geo->colors;
|
||||
float32 f[4];
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
f[0] = color[0]/255.0f;
|
||||
f[1] = color[1]/255.0f;
|
||||
f[2] = color[2]/255.0f;
|
||||
f[3] = color[3]/255.0f;
|
||||
packattrib(p, f, a);
|
||||
color += 4;
|
||||
f[0] = color->red/255.0f;
|
||||
f[1] = color->green/255.0f;
|
||||
f[2] = color->blue/255.0f;
|
||||
f[3] = color->alpha/255.0f;
|
||||
packattrib(p, (float32*)f, a);
|
||||
color++;
|
||||
p += a->stride;
|
||||
}
|
||||
a++;
|
||||
@ -457,10 +457,10 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
||||
geo->allocateData();
|
||||
|
||||
uint8 *p;
|
||||
float32 *texcoord = geo->texCoords[0];
|
||||
uint8 *color = geo->colors;
|
||||
float32 *vert = geo->morphTargets->vertices;
|
||||
float32 *norm = geo->morphTargets->normals;
|
||||
TexCoords *texcoord = geo->texCoords[0];
|
||||
RGBA *color = geo->colors;
|
||||
V3d *vert = geo->morphTargets->vertices;
|
||||
V3d *norm = geo->morphTargets->normals;
|
||||
float32 f[4];
|
||||
|
||||
InstanceDataHeader *header = (InstanceDataHeader*)geo->instData;
|
||||
@ -471,24 +471,24 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
||||
switch(a->index){
|
||||
case 0: // Vertices
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
unpackattrib(vert, p, a);
|
||||
vert += 3;
|
||||
unpackattrib((float32*)vert, p, a);
|
||||
vert++;
|
||||
p += a->stride;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: // texCoords
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
unpackattrib(texcoord, p, a, 512.0f);
|
||||
texcoord += 2;
|
||||
unpackattrib((float32*)texcoord, p, a, 512.0f);
|
||||
texcoord++;
|
||||
p += a->stride;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // normals
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
unpackattrib(norm, p, a);
|
||||
norm += 3;
|
||||
unpackattrib((float32*)norm, p, a);
|
||||
norm++;
|
||||
p += a->stride;
|
||||
}
|
||||
break;
|
||||
@ -497,11 +497,11 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
||||
for(int32 i = 0; i < geo->numVertices; i++){
|
||||
// TODO: this seems too complicated
|
||||
unpackattrib(f, p, a);
|
||||
color[0] = f[0]*255.0f;
|
||||
color[1] = f[1]*255.0f;
|
||||
color[2] = f[2]*255.0f;
|
||||
color[3] = f[3]*255.0f;
|
||||
color += 4;
|
||||
color->red = f[0]*255.0f;
|
||||
color->green = f[1]*255.0f;
|
||||
color->blue = f[2]*255.0f;
|
||||
color->alpha = f[3]*255.0f;
|
||||
color++;
|
||||
p += a->stride;
|
||||
}
|
||||
break;
|
||||
|
@ -52,48 +52,48 @@ findMinVertAndNumVertices(uint16 *indices, uint32 numIndices, uint32 *minVert, i
|
||||
}
|
||||
|
||||
void
|
||||
instV4d(int type, uint8 *dst, float *src, uint32 numVertices, uint32 stride)
|
||||
instV4d(int type, uint8 *dst, V4d *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
if(type == VERT_FLOAT4)
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
memcpy(dst, src, 16);
|
||||
dst += stride;
|
||||
src += 4;
|
||||
src++;
|
||||
}
|
||||
else
|
||||
assert(0 && "unsupported instV3d type");
|
||||
assert(0 && "unsupported instV4d type");
|
||||
}
|
||||
|
||||
void
|
||||
instV3d(int type, uint8 *dst, float *src, uint32 numVertices, uint32 stride)
|
||||
instV3d(int type, uint8 *dst, V3d *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
if(type == VERT_FLOAT3)
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
memcpy(dst, src, 12);
|
||||
dst += stride;
|
||||
src += 3;
|
||||
src++;
|
||||
}
|
||||
else if(type == VERT_COMPNORM)
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
uint32 n = ((((uint32)(src[2] * 511.0f)) & 0x3ff) << 22) |
|
||||
((((uint32)(src[1] * 1023.0f)) & 0x7ff) << 11) |
|
||||
((((uint32)(src[0] * 1023.0f)) & 0x7ff) << 0);
|
||||
uint32 n = ((((uint32)(src->z * 511.0f)) & 0x3ff) << 22) |
|
||||
((((uint32)(src->y * 1023.0f)) & 0x7ff) << 11) |
|
||||
((((uint32)(src->x * 1023.0f)) & 0x7ff) << 0);
|
||||
*(uint32*)dst = n;
|
||||
dst += stride;
|
||||
src += 3;
|
||||
src++;
|
||||
}
|
||||
else
|
||||
assert(0 && "unsupported instV3d type");
|
||||
}
|
||||
|
||||
void
|
||||
uninstV3d(int type, float *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
uninstV3d(int type, V3d *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
if(type == VERT_FLOAT3)
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
memcpy(dst, src, 12);
|
||||
src += stride;
|
||||
dst += 3;
|
||||
dst++;
|
||||
}
|
||||
else if(type == VERT_COMPNORM)
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
@ -106,63 +106,63 @@ uninstV3d(int type, float *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
if(normal[0] & 0x400) normal[0] |= ~0x7FF;
|
||||
if(normal[1] & 0x400) normal[1] |= ~0x7FF;
|
||||
if(normal[2] & 0x200) normal[2] |= ~0x3FF;
|
||||
dst[0] = normal[0] / 1023.0f;
|
||||
dst[1] = normal[1] / 1023.0f;
|
||||
dst[2] = normal[2] / 511.0f;
|
||||
dst->x = normal[0] / 1023.0f;
|
||||
dst->y = normal[1] / 1023.0f;
|
||||
dst->z = normal[2] / 511.0f;
|
||||
src += stride;
|
||||
dst += 3;
|
||||
dst++;
|
||||
}
|
||||
else
|
||||
assert(0 && "unsupported uninstV3d type");
|
||||
}
|
||||
|
||||
void
|
||||
instV2d(int type, uint8 *dst, float *src, uint32 numVertices, uint32 stride)
|
||||
instTexCoords(int type, uint8 *dst, TexCoords *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
assert(type == VERT_FLOAT2);
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
memcpy(dst, src, 8);
|
||||
dst += stride;
|
||||
src += 2;
|
||||
src++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
uninstV2d(int type, float *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
uninstTexCoords(int type, TexCoords *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
assert(type == VERT_FLOAT2);
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
memcpy(dst, src, 8);
|
||||
src += stride;
|
||||
dst += 2;
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
bool32
|
||||
instColor(int type, uint8 *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
bool32 hasAlpha = 0;
|
||||
if(type == VERT_ARGB){
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
dst[3] = src[3];
|
||||
dst[0] = src->blue;
|
||||
dst[1] = src->green;
|
||||
dst[2] = src->red;
|
||||
dst[3] = src->alpha;
|
||||
if(dst[3] != 0xFF)
|
||||
hasAlpha = 1;
|
||||
dst += stride;
|
||||
src += 4;
|
||||
src++;
|
||||
}
|
||||
}else if(type == VERT_RGBA){
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = src[3];
|
||||
dst[0] = src->red;
|
||||
dst[1] = src->green;
|
||||
dst[2] = src->blue;
|
||||
dst[3] = src->alpha;
|
||||
if(dst[3] != 0xFF)
|
||||
hasAlpha = 1;
|
||||
dst += stride;
|
||||
src += 4;
|
||||
src++;
|
||||
}
|
||||
}else
|
||||
assert(0 && "unsupported color type");
|
||||
@ -170,16 +170,16 @@ instColor(int type, uint8 *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
}
|
||||
|
||||
void
|
||||
uninstColor(int type, uint8 *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
uninstColor(int type, RGBA *dst, uint8 *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
assert(type == VERT_ARGB);
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
dst[3] = src[3];
|
||||
dst->red = src[2];
|
||||
dst->green = src[1];
|
||||
dst->blue = src[0];
|
||||
dst->alpha = src[3];
|
||||
src += stride;
|
||||
dst += 4;
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,14 +400,14 @@ uint32*
|
||||
instanceNormal(uint32 *wp, Geometry *g, Mesh *m, uint32 idx, uint32 n)
|
||||
{
|
||||
uint16 j;
|
||||
float *d = g->morphTargets[0].normals;
|
||||
V3d *d = g->morphTargets[0].normals;
|
||||
uint8 *p = (uint8*)wp;
|
||||
if((g->flags & Geometry::NORMALS))
|
||||
for(uint32 i = idx; i < idx+n; i++){
|
||||
j = m->indices[i];
|
||||
*p++ = d[j*3+0]*127.0f;
|
||||
*p++ = d[j*3+1]*127.0f;
|
||||
*p++ = d[j*3+2]*127.0f;
|
||||
*p++ = d[j].x*127.0f;
|
||||
*p++ = d[j].y*127.0f;
|
||||
*p++ = d[j].z*127.0f;
|
||||
}
|
||||
else
|
||||
for(uint32 i = idx; i < idx+n; i++){
|
||||
@ -872,57 +872,19 @@ ObjPipeline::ObjPipeline(uint32 platform)
|
||||
this->impl.uninstance = objUninstance;
|
||||
}
|
||||
|
||||
/*
|
||||
int32
|
||||
findVertex(Geometry *g, uint32 flags[], uint32 mask, Vertex *v)
|
||||
{
|
||||
float32 *verts = g->morphTargets[0].vertices;
|
||||
float32 *tex = g->texCoords[0];
|
||||
float32 *tex1 = g->texCoords[1];
|
||||
float32 *norms = g->morphTargets[0].normals;
|
||||
uint8 *cols = g->colors;
|
||||
|
||||
for(int32 i = 0; i < g->numVertices; i++){
|
||||
if(mask & flags[i] & 0x1 &&
|
||||
!(verts[0] == v->p[0] && verts[1] == v->p[1] && verts[2] == v->p[2]))
|
||||
goto cont;
|
||||
if(mask & flags[i] & 0x10 &&
|
||||
!(norms[0] == v->n[0] && norms[1] == v->n[1] && norms[2] == v->n[2]))
|
||||
goto cont;
|
||||
if(mask & flags[i] & 0x100 &&
|
||||
!(cols[0] == v->c[0] && cols[1] == v->c[1] && cols[2] == v->c[2] && cols[3] == v->c[3]))
|
||||
goto cont;
|
||||
if(mask & flags[i] & 0x1000 &&
|
||||
!(tex[0] == v->t[0] && tex[1] == v->t[1]))
|
||||
goto cont;
|
||||
if(mask & flags[i] & 0x2000 &&
|
||||
!(tex1[0] == v->t1[0] && tex1[1] == v->t1[1]))
|
||||
goto cont;
|
||||
return i;
|
||||
cont:
|
||||
verts += 3;
|
||||
tex += 2;
|
||||
tex1 += 2;
|
||||
norms += 3;
|
||||
cols += 4;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
insertVertex(Geometry *geo, int32 i, uint32 mask, Vertex *v)
|
||||
{
|
||||
if(mask & 0x1)
|
||||
memcpy(&geo->morphTargets[0].vertices[i*3], v->p, 12);
|
||||
geo->morphTargets[0].vertices[i] = v->p;
|
||||
if(mask & 0x10)
|
||||
memcpy(&geo->morphTargets[0].normals[i*3], v->n, 12);
|
||||
geo->morphTargets[0].normals[i] = v->n;
|
||||
if(mask & 0x100)
|
||||
memcpy(&geo->colors[i*4], v->c, 4);
|
||||
geo->colors[i] = v->c;
|
||||
if(mask & 0x1000)
|
||||
memcpy(&geo->texCoords[0][i*2], v->t, 8);
|
||||
geo->texCoords[0][i] = v->t;
|
||||
if(mask & 0x2000)
|
||||
memcpy(&geo->texCoords[1][i*2], v->t1, 8);
|
||||
geo->texCoords[1][i] = v->t1;
|
||||
}
|
||||
|
||||
void
|
||||
@ -983,9 +945,9 @@ genericUninstanceCB(MatPipeline *pipe, Geometry *geo, uint32 flags[], Mesh *mesh
|
||||
memcpy(&v.p, xyz ? xyz : xyzw, 12);
|
||||
if(mask & 0x10){
|
||||
// TODO: figure out scaling :/
|
||||
v.n[0] = normals[0]/128.0f;
|
||||
v.n[1] = normals[1]/128.0f;
|
||||
v.n[2] = normals[2]/128.0f;
|
||||
v.n.x = normals[0]/128.0f;
|
||||
v.n.y = normals[1]/128.0f;
|
||||
v.n.z = normals[2]/128.0f;
|
||||
}
|
||||
if(mask & 0x100)
|
||||
memcpy(&v.c, rgba, 4);
|
||||
|
@ -202,28 +202,23 @@ findVertexSkin(Geometry *g, uint32 flags[], uint32 mask, Vertex *v)
|
||||
inds = skin->indices;
|
||||
}
|
||||
|
||||
float32 *verts = g->morphTargets[0].vertices;
|
||||
float32 *tex = g->texCoords[0];
|
||||
float32 *tex1 = g->texCoords[1];
|
||||
float32 *norms = g->morphTargets[0].normals;
|
||||
uint8 *cols = g->colors;
|
||||
V3d *verts = g->morphTargets[0].vertices;
|
||||
TexCoords *tex = g->texCoords[0];
|
||||
TexCoords *tex1 = g->texCoords[1];
|
||||
V3d *norms = g->morphTargets[0].normals;
|
||||
RGBA *cols = g->colors;
|
||||
|
||||
for(int32 i = 0; i < g->numVertices; i++){
|
||||
uint32 flag = flags ? flags[i] : ~0;
|
||||
if(mask & flag & 0x1 &&
|
||||
!(verts[0] == v->p[0] && verts[1] == v->p[1] && verts[2] == v->p[2]))
|
||||
if(mask & flag & 0x1 && !equal(*verts, v->p))
|
||||
goto cont;
|
||||
if(mask & flag & 0x10 &&
|
||||
!(norms[0] == v->n[0] && norms[1] == v->n[1] && norms[2] == v->n[2]))
|
||||
if(mask & flag & 0x10 && !equal(*norms, v->n))
|
||||
goto cont;
|
||||
if(mask & flag & 0x100 &&
|
||||
!(cols[0] == v->c[0] && cols[1] == v->c[1] && cols[2] == v->c[2] && cols[3] == v->c[3]))
|
||||
if(mask & flag & 0x100 && !equal(*cols, v->c))
|
||||
goto cont;
|
||||
if(mask & flag & 0x1000 &&
|
||||
!(tex[0] == v->t[0] && tex[1] == v->t[1]))
|
||||
if(mask & flag & 0x1000 && !equal(*tex, v->t))
|
||||
goto cont;
|
||||
if(mask & flag & 0x2000 &&
|
||||
!(tex1[0] == v->t1[0] && tex1[1] == v->t1[1]))
|
||||
if(mask & flag & 0x2000 && !equal(*tex1, v->t1))
|
||||
goto cont;
|
||||
if(mask & flag & 0x10000 &&
|
||||
!(wghts[0] == v->w[0] && wghts[1] == v->w[1] &&
|
||||
@ -233,10 +228,11 @@ findVertexSkin(Geometry *g, uint32 flags[], uint32 mask, Vertex *v)
|
||||
goto cont;
|
||||
return i;
|
||||
cont:
|
||||
verts += 3;
|
||||
tex += 2;
|
||||
norms += 3;
|
||||
cols += 4;
|
||||
verts++;
|
||||
tex++;
|
||||
tex1++;
|
||||
norms++;
|
||||
cols++;
|
||||
wghts += 4;
|
||||
inds += 4;
|
||||
}
|
||||
|
@ -121,11 +121,11 @@ public:
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
float32 p[3];
|
||||
float32 t[2];
|
||||
float32 t1[2];
|
||||
uint8 c[4];
|
||||
float32 n[3];
|
||||
V3d p;
|
||||
TexCoords t;
|
||||
TexCoords t1;
|
||||
RGBA c;
|
||||
V3d n;
|
||||
// skin
|
||||
float32 w[4];
|
||||
uint8 i[4];
|
||||
|
16
src/rwbase.h
16
src/rwbase.h
@ -55,6 +55,7 @@ struct RGBA
|
||||
uint8 blue;
|
||||
uint8 alpha;
|
||||
};
|
||||
inline bool32 equal(const RGBA &c1, const RGBA &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
||||
|
||||
struct RGBAf
|
||||
{
|
||||
@ -63,6 +64,7 @@ struct RGBAf
|
||||
float32 blue;
|
||||
float32 alpha;
|
||||
};
|
||||
inline bool32 equal(const RGBAf &c1, const RGBAf &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
||||
|
||||
inline void convColor(RGBA *i, RGBAf *f){
|
||||
int32 c;
|
||||
@ -83,6 +85,12 @@ inline void convColor(RGBAf *f, RGBA *i){
|
||||
f->alpha = i->alpha/255.0f;
|
||||
}
|
||||
|
||||
struct TexCoords
|
||||
{
|
||||
float32 u, v;
|
||||
};
|
||||
inline bool32 equal(const TexCoords &t1, const TexCoords &t2) { return t1.u == t2.u && t1.v == t2.v; }
|
||||
|
||||
struct V2d;
|
||||
struct V3d;
|
||||
struct Quat;
|
||||
@ -96,6 +104,7 @@ struct V2d
|
||||
};
|
||||
|
||||
inline V2d makeV2d(float32 x, float32 y) { V2d v = { x, y }; return v; }
|
||||
inline bool32 equal(const V2d &v1, const V2d &v2) { return v1.x == v2.x && v1.y == v2.y; }
|
||||
inline V2d neg(const V2d &a) { return makeV2d(-a.x, -a.y); }
|
||||
inline V2d add(const V2d &a, const V2d &b) { return makeV2d(a.x+b.x, a.y+b.y); }
|
||||
inline V2d sub(const V2d &a, const V2d &b) { return makeV2d(a.x-b.x, a.y-b.y); }
|
||||
@ -113,6 +122,7 @@ struct V3d
|
||||
};
|
||||
|
||||
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v = { x, y, z }; return v; }
|
||||
inline bool32 equal(const V3d &v1, const V3d &v2) { return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; }
|
||||
inline V3d neg(const V3d &a) { return makeV3d(-a.x, -a.y, -a.z); }
|
||||
inline V3d add(const V3d &a, const V3d &b) { return makeV3d(a.x+b.x, a.y+b.y, a.z+b.z); }
|
||||
inline V3d sub(const V3d &a, const V3d &b) { return makeV3d(a.x-b.x, a.y-b.y, a.z-b.z); }
|
||||
@ -128,6 +138,12 @@ inline V3d lerp(const V3d &a, const V3d &b, float32 r){
|
||||
a.z + r*(b.z - a.z));
|
||||
};
|
||||
|
||||
struct V4d
|
||||
{
|
||||
float32 x, y, z, w;
|
||||
};
|
||||
inline bool32 equal(const V4d &v1, const V4d &v2) { return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w; }
|
||||
|
||||
Quat makeQuat(float32 w, float32 x, float32 y, float32 z);
|
||||
Quat makeQuat(float32 w, const V3d &vec);
|
||||
|
||||
|
@ -360,8 +360,8 @@ struct MeshHeader
|
||||
struct MorphTarget
|
||||
{
|
||||
Sphere boundingSphere;
|
||||
float32 *vertices;
|
||||
float32 *normals;
|
||||
V3d *vertices;
|
||||
V3d *normals;
|
||||
};
|
||||
|
||||
struct InstanceDataHeader
|
||||
@ -401,8 +401,8 @@ struct Geometry : PluginBase<Geometry>
|
||||
int32 numTexCoordSets;
|
||||
|
||||
Triangle *triangles;
|
||||
uint8 *colors;
|
||||
float32 *texCoords[8];
|
||||
RGBA *colors;
|
||||
TexCoords *texCoords[8];
|
||||
|
||||
MorphTarget *morphTargets;
|
||||
MaterialList matList;
|
||||
|
@ -47,12 +47,12 @@ enum {
|
||||
VERT_COMPNORM
|
||||
};
|
||||
|
||||
void instV4d(int type, uint8 *dst, float *src, uint32 numVertices, uint32 stride);
|
||||
void instV3d(int type, uint8 *dst, float *src, uint32 numVertices, uint32 stride);
|
||||
void uninstV3d(int type, float *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
void instV2d(int type, uint8 *dst, float *src, uint32 numVertices, uint32 stride);
|
||||
void uninstV2d(int type, float *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
bool32 instColor(int type, uint8 *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
void uninstColor(int type, uint8 *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
void instV4d(int type, uint8 *dst, V4d *src, uint32 numVertices, uint32 stride);
|
||||
void instV3d(int type, uint8 *dst, V3d *src, uint32 numVertices, uint32 stride);
|
||||
void uninstV3d(int type, V3d *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
void instTexCoords(int type, uint8 *dst, TexCoords *src, uint32 numVertices, uint32 stride);
|
||||
void uninstTexCoords(int type, TexCoords *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
bool32 instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride);
|
||||
void uninstColor(int type, RGBA *dst, uint8 *src, uint32 numVertices, uint32 stride);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user