mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-25 16:18:57 +08:00
fixed mesh missing default stride calculation
This commit is contained in:
parent
4c0531a3f3
commit
5a6d2c3de7
|
@ -22,6 +22,7 @@ add_library(blah
|
|||
public/blah/graphics/texture.h
|
||||
public/blah/graphics/framebuffer.h
|
||||
public/blah/graphics/shader.h
|
||||
public/blah/graphics/mesh.cpp
|
||||
public/blah/graphics/mesh.h
|
||||
public/blah/graphics/material.h
|
||||
public/blah/graphics/material.cpp
|
||||
|
|
|
@ -1028,7 +1028,7 @@ namespace Blah
|
|||
return m_id;
|
||||
}
|
||||
|
||||
virtual void vertex_format(const VertexAttribute* attributes, int attribute_count, int stride = -1) override
|
||||
virtual void vertex_format_internal(const VertexAttribute* attributes, int attribute_count, int stride = -1) override
|
||||
{
|
||||
gl.BindVertexArray(m_id);
|
||||
{
|
||||
|
@ -1040,7 +1040,7 @@ namespace Blah
|
|||
gl.BindVertexArray(0);
|
||||
}
|
||||
|
||||
virtual void instance_format(const VertexAttribute* attributes, int attribute_count, int stride = -1) override
|
||||
virtual void instance_format_internal(const VertexAttribute* attributes, int attribute_count, int stride = -1) override
|
||||
{
|
||||
gl.BindVertexArray(m_id);
|
||||
{
|
||||
|
|
51
public/blah/graphics/mesh.cpp
Normal file
51
public/blah/graphics/mesh.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "mesh.h"
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
void Mesh::vertex_format(const VertexAttribute* attributes, int attribute_count, int stride)
|
||||
{
|
||||
if (stride < 0)
|
||||
{
|
||||
stride = 0;
|
||||
|
||||
for (int n = 0; n < attribute_count; n++)
|
||||
{
|
||||
const VertexAttribute* attrib = (attributes + n);
|
||||
|
||||
if (attrib->type == VertexAttributeType::Byte)
|
||||
stride += attrib->components * 1;
|
||||
else if (attrib->type == VertexAttributeType::Short)
|
||||
stride += attrib->components * 2;
|
||||
else if (attrib->type == VertexAttributeType::Int)
|
||||
stride += attrib->components * 4;
|
||||
else if (attrib->type == VertexAttributeType::Float)
|
||||
stride += attrib->components * 4;
|
||||
}
|
||||
}
|
||||
|
||||
vertex_format_internal(attributes, attribute_count, stride);
|
||||
}
|
||||
|
||||
void Mesh::instance_format(const VertexAttribute* attributes, int attribute_count, int stride)
|
||||
{
|
||||
if (stride < 0)
|
||||
{
|
||||
stride = 0;
|
||||
|
||||
for (int n = 0; n < attribute_count; n++)
|
||||
{
|
||||
const VertexAttribute* attrib = (attributes + n);
|
||||
|
||||
if (attrib->type == VertexAttributeType::Byte)
|
||||
stride += attrib->components * 1;
|
||||
else if (attrib->type == VertexAttributeType::Short)
|
||||
stride += attrib->components * 2;
|
||||
else if (attrib->type == VertexAttributeType::Int)
|
||||
stride += attrib->components * 4;
|
||||
else if (attrib->type == VertexAttributeType::Float)
|
||||
stride += attrib->components * 4;
|
||||
}
|
||||
}
|
||||
|
||||
instance_format_internal(attributes, attribute_count, stride);
|
||||
}
|
|
@ -11,10 +11,10 @@ namespace Blah
|
|||
virtual ~Mesh() = default;
|
||||
|
||||
// Sets the Vertex Format of the Mesh
|
||||
virtual void vertex_format(const VertexAttribute* attributes, int attribute_count, int stride = -1) = 0;
|
||||
void vertex_format(const VertexAttribute* attributes, int attribute_count, int stride = -1);
|
||||
|
||||
// Sets the Instance Format of the Mesh
|
||||
virtual void instance_format(const VertexAttribute* attributes, int attribute_count, int stride = -1) = 0;
|
||||
void instance_format(const VertexAttribute* attributes, int attribute_count, int stride = -1);
|
||||
|
||||
// Uploads the given index buffer to the Mesh
|
||||
virtual void index_data(const void* indices, int64_t count) = 0;
|
||||
|
@ -41,6 +41,10 @@ namespace Blah
|
|||
|
||||
// Destroys the given Mesh
|
||||
virtual void dispose() = 0;
|
||||
|
||||
protected:
|
||||
virtual void vertex_format_internal(const VertexAttribute* attributes, int count, int stride) = 0;
|
||||
virtual void instance_format_internal(const VertexAttribute* attributes, int count, int stride) = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Mesh> MeshRef;
|
||||
|
|
Loading…
Reference in New Issue
Block a user