mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-28 16:58: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/texture.h
|
||||||
public/blah/graphics/framebuffer.h
|
public/blah/graphics/framebuffer.h
|
||||||
public/blah/graphics/shader.h
|
public/blah/graphics/shader.h
|
||||||
|
public/blah/graphics/mesh.cpp
|
||||||
public/blah/graphics/mesh.h
|
public/blah/graphics/mesh.h
|
||||||
public/blah/graphics/material.h
|
public/blah/graphics/material.h
|
||||||
public/blah/graphics/material.cpp
|
public/blah/graphics/material.cpp
|
||||||
|
|
|
@ -1028,7 +1028,7 @@ namespace Blah
|
||||||
return m_id;
|
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);
|
gl.BindVertexArray(m_id);
|
||||||
{
|
{
|
||||||
|
@ -1040,7 +1040,7 @@ namespace Blah
|
||||||
gl.BindVertexArray(0);
|
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);
|
gl.BindVertexArray(m_id);
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,12 +29,12 @@ using namespace Internal;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
SDL_Window* window = nullptr;
|
SDL_Window* window = nullptr;
|
||||||
SDL_Joystick* joysticks[BLAH_MAX_CONTROLLERS];
|
SDL_Joystick* joysticks[BLAH_MAX_CONTROLLERS];
|
||||||
SDL_GameController* gamepads[BLAH_MAX_CONTROLLERS];
|
SDL_GameController* gamepads[BLAH_MAX_CONTROLLERS];
|
||||||
char* basePath = nullptr;
|
char* basePath = nullptr;
|
||||||
char* userPath = nullptr;
|
char* userPath = nullptr;
|
||||||
bool displayed = false;
|
bool displayed = false;
|
||||||
|
|
||||||
void sdl_log(void* userdata, int category, SDL_LogPriority priority, const char* message)
|
void sdl_log(void* userdata, int category, SDL_LogPriority priority, const char* message)
|
||||||
{
|
{
|
||||||
|
|
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;
|
virtual ~Mesh() = default;
|
||||||
|
|
||||||
// Sets the Vertex Format of the Mesh
|
// 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
|
// 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
|
// Uploads the given index buffer to the Mesh
|
||||||
virtual void index_data(const void* indices, int64_t count) = 0;
|
virtual void index_data(const void* indices, int64_t count) = 0;
|
||||||
|
@ -41,6 +41,10 @@ namespace Blah
|
||||||
|
|
||||||
// Destroys the given Mesh
|
// Destroys the given Mesh
|
||||||
virtual void dispose() = 0;
|
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;
|
typedef std::shared_ptr<Mesh> MeshRef;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user