Skip to content

Commit

Permalink
Added stub code for unpacking trees for FFP usage (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Sep 6, 2023
1 parent ea030f5 commit 7ad9f52
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 9 deletions.
51 changes: 51 additions & 0 deletions src/Common/OGF_GContainer_Vertices.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ constexpr D3DVERTEXELEMENT9 x_decl_vert[] = // 12
D3DDECL_END()
};

constexpr D3DVERTEXELEMENT9 mu_model_decl[] = // 12+4+4+4+8 = 32
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
{ 0, 24, D3DDECLTYPE_SHORT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

constexpr D3DVERTEXELEMENT9 mu_model_decl_unpacked[] = // 12+4+4+8 = 28
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
#pragma pack(push, 1)
struct x_vert
{
Expand Down Expand Up @@ -208,4 +226,37 @@ struct r1v_vert_unpacked
return *this;
}
};

struct mu_model_vert
{
Fvector3 P;
u32 N;
u32 T;
u32 B;
_vector4<s16> misc;
};

struct mu_model_vert_unpacked
{
Fvector3 P;
u32 N;
u32 C;
Fvector2 tc;

mu_model_vert_unpacked& operator=(const mu_model_vert& packed)
{
P = packed.P;

Fcolor unpackedN(packed.N);
unpackedN.mul_rgb(2);
unpackedN.sub_rgb(1);
N = unpackedN.get();

tc.x = (packed.misc.x) * (32.f / 32768.f);
tc.y = (packed.misc.y) * (32.f / 32768.f);

return *this;
}
};

#pragma pack(pop)
27 changes: 26 additions & 1 deletion src/Layers/xrRender/FTreeVisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "xrEngine/Environment.h"
#include "xrCore/FMesh.hpp"
#include "FTreeVisual.h"
#include "Common/OGF_GContainer_Vertices.hpp"

shared_str m_xform;
shared_str m_xform_v;
Expand All @@ -22,7 +23,7 @@ void FTreeVisual::Load(const char* N, IReader* data, u32 dwFlags)
{
dxRender_Visual::Load(N, data, dwFlags);

VertexElement* vFormat = nullptr;
const VertexElement* vFormat = nullptr;

// read vertices
R_ASSERT(data->find_chunk(OGF_GCONTAINER));
Expand Down Expand Up @@ -64,6 +65,30 @@ void FTreeVisual::Load(const char* N, IReader* data, u32 dwFlags)
// Msg ("hemi[%f / %f], sun[%f / %f]",c_scale.hemi,c_bias.hemi,c_scale.sun,c_bias.sun);
}

/*if (RImplementation.o.ffp && dcl_equal(vFormat, mu_model_decl_unpacked))
{
const size_t vertices_size = vCount * sizeof(mu_model_vert_unpacked);
const auto new_buffer = xr_new<VertexStagingBuffer>();
new_buffer->Create(vertices_size);
auto vert_new = static_cast<mu_model_vert_unpacked*>(new_buffer->Map());
const auto vert_orig = static_cast<mu_model_vert_unpacked*>(p_rm_Vertices->Map(vBase, vertices_size, true)); // read-back
CopyMemory(vert_new, vert_orig, vertices_size);
for (size_t i = 0; i < vCount; ++i)
{
//vert_new->P.mul(xform.j);
++vert_new;
}
new_buffer->Unmap(true);
p_rm_Vertices->Unmap(false);
_RELEASE(p_rm_Vertices);
p_rm_Vertices = new_buffer;
vBase = 0;
}*/

// Geom
rm_geom.create(vFormat, *p_rm_Vertices, *p_rm_Indices);

Expand Down
13 changes: 13 additions & 0 deletions src/Layers/xrRenderPC_R1/FStaticRender_Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ void CRender::LoadBuffers(CStreamReader* base_fs, bool alternative)
for (size_t i = 0; i < vCount; ++i)
data[i] = packedData[i];
}
/*else if (dcl_equal(dcl, mu_model_decl))
{
dcl_len = std::size(mu_model_decl_unpacked);
_DC[i].resize(dcl_len);
CopyMemory(_DC[i].begin(), mu_model_decl_unpacked, dcl_len * sizeof(VertexElement));
vSize = GetDeclVertexSize(mu_model_decl_unpacked, 0);
_VB[i].Create(vCount * vSize, true);
auto* data = static_cast<mu_model_vert_unpacked*>(_VB[i].Map());
const auto* packedData = (mu_model_vert*)temp.data();
for (size_t i = 0; i < vCount; ++i)
data[i] = packedData[i];
}*/
else
{
_VB[i].Create(vCount * vSize);
Expand Down
10 changes: 2 additions & 8 deletions src/utils/xrLC/xrMU_Model_export_geometry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "utils/xrLC_Light/xrMU_Model.h"
#include "OGF_Face.h"
#include "Common/OGF_GContainer_Vertices.hpp"

const u32 max_tile = 16;
const s32 quant = 32768 / max_tile;
Expand All @@ -12,18 +13,11 @@ s16 QC(float v)
return s16(t);
}

D3DVERTEXELEMENT9 decl[] = // 12+4+4+4+8=32
{{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
{0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},
{0, 24, D3DDECLTYPE_SHORT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()};

void export_geometry(xrMU_Model& mu_model)
{
// Declarator
VDeclarator D;
D.set(decl);
D.set(mu_model_decl);

// RT-check, BOX, low-point, frac-size
Fbox BB;
Expand Down

0 comments on commit 7ad9f52

Please sign in to comment.