From 5b791424711f4c81f09394983901e1a4b0f3f796 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Thu, 4 Jun 2026 00:36:32 -0700 Subject: [PATCH] Rename KRENGINE_ATTRIB_VERTEX to KRENGINE_ATTRIB_POSITION, WIP new krmesh header structs --- kraken/KRPipeline.cpp | 8 +-- kraken/nodes/KRCamera.cpp | 4 +- kraken/nodes/KRLight.cpp | 4 +- kraken/nodes/KRParticleSystemNewtonian.cpp | 2 +- kraken/nodes/KRPointLight.cpp | 4 +- kraken/resources/mesh/KRMesh.cpp | 16 ++--- kraken/resources/mesh/KRMesh.h | 69 +++++++++++++++++++++- kraken/resources/mesh/KRMeshManager.cpp | 8 +-- 8 files changed, 91 insertions(+), 24 deletions(-) diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index f9074cd..5cd61e2 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -74,7 +74,7 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KR // TODO - Refactor this... These lookup tables should be in KRMesh... static const KRMesh::vertex_attrib_t attribute_mapping[KRMesh::KRENGINE_NUM_ATTRIBUTES] = { - KRMesh::KRENGINE_ATTRIB_VERTEX, + KRMesh::KRENGINE_ATTRIB_POSITION, KRMesh::KRENGINE_ATTRIB_NORMAL, KRMesh::KRENGINE_ATTRIB_TANGENT, KRMesh::KRENGINE_ATTRIB_COLOR0, @@ -95,7 +95,7 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KR KRMesh::KRENGINE_ATTRIB_TEXCOORD7, KRMesh::KRENGINE_ATTRIB_BONEINDEXES, KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS, - KRMesh::KRENGINE_ATTRIB_VERTEX, + KRMesh::KRENGINE_ATTRIB_POSITION, KRMesh::KRENGINE_ATTRIB_NORMAL, KRMesh::KRENGINE_ATTRIB_TANGENT, KRMesh::KRENGINE_ATTRIB_TEXCOORD0, @@ -145,7 +145,7 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KR // TODO - We should have an interface to allow classes such as KRMesh to expose bindings SpvReflectInterfaceVariable& input_var = *reflection->input_variables[i]; if (strcmp(input_var.name, "vertex_position") == 0) { - attribute_locations[KRMesh::KRENGINE_ATTRIB_VERTEX] = input_var.location + 1; + attribute_locations[KRMesh::KRENGINE_ATTRIB_POSITION] = input_var.location + 1; } else if (strcmp(input_var.name, "vertex_normal") == 0) { attribute_locations[KRMesh::KRENGINE_ATTRIB_NORMAL] = input_var.location + 1; } else if (strcmp(input_var.name, "vertex_tangent") == 0) { @@ -204,7 +204,7 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KR uint32_t vertexAttributeCount = 0; VkVertexInputAttributeDescription vertexAttributeDescriptions[KRMesh::KRENGINE_NUM_ATTRIBUTES]{}; - for (int i = KRMesh::KRENGINE_ATTRIB_VERTEX; i < KRMesh::KRENGINE_NUM_ATTRIBUTES; i++) { + for (int i = KRMesh::KRENGINE_ATTRIB_POSITION; i < KRMesh::KRENGINE_NUM_ATTRIBUTES; i++) { KRMesh::vertex_attrib_t mesh_attrib = static_cast(i); int location_attrib = attribute_mapping[i]; if (KRMesh::has_vertex_attribute(vertexAttributes, (KRMesh::vertex_attrib_t)i) && attribute_locations[location_attrib]) { diff --git a/kraken/nodes/KRCamera.cpp b/kraken/nodes/KRCamera.cpp index 90fcdaa..313a56c 100755 --- a/kraken/nodes/KRCamera.cpp +++ b/kraken/nodes/KRCamera.cpp @@ -91,7 +91,7 @@ KRCamera::KRCamera(KRScene& scene, std::string name) m_fade_color = Vector4::Zero(); - m_debug_text_vbo_data.init(m_pContext->getMeshManager(), &m_debug_text_vertices, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0), true, KRMeshManager::KRVBOData::IMMEDIATE + m_debug_text_vbo_data.init(m_pContext->getMeshManager(), &m_debug_text_vertices, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0), true, KRMeshManager::KRVBOData::IMMEDIATE #if KRENGINE_DEBUG_GPU_LABELS , "Debug Text" #endif @@ -616,7 +616,7 @@ void KRCamera::renderDebug(RenderInfo& ri) info.renderPass = ri.renderPass; info.rasterMode = RasterMode::kAlphaBlendNoTest; info.cullMode = CullMode::kCullNone; - info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); + info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* fontShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); diff --git a/kraken/nodes/KRLight.cpp b/kraken/nodes/KRLight.cpp index cea7d53..3595e38 100755 --- a/kraken/nodes/KRLight.cpp +++ b/kraken/nodes/KRLight.cpp @@ -238,7 +238,7 @@ void KRLight::render(RenderInfo& ri) info.renderPass = ri.renderPass; info.rasterMode = RasterMode::kAdditive; info.cullMode = CullMode::kCullNone; - info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); + info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); if (pParticleShader && pParticleShader->bind(ri, getParticleModelMatrix(*ri.viewport))) { // TODO: Pass light index to shader @@ -278,7 +278,7 @@ void KRLight::render(RenderInfo& ri) info.renderPass = ri.renderPass; info.rasterMode = RasterMode::kAdditive; info.cullMode = CullMode::kCullNone; - info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX); + info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION); info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); diff --git a/kraken/nodes/KRParticleSystemNewtonian.cpp b/kraken/nodes/KRParticleSystemNewtonian.cpp index 13af7e3..999b0e9 100755 --- a/kraken/nodes/KRParticleSystemNewtonian.cpp +++ b/kraken/nodes/KRParticleSystemNewtonian.cpp @@ -98,7 +98,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) info.renderPass = ri.renderPass; info.rasterMode = RasterMode::kAdditive; info.cullMode = CullMode::kCullNone; - info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); + info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); diff --git a/kraken/nodes/KRPointLight.cpp b/kraken/nodes/KRPointLight.cpp index 80da372..6de7e27 100755 --- a/kraken/nodes/KRPointLight.cpp +++ b/kraken/nodes/KRPointLight.cpp @@ -112,7 +112,7 @@ void KRPointLight::render(RenderInfo& ri) } else { info.rasterMode = bVisualize ? RasterMode::kAdditive : RasterMode::kAlphaBlend; } - info.vertexAttributes = bInsideLight ? m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.getVertexAttributes() : 1 << KRMesh::KRENGINE_ATTRIB_VERTEX; + info.vertexAttributes = bInsideLight ? m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.getVertexAttributes() : 1 << KRMesh::KRENGINE_ATTRIB_POSITION; info.modelFormat = bInsideLight ? ModelFormat::KRENGINE_MODEL_FORMAT_STRIP : ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); @@ -126,7 +126,7 @@ void KRPointLight::render(RenderInfo& ri) // Render sphere of light's influence generateMesh(); - GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices)); + GLDEBUG(glVertexAttribPointer(KRMesh::KRENGINE_ATTRIB_POSITION, 3, GL_FLOAT, 0, 0, m_sphereVertices)); vkCmdDraw(ri.commandBuffer, m_cVertices, 1, 0, 0); } diff --git a/kraken/resources/mesh/KRMesh.cpp b/kraken/resources/mesh/KRMesh.cpp index a460ffd..875935f 100755 --- a/kraken/resources/mesh/KRMesh.cpp +++ b/kraken/resources/mesh/KRMesh.cpp @@ -554,7 +554,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool if (use_short_vertexes) { vertex_attrib_flags |= (1 << KRENGINE_ATTRIB_VERTEX_SHORT); } else { - vertex_attrib_flags |= (1 << KRENGINE_ATTRIB_VERTEX); + vertex_attrib_flags |= (1 << KRENGINE_ATTRIB_POSITION); } } if (mi.normals.size() || calculate_normals) { @@ -865,8 +865,8 @@ Vector3 KRMesh::getVertexPosition(int index) const if (has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { short* v = (short*)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]); return Vector3::Create((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); - } else if (has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) { - return Vector3::Create((float*)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX])); + } else if (has_vertex_attribute(KRENGINE_ATTRIB_POSITION)) { + return Vector3::Create((float*)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_POSITION])); } else { return Vector3::Zero(); } @@ -925,8 +925,8 @@ void KRMesh::setVertexPosition(int index, const Vector3& v) vert[0] = (short)(v.x * 32767.0f); vert[1] = (short)(v.y * 32767.0f); vert[2] = (short)(v.z * 32767.0f); - } else if (has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) { - float* vert = (float*)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX]); + } else if (has_vertex_attribute(KRENGINE_ATTRIB_POSITION)) { + float* vert = (float*)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_POSITION]); vert[0] = v.x; vert[1] = v.y; vert[2] = v.z; @@ -1015,7 +1015,7 @@ void KRMesh::setBoneWeight(int index, int weight_index, float bone_weight) size_t KRMesh::VertexSizeForAttributes(__int32_t vertex_attrib_flags) { size_t data_size = 0; - if (has_vertex_attribute(vertex_attrib_flags, KRENGINE_ATTRIB_VERTEX)) { + if (has_vertex_attribute(vertex_attrib_flags, KRENGINE_ATTRIB_POSITION)) { data_size += sizeof(float) * 3; } if (has_vertex_attribute(vertex_attrib_flags, KRENGINE_ATTRIB_NORMAL)) { @@ -1143,7 +1143,7 @@ size_t KRMesh::AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_ VkFormat KRMesh::AttributeVulkanFormat(__int32_t vertex_attrib) { switch (vertex_attrib) { - case KRENGINE_ATTRIB_VERTEX: + case KRENGINE_ATTRIB_POSITION: case KRENGINE_ATTRIB_NORMAL: case KRENGINE_ATTRIB_TANGENT: case KRENGINE_ATTRIB_BONEWEIGHTS: @@ -1476,7 +1476,7 @@ void KRMesh::convertToIndexed() int found_index = -1; if (prev_indexes.count(vertex_key) == 0) { found_index = (int)mi.vertices.size() - vertex_index_base_start_vertex; - if (has_vertex_attribute(KRENGINE_ATTRIB_VERTEX) || has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { + if (has_vertex_attribute(KRENGINE_ATTRIB_POSITION) || has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { mi.vertices.push_back(vertex_position); } if (has_vertex_attribute(KRENGINE_ATTRIB_NORMAL) || has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) { diff --git a/kraken/resources/mesh/KRMesh.h b/kraken/resources/mesh/KRMesh.h index 7b81160..2e97229 100755 --- a/kraken/resources/mesh/KRMesh.h +++ b/kraken/resources/mesh/KRMesh.h @@ -82,9 +82,76 @@ public: bool hasTransparency(); + enum class ComponentType : uint8_t + { + empty = 0, + int8, + uint8, + int16, + uint16, + int32, + uint32, + int64, + uint64, + float16, + float32, + float64 + }; + + enum class DataType : uint8_t + { + scalar = 0, + vec2, + vec3, + vec4, + mat2, + mat3, + mat4 + }; + + enum class VertexAttribute : uint8_t + { + position = 0, + normal, + tangent, + texcoord, + color, + joints, + weights + }; + + typedef struct + { + ComponentType component; + DataType type; + VertexAttribute attribute; + bool normalized : 1; + } AttributeInfo; + static_assert(sizeof(AttributeInfo) == 4); + + enum class Topology : uint8_t + { + Points = 0, + LineStrips, + LineLoops, + Lines, + Triangles, + TriangleStrips, + TriangleFans + }; + + static const int kMaxAttributes = 32; + typedef struct + { + Topology topology; + AttributeInfo attributes[kMaxAttributes]; + int64_t vertexCount; + int64_t indexCount; + } PrimitiveInfo; + typedef enum { - KRENGINE_ATTRIB_VERTEX = 0, + KRENGINE_ATTRIB_POSITION = 0, KRENGINE_ATTRIB_NORMAL, KRENGINE_ATTRIB_TANGENT, KRENGINE_ATTRIB_COLOR0, diff --git a/kraken/resources/mesh/KRMeshManager.cpp b/kraken/resources/mesh/KRMeshManager.cpp index fec7607..47ab12e 100755 --- a/kraken/resources/mesh/KRMeshManager.cpp +++ b/kraken/resources/mesh/KRMeshManager.cpp @@ -77,7 +77,7 @@ void KRMeshManager::init() -1.0, 1.0,-1.0 }; - KRENGINE_VBO_3D_CUBE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX); + KRENGINE_VBO_3D_CUBE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_POSITION); KRENGINE_VBO_3D_CUBE_VERTICES.expand(sizeof(float) * 3 * 14); KRENGINE_VBO_3D_CUBE_VERTICES.lock(); memcpy(KRENGINE_VBO_3D_CUBE_VERTICES.getStart(), _KRENGINE_VBO_3D_CUBE_VERTEX_DATA, sizeof(float) * 3 * 14); @@ -98,7 +98,7 @@ void KRMeshManager::init() -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; - KRENGINE_VBO_2D_SQUARE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); + KRENGINE_VBO_2D_SQUARE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0); KRENGINE_VBO_2D_SQUARE_VERTICES.expand(sizeof(float) * 5 * 4); KRENGINE_VBO_2D_SQUARE_VERTICES.lock(); memcpy(KRENGINE_VBO_2D_SQUARE_VERTICES.getStart(), _KRENGINE_VBO_2D_SQUARE_VERTEX_DATA, sizeof(float) * 5 * 4); @@ -347,7 +347,7 @@ void KRMeshManager::initVolumetricLightingVertexes() } - KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING.init(this, &m_volumetricLightingVertexData, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX), false, KRVBOData::CONSTANT + KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING.init(this, &m_volumetricLightingVertexData, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_POSITION), false, KRVBOData::CONSTANT #if KRENGINE_DEBUG_GPU_LABELS , "Volumetric Lighting Planes [built-in]" #endif @@ -393,7 +393,7 @@ void KRMeshManager::initRandomParticles() iVertex++; } - KRENGINE_VBO_DATA_RANDOM_PARTICLES.init(this, &m_randomParticleVertexData, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0), false, KRVBOData::CONSTANT + KRENGINE_VBO_DATA_RANDOM_PARTICLES.init(this, &m_randomParticleVertexData, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_POSITION) | (1 << KRMesh::KRENGINE_ATTRIB_TEXCOORD0), false, KRVBOData::CONSTANT #if KRENGINE_DEBUG_GPU_LABELS , "Random Particles [built-in]" #endif