WIP KRMesh file format refactoring, to support independently formatted sub-meshes / primitives per model
Some checks are pending
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Waiting to run
Some checks are pending
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Waiting to run
This commit is contained in:
@@ -206,7 +206,7 @@ public:
|
||||
RasterMode rasterMode;
|
||||
CullMode cullMode;
|
||||
uint32_t vertexAttributes;
|
||||
Topology modelFormat;
|
||||
Topology topology;
|
||||
const KRRenderPass* renderPass;
|
||||
};
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
|
||||
key.second.push_back(surface.m_swapChain->m_extent.width);
|
||||
key.second.push_back(surface.m_swapChain->m_extent.height);
|
||||
key.second.push_back(info.vertexAttributes);
|
||||
key.second.push_back((int)info.modelFormat);
|
||||
key.second.push_back((int)info.topology);
|
||||
// TODO - Add renderPass unique identifier to key
|
||||
PipelineMap::iterator itr = m_pipelines.find(key);
|
||||
if (itr != m_pipelines.end()) {
|
||||
@@ -95,7 +95,7 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
|
||||
shaders.push_back(shader);
|
||||
}
|
||||
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface.m_deviceHandle, info.renderPass, surface.getDimensions(), surface.getDimensions(), info, info.shader_name->c_str(), shaders, info.vertexAttributes, info.modelFormat);
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface.m_deviceHandle, info.renderPass, surface.getDimensions(), surface.getDimensions(), info, info.shader_name->c_str(), shaders, info.vertexAttributes, info.topology);
|
||||
|
||||
m_pipelines[key] = pipeline;
|
||||
|
||||
@@ -145,7 +145,7 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
|
||||
key.second.push_back((int)info.rasterMode);
|
||||
key.second.push_back((int)info.cullMode);
|
||||
key.second.push_back(info.vertexAttributes);
|
||||
key.second.push_back((int)info.modelFormat);
|
||||
key.second.push_back((int)info.topology);
|
||||
key.second.push_back(info.bAlphaTest);
|
||||
key.second.push_back(info.bDiffuseMap);
|
||||
key.second.push_back(info.bNormalMap);
|
||||
@@ -295,7 +295,7 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
|
||||
Vector4 fade_color = info.pCamera->getFadeColor();
|
||||
|
||||
char szKey[256];
|
||||
sprintf(szKey, "%i_%i_%i_%i_%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f", (int)info.rasterMode, (int)info.cullMode, (int)info.modelFormat, (int)info.vertexAttributes, light_directional_count, light_point_count, light_spot_count, info.bone_count, info.pCamera->settings.fog_type, info.pCamera->settings.bEnablePerPixel, info.bAlphaTest, info.bDiffuseMap, info.bNormalMap, info.bSpecMap, info.bReflectionMap, info.bReflectionCubeMap, info.pCamera->settings.bDebugPSSM, iShadowQuality, info.pCamera->settings.bEnableAmbient, info.pCamera->settings.bEnableDiffuse, info.pCamera->settings.bEnableSpecular, info.bLightMap, info.bDiffuseMapScale, info.bSpecMapScale, info.bReflectionMapScale, info.bNormalMapScale, info.bDiffuseMapOffset, info.bSpecMapOffset, info.bReflectionMapOffset, info.bNormalMapOffset, info.pCamera->settings.volumetric_environment_enable && info.pCamera->settings.volumetric_environment_downsample != 0, info.renderPass, info.shader_name->c_str(), info.pCamera->settings.dof_quality, info.pCamera->settings.bEnableFlash, info.pCamera->settings.bEnableVignette, info.pCamera->settings.dof_depth, info.pCamera->settings.dof_falloff, info.pCamera->settings.flash_depth, info.pCamera->settings.flash_falloff, info.pCamera->settings.flash_intensity, info.pCamera->settings.vignette_radius, info.pCamera->settings.vignette_falloff, fade_color.x, fade_color.y, fade_color.z, fade_color.w);
|
||||
sprintf(szKey, "%i_%i_%i_%i_%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f", (int)info.rasterMode, (int)info.cullMode, (int)info.topology, (int)info.vertexAttributes, light_directional_count, light_point_count, light_spot_count, info.bone_count, info.pCamera->settings.fog_type, info.pCamera->settings.bEnablePerPixel, info.bAlphaTest, info.bDiffuseMap, info.bNormalMap, info.bSpecMap, info.bReflectionMap, info.bReflectionCubeMap, info.pCamera->settings.bDebugPSSM, iShadowQuality, info.pCamera->settings.bEnableAmbient, info.pCamera->settings.bEnableDiffuse, info.pCamera->settings.bEnableSpecular, info.bLightMap, info.bDiffuseMapScale, info.bSpecMapScale, info.bReflectionMapScale, info.bNormalMapScale, info.bDiffuseMapOffset, info.bSpecMapOffset, info.bReflectionMapOffset, info.bNormalMapOffset, info.pCamera->settings.volumetric_environment_enable && info.pCamera->settings.volumetric_environment_downsample != 0, info.renderPass, info.shader_name->c_str(), info.pCamera->settings.dof_quality, info.pCamera->settings.bEnableFlash, info.pCamera->settings.bEnableVignette, info.pCamera->settings.dof_depth, info.pCamera->settings.dof_falloff, info.pCamera->settings.flash_depth, info.pCamera->settings.flash_falloff, info.pCamera->settings.flash_intensity, info.pCamera->settings.vignette_radius, info.pCamera->settings.vignette_falloff, fade_color.x, fade_color.y, fade_color.z, fade_color.w);
|
||||
|
||||
pPipeline = new KRPipeline(getContext(), szKey, options, vertSource->getData()->getString(), fragSource->getData()->getString());
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ void KRAmbientZone::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.topology = sphereModel->getTopology();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -152,7 +152,7 @@ void KRAudioSource::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.topology = sphereModel->getTopology();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -92,7 +92,7 @@ void KRBone::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAdditiveNoTest;
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.topology = sphereModel->getTopology();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -188,7 +188,7 @@ void KRCamera::render(KRNode::RenderInfo& ri)
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.vertexAttributes = vertices.getVertexAttributes();
|
||||
info.modelFormat = Topology::TriangleStrips;
|
||||
info.topology = Topology::TriangleStrips;
|
||||
KRPipeline* pVisShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
}
|
||||
*/
|
||||
@@ -425,7 +425,7 @@ void KRCamera::renderPost(RenderInfo& ri)
|
||||
info.pCamera = this;
|
||||
info.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
info.rasterMode = RasterMode::kOpaqueNoTest;
|
||||
info.modelFormat = Topology::TriangleStrips;
|
||||
info.topology = Topology::TriangleStrips;
|
||||
info.vertexAttributes = vertices.getVertexAttributes();
|
||||
|
||||
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
|
||||
@@ -617,7 +617,7 @@ void KRCamera::renderDebug(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAlphaBlendNoTest;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0);
|
||||
info.modelFormat = Topology::Triangles;
|
||||
info.topology = Topology::Triangles;
|
||||
KRPipeline* fontShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
if (fontShader && fontShader->bind(ri, Matrix4())) {
|
||||
|
||||
@@ -217,7 +217,7 @@ void KRCollider::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.modelFormat = m_model.val.get()->getModelFormat();
|
||||
info.topology = m_model.val.get()->getTopology();
|
||||
info.vertexAttributes = m_model.val.get()->getVertexAttributes();
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -161,7 +161,7 @@ void KRDirectionalLight::render(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAdditiveNoTest;
|
||||
|
||||
info.vertexAttributes = vertices.getVertexAttributes();
|
||||
info.modelFormat = Topology::TriangleStrips;
|
||||
info.topology = Topology::TriangleStrips;
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if (pShader && pShader->bind(ri, getModelMatrix())) { // TODO: Need to pass in the light index to the shader
|
||||
|
||||
@@ -239,7 +239,7 @@ void KRLight::render(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0);
|
||||
info.modelFormat = Topology::Triangles;
|
||||
info.topology = Topology::Triangles;
|
||||
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if (pParticleShader && pParticleShader->bind(ri, getParticleModelMatrix(*ri.viewport))) { // TODO: Pass light index to shader
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);
|
||||
@@ -279,7 +279,7 @@ void KRLight::render(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION);
|
||||
info.modelFormat = Topology::Triangles;
|
||||
info.topology = Topology::Triangles;
|
||||
|
||||
KRPipeline* pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if (pFogShader) {
|
||||
@@ -313,7 +313,7 @@ void KRLight::render(RenderInfo& ri)
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.topology = sphereModel->getTopology();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
@@ -364,7 +364,7 @@ void KRLight::render(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAdditiveNoTest;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.vertexAttributes = vertices.getVertexAttributes();
|
||||
info.modelFormat = Topology::TriangleStrips;
|
||||
info.topology = Topology::TriangleStrips;
|
||||
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -99,7 +99,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0);
|
||||
info.modelFormat = Topology::Triangles;
|
||||
info.topology = Topology::Triangles;
|
||||
|
||||
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if (pParticleShader && pParticleShader->bind(ri, getModelMatrix())) {
|
||||
|
||||
@@ -113,7 +113,7 @@ void KRPointLight::render(RenderInfo& ri)
|
||||
info.rasterMode = bVisualize ? RasterMode::kAdditive : RasterMode::kAlphaBlend;
|
||||
}
|
||||
info.vertexAttributes = bInsideLight ? m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.getVertexAttributes() : 1 << KRMesh::KRENGINE_ATTRIB_POSITION;
|
||||
info.modelFormat = bInsideLight ? Topology::TriangleStrips : Topology::Triangles;
|
||||
info.topology = bInsideLight ? Topology::TriangleStrips : Topology::Triangles;
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if (pShader && pShader->bind(ri, sphereModelMatrix)) { // TODO: Pass light index to shader
|
||||
|
||||
@@ -127,7 +127,7 @@ void KRReverbZone::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = RasterMode::kAlphaBlend;
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.topology = sphereModel->getTopology();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -133,7 +133,7 @@ void KRSprite::render(RenderInfo& ri)
|
||||
info.rasterMode = RasterMode::kAdditive;
|
||||
info.cullMode = CullMode::kCullNone;
|
||||
info.vertexAttributes = vertices.getVertexAttributes();
|
||||
info.modelFormat = Topology::TriangleStrips;
|
||||
info.topology = Topology::TriangleStrips;
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if (pShader && pShader->bind(ri, getModelMatrix())) {
|
||||
|
||||
@@ -743,7 +743,7 @@ kraken_stream_level KRMaterial::getStreamLevel()
|
||||
return stream_level;
|
||||
}
|
||||
|
||||
bool KRMaterial::bind(KRNode::RenderInfo& ri, Topology modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, float lod_coverage)
|
||||
bool KRMaterial::bind(KRNode::RenderInfo& ri, Topology topology, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, float lod_coverage)
|
||||
{
|
||||
bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap;
|
||||
|
||||
@@ -784,7 +784,7 @@ bool KRMaterial::bind(KRNode::RenderInfo& ri, Topology modelFormat, __uint32_t v
|
||||
info.bAlphaTest = bAlphaTest;
|
||||
info.rasterMode = bAlphaBlend ? RasterMode::kAlphaBlend : RasterMode::kOpaque;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.modelFormat = modelFormat;
|
||||
info.topology = topology;
|
||||
info.vertexAttributes = vertexAttributes;
|
||||
info.cullMode = cullMode;
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
|
||||
bool isTransparent();
|
||||
|
||||
bool bind(KRNode::RenderInfo& ri, Topology modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, float lod_coverage = 0.0f);
|
||||
bool bind(KRNode::RenderInfo& ri, Topology topology, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, float lod_coverage = 0.0f);
|
||||
|
||||
bool needsVertexTangents();
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ void KRMesh::loadPack(Block* data)
|
||||
m_pMetaData = m_pData->getSubBlock(0, sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count);
|
||||
m_pMetaData->lock();
|
||||
|
||||
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8);
|
||||
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.primitive.indexCount), ph.index_base_count * 8);
|
||||
m_pIndexBaseData->lock();
|
||||
|
||||
m_extents = ph.extents;
|
||||
@@ -263,7 +263,7 @@ void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, cons
|
||||
switch (pMaterial->getAlphaMode()) {
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
||||
if (pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
|
||||
if (pMaterial->bind(ri, getTopology(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
|
||||
{
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
}
|
||||
@@ -273,14 +273,14 @@ void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, cons
|
||||
// Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||
//
|
||||
// Render back faces before front faces
|
||||
if (pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
|
||||
if (pMaterial->bind(ri, getTopology(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
|
||||
{
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
}
|
||||
}
|
||||
|
||||
// Render front faces
|
||||
if (pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
|
||||
if (pMaterial->bind(ri, getTopology(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
|
||||
{
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
|
||||
int index_data_offset = (int)getIndexDataOffset();
|
||||
pack_header* pHeader = getHeader();
|
||||
int32_t vertex_attrib_flags = pHeader->vertex_attrib_flags;
|
||||
int32_t vertex_count = pHeader->vertex_count;
|
||||
int32_t vertex_count = pHeader->primitive.vertexCount;
|
||||
|
||||
int vbo_index = 0;
|
||||
if (getIndexCount(iSubmesh) > 0) {
|
||||
@@ -590,11 +590,11 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
||||
memset(pHeader, 0, sizeof(pack_header));
|
||||
pHeader->vertex_attrib_flags = vertex_attrib_flags;
|
||||
pHeader->submesh_count = (__int32_t)submesh_count;
|
||||
pHeader->vertex_count = (__int32_t)vertex_count;
|
||||
pHeader->primitive.vertexCount = (__int32_t)vertex_count;
|
||||
pHeader->bone_count = (__int32_t)bone_count;
|
||||
pHeader->index_count = (__int32_t)index_count;
|
||||
pHeader->primitive.indexCount = (__int32_t)index_count;
|
||||
pHeader->index_base_count = (__int32_t)index_base_count;
|
||||
pHeader->model_format = (__int32_t)mi.format;
|
||||
pHeader->primitive.topology = mi.format;
|
||||
strcpy(pHeader->szTag, "KRMESH1.0 ");
|
||||
updateAttributeOffsets();
|
||||
|
||||
@@ -714,7 +714,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
||||
|
||||
// Calculate missing surface normals and tangents
|
||||
if (calculate_normals || calculate_tangents) {
|
||||
switch (getModelFormat()) {
|
||||
switch (getTopology()) {
|
||||
case Topology::Triangles:
|
||||
{
|
||||
// NOTE: This will not work properly if the vertices are already indexed
|
||||
@@ -751,7 +751,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
||||
m_pData->copy((void*)&ph, 0, sizeof(ph));
|
||||
m_pMetaData = m_pData->getSubBlock(0, sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count);
|
||||
m_pMetaData->lock();
|
||||
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8);
|
||||
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.primitive.indexCount), ph.index_base_count * 8);
|
||||
m_pIndexBaseData->lock();
|
||||
|
||||
// ----
|
||||
@@ -816,7 +816,7 @@ unsigned char* KRMesh::getVertexData() const
|
||||
size_t KRMesh::getVertexDataOffset() const
|
||||
{
|
||||
pack_header* pHeader = getHeader();
|
||||
return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count) + KRALIGN(8 * pHeader->index_base_count);
|
||||
return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->primitive.indexCount) + KRALIGN(8 * pHeader->index_base_count);
|
||||
}
|
||||
|
||||
__uint16_t* KRMesh::getIndexData() const
|
||||
@@ -835,7 +835,7 @@ __uint32_t* KRMesh::getIndexBaseData() const
|
||||
{
|
||||
if (m_pIndexBaseData == NULL) {
|
||||
pack_header* pHeader = getHeader();
|
||||
return (__uint32_t*)((unsigned char*)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count));
|
||||
return (__uint32_t*)((unsigned char*)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->primitive.indexCount));
|
||||
} else {
|
||||
return (__uint32_t*)m_pIndexBaseData->getStart();
|
||||
}
|
||||
@@ -867,7 +867,7 @@ int KRMesh::getVertexCount(int submesh) const
|
||||
int KRMesh::getIndexCount(int submesh) const
|
||||
{
|
||||
pack_header* pHeader = getHeader();
|
||||
if (pHeader->index_count == 0) {
|
||||
if (pHeader->primitive.indexCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
int index_group = getSubmesh(submesh)->index_group;
|
||||
@@ -1227,9 +1227,9 @@ Matrix4 KRMesh::getBoneBindPose(int bone_index)
|
||||
return Matrix4::Create(getBone(bone_index)->bind_pose);
|
||||
}
|
||||
|
||||
Topology KRMesh::getModelFormat() const
|
||||
Topology KRMesh::getTopology() const
|
||||
{
|
||||
return (Topology)getHeader()->model_format;
|
||||
return getHeader()->primitive.topology;
|
||||
}
|
||||
|
||||
bool KRMesh::rayCast(const Vector3& start, const Vector3& dir, const Triangle3& tri, const Vector3& tri_n0, const Vector3& tri_n1, const Vector3& tri_n2, HitInfo& hitinfo)
|
||||
@@ -1272,7 +1272,7 @@ bool KRMesh::rayCast(const Vector3& start, const Vector3& dir, HitInfo& hitinfo)
|
||||
bool hit_found = false;
|
||||
for (int submesh_index = 0; submesh_index < getSubmeshCount(); submesh_index++) {
|
||||
int vertex_count = getVertexCount(submesh_index);
|
||||
switch (getModelFormat()) {
|
||||
switch (getTopology()) {
|
||||
case Topology::Triangles:
|
||||
for (int triangle_index = 0; triangle_index < vertex_count / 3; triangle_index++) {
|
||||
int tri_vert_index[3]; // FINDME, HACK! This is not very efficient for indexed collider meshes...
|
||||
@@ -1302,7 +1302,7 @@ bool KRMesh::sphereCast(const Matrix4& model_to_world, const Vector3& v0, const
|
||||
bool hit_found = false;
|
||||
for (int submesh_index = 0; submesh_index < getSubmeshCount(); submesh_index++) {
|
||||
int vertex_count = getVertexCount(submesh_index);
|
||||
switch (getModelFormat()) {
|
||||
switch (getTopology()) {
|
||||
case Topology::Triangles:
|
||||
for (int triangle_index = 0; triangle_index < vertex_count / 3; triangle_index++) {
|
||||
int tri_vert_index[3]; // FINDME, HACK! This is not very efficient for indexed collider meshes...
|
||||
@@ -1385,7 +1385,7 @@ void KRMesh::convertToIndexed()
|
||||
int vertex_index_base_start_vertex = 0;
|
||||
|
||||
mesh_info mi;
|
||||
mi.format = getModelFormat();
|
||||
mi.format = getTopology();
|
||||
|
||||
int bone_count = getBoneCount();
|
||||
for (int bone_index = 0; bone_index < bone_count; bone_index++) {
|
||||
@@ -1517,7 +1517,7 @@ void KRMesh::convertToIndexed()
|
||||
|
||||
delete[] szKey;
|
||||
|
||||
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i (%.2f%% saving)", getHeader()->vertex_count, mi.vertices.size(), ((float)getHeader()->vertex_count - (float)mi.vertices.size()) / (float)getHeader()->vertex_count * 100.0f);
|
||||
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i (%.2f%% saving)", getHeader()->primitive.vertexCount, mi.vertices.size(), ((float)getHeader()->primitive.vertexCount - (float)mi.vertices.size()) / (float)getHeader()->primitive.vertexCount * 100.0f);
|
||||
|
||||
m_pData->unlock();
|
||||
LoadData(mi, false, false);
|
||||
@@ -1542,8 +1542,8 @@ void KRMesh::getIndexedRange(int index_group, int& start_index_offset, int& star
|
||||
index_count = index_base_data[index_group * 2 + 2] - start_index_offset;
|
||||
vertex_count = index_base_data[index_group * 2 + 3] - start_vertex_offset;
|
||||
} else {
|
||||
index_count = h->index_count - start_index_offset;
|
||||
vertex_count = h->vertex_count - start_vertex_offset;
|
||||
index_count = h->primitive.indexCount - start_index_offset;
|
||||
vertex_count = h->primitive.vertexCount - start_vertex_offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1574,7 +1574,7 @@ void KRMesh::optimizeIndexes()
|
||||
|
||||
m_pData->lock();
|
||||
// TODO - Implement optimization for indexed strips
|
||||
if (getModelFormat() == Topology::Triangles && getIndexCount(0) > 0) {
|
||||
if (getTopology() == Topology::Triangles && getIndexCount(0) > 0) {
|
||||
|
||||
__uint16_t* new_indices = (__uint16_t*)malloc(0x10000 * sizeof(__uint16_t));
|
||||
__uint16_t* vertex_mapping = (__uint16_t*)malloc(0x10000 * sizeof(__uint16_t));
|
||||
@@ -1655,7 +1655,7 @@ void KRMesh::optimizeIndexes()
|
||||
free(new_indices);
|
||||
free(vertex_mapping);
|
||||
free(new_vertex_data);
|
||||
} // getModelFormat() == Topology::Triangles && getIndexCount(0) > 0
|
||||
} // getTopology() == Topology::Triangles && getIndexCount(0) > 0
|
||||
|
||||
m_pData->unlock();
|
||||
}
|
||||
|
||||
@@ -69,21 +69,6 @@ enum class Topology : uint8_t
|
||||
TriangleFans
|
||||
};
|
||||
|
||||
class KRMesh : public KRResource
|
||||
{
|
||||
|
||||
public:
|
||||
KRMesh(KRContext& context, std::string name, mimir::Block* data);
|
||||
KRMesh(KRContext& context, std::string name);
|
||||
virtual ~KRMesh();
|
||||
|
||||
kraken_stream_level getStreamLevel();
|
||||
virtual void getResourceBindings(std::list<KRResourceBinding*>& bindings) override;
|
||||
void preStream();
|
||||
void requestResidency(uint32_t usage, float lodCoverage) final;
|
||||
|
||||
bool hasTransparency();
|
||||
|
||||
enum class ComponentType : uint8_t
|
||||
{
|
||||
empty = 0,
|
||||
@@ -100,6 +85,22 @@ public:
|
||||
float64
|
||||
};
|
||||
|
||||
static constexpr std::array<int, 12> ComponentSize =
|
||||
{
|
||||
0, // empty
|
||||
1, // int8
|
||||
1, // uint8
|
||||
2, // int16
|
||||
2, // uint16
|
||||
4, // int32
|
||||
4, // uint32
|
||||
8, // int64
|
||||
8, // uint64
|
||||
2, // float16
|
||||
4, // float32
|
||||
8 // float64
|
||||
};
|
||||
|
||||
enum class DataType : uint8_t
|
||||
{
|
||||
scalar = 0,
|
||||
@@ -133,6 +134,21 @@ public:
|
||||
VertexAttribute::weights
|
||||
};
|
||||
|
||||
class KRMesh : public KRResource
|
||||
{
|
||||
|
||||
public:
|
||||
KRMesh(KRContext& context, std::string name, mimir::Block* data);
|
||||
KRMesh(KRContext& context, std::string name);
|
||||
virtual ~KRMesh();
|
||||
|
||||
kraken_stream_level getStreamLevel();
|
||||
virtual void getResourceBindings(std::list<KRResourceBinding*>& bindings) override;
|
||||
void preStream();
|
||||
void requestResidency(uint32_t usage, float lodCoverage) final;
|
||||
|
||||
bool hasTransparency();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ComponentType component;
|
||||
@@ -145,10 +161,10 @@ public:
|
||||
static const int kMaxAttributes = 32;
|
||||
typedef struct
|
||||
{
|
||||
Topology topology;
|
||||
AttributeInfo attributes[kMaxAttributes];
|
||||
int64_t vertexCount;
|
||||
int64_t indexCount;
|
||||
Topology topology;
|
||||
} PrimitiveInfo;
|
||||
|
||||
typedef enum
|
||||
@@ -316,7 +332,7 @@ public:
|
||||
hydra::Matrix4 getBoneBindPose(int bone_index);
|
||||
|
||||
|
||||
Topology getModelFormat() const;
|
||||
Topology getTopology() const;
|
||||
|
||||
bool lineCast(const hydra::Vector3& v0, const hydra::Vector3& v1, hydra::HitInfo& hitinfo) const;
|
||||
bool rayCast(const hydra::Vector3& v0, const hydra::Vector3& dir, hydra::HitInfo& hitinfo) const;
|
||||
@@ -350,15 +366,13 @@ private:
|
||||
typedef struct
|
||||
{
|
||||
char szTag[16];
|
||||
int32_t model_format; // 0 == Triangle list, 1 == Triangle strips, 2 == Indexed triangle list, 3 == Indexed triangle strips, rest are reserved (model_format_t enum)
|
||||
PrimitiveInfo primitive;
|
||||
int32_t vertex_attrib_flags;
|
||||
int32_t vertex_count;
|
||||
int32_t submesh_count;
|
||||
int32_t bone_count;
|
||||
hydra::AABB extents; // Axis aligned bounding box, in model's coordinate space
|
||||
int32_t index_count;
|
||||
int32_t index_base_count;
|
||||
unsigned char reserved[444]; // Pad out to 512 bytes
|
||||
unsigned char reserved[456 - sizeof(PrimitiveInfo)]; // Pad out to 512 bytes
|
||||
} pack_header;
|
||||
|
||||
static_assert(sizeof(pack_header) == 512);
|
||||
|
||||
Reference in New Issue
Block a user