Browse Source

Render: Cleanup buffer

master
Riyyi 4 months ago
parent
commit
21319b93ad
  1. 131
      src/inferno/render/buffer.cpp
  2. 14
      src/inferno/render/buffer.h

131
src/inferno/render/buffer.cpp

@ -5,10 +5,9 @@
*/ */
#include "glad/glad.h" #include "glad/glad.h"
#include "ruc/meta/assert.h"
#include "inferno/core.h"
#include "inferno/render/buffer.h" #include "inferno/render/buffer.h"
#include "ruc/meta/assert.h"
namespace Inferno { namespace Inferno {
@ -43,57 +42,38 @@ uint32_t BufferElement::getTypeSize(const BufferElementType type)
case BufferElementType::None: case BufferElementType::None:
return 0; return 0;
case BufferElementType::Bool: case BufferElementType::Bool:
return sizeof(bool);
case BufferElementType::Bool2: case BufferElementType::Bool2:
return sizeof(bool) * 2;
case BufferElementType::Bool3: case BufferElementType::Bool3:
return sizeof(bool) * 3;
case BufferElementType::Bool4: case BufferElementType::Bool4:
return sizeof(bool) * 4; return sizeof(bool) * getTypeCount(type);
case BufferElementType::Int: case BufferElementType::Int:
return sizeof(int32_t);
case BufferElementType::Int2: case BufferElementType::Int2:
return sizeof(int32_t) * 2;
case BufferElementType::Int3: case BufferElementType::Int3:
return sizeof(int32_t) * 3;
case BufferElementType::Int4: case BufferElementType::Int4:
return sizeof(int32_t) * 4; return sizeof(int32_t) * getTypeCount(type);
case BufferElementType::Uint: case BufferElementType::Uint:
return sizeof(uint32_t);
case BufferElementType::Uint2: case BufferElementType::Uint2:
return sizeof(uint32_t) * 2;
case BufferElementType::Uint3: case BufferElementType::Uint3:
return sizeof(uint32_t) * 3;
case BufferElementType::Uint4: case BufferElementType::Uint4:
return sizeof(uint32_t) * 4; return sizeof(uint32_t) * getTypeCount(type);
case BufferElementType::Float: case BufferElementType::Float:
return sizeof(float);
case BufferElementType::Vec2: case BufferElementType::Vec2:
return sizeof(float) * 2;
case BufferElementType::Vec3: case BufferElementType::Vec3:
return sizeof(float) * 3;
case BufferElementType::Vec4: case BufferElementType::Vec4:
return sizeof(float) * 4; return sizeof(float) * getTypeCount(type);
case BufferElementType::Double: case BufferElementType::VecDouble:
return sizeof(double); case BufferElementType::VecDouble2:
case BufferElementType::Double2: case BufferElementType::VecDouble3:
return sizeof(double); case BufferElementType::VecDouble4:
case BufferElementType::Double3: return sizeof(double) * getTypeCount(type);
return sizeof(double);
case BufferElementType::Double4:
return sizeof(double);
case BufferElementType::Mat2: case BufferElementType::Mat2:
return sizeof(float) * 2 * 2;
case BufferElementType::Mat3: case BufferElementType::Mat3:
return sizeof(float) * 3 * 3;
case BufferElementType::Mat4: case BufferElementType::Mat4:
return sizeof(float) * 4 * 4; return sizeof(float) * getTypeCount(type);
case BufferElementType::DoubleMat2: case BufferElementType::MatDouble2:
return sizeof(double) * 2 * 2; case BufferElementType::MatDouble3:
case BufferElementType::DoubleMat3: case BufferElementType::MatDouble4:
return sizeof(double) * 3 * 3; return sizeof(double) * getTypeCount(type);
case BufferElementType::DoubleMat4:
return sizeof(double) * 4 * 4;
}; };
VERIFY(false, "BufferElement unknown BufferElementType size!"); VERIFY(false, "BufferElement unknown BufferElementType size!");
@ -106,44 +86,28 @@ uint32_t BufferElement::getTypeCount(const BufferElementType type)
case BufferElementType::None: case BufferElementType::None:
return 0; return 0;
case BufferElementType::Bool: case BufferElementType::Bool:
return 1;
case BufferElementType::Bool2:
return 2;
case BufferElementType::Bool3:
return 3;
case BufferElementType::Bool4:
return 4;
case BufferElementType::Int: case BufferElementType::Int:
return 1;
case BufferElementType::Int2:
return 2;
case BufferElementType::Int3:
return 3;
case BufferElementType::Int4:
return 4;
case BufferElementType::Uint: case BufferElementType::Uint:
return 1;
case BufferElementType::Uint2:
return 2;
case BufferElementType::Uint3:
return 3;
case BufferElementType::Uint4:
return 4;
case BufferElementType::Float: case BufferElementType::Float:
case BufferElementType::VecDouble:
return 1; return 1;
case BufferElementType::Bool2:
case BufferElementType::Int2:
case BufferElementType::Uint2:
case BufferElementType::Vec2: case BufferElementType::Vec2:
case BufferElementType::VecDouble2:
return 2; return 2;
case BufferElementType::Bool3:
case BufferElementType::Int3:
case BufferElementType::Uint3:
case BufferElementType::Vec3: case BufferElementType::Vec3:
case BufferElementType::VecDouble3:
return 3; return 3;
case BufferElementType::Bool4:
case BufferElementType::Int4:
case BufferElementType::Uint4:
case BufferElementType::Vec4: case BufferElementType::Vec4:
return 4; case BufferElementType::VecDouble4:
case BufferElementType::Double:
return 1;
case BufferElementType::Double2:
return 2;
case BufferElementType::Double3:
return 3;
case BufferElementType::Double4:
return 4; return 4;
case BufferElementType::Mat2: case BufferElementType::Mat2:
return 2 * 2; return 2 * 2;
@ -151,11 +115,11 @@ uint32_t BufferElement::getTypeCount(const BufferElementType type)
return 3 * 3; return 3 * 3;
case BufferElementType::Mat4: case BufferElementType::Mat4:
return 4 * 4; return 4 * 4;
case BufferElementType::DoubleMat2: case BufferElementType::MatDouble2:
return 2 * 2; return 2 * 2;
case BufferElementType::DoubleMat3: case BufferElementType::MatDouble3:
return 3 * 3; return 3 * 3;
case BufferElementType::DoubleMat4: case BufferElementType::MatDouble4:
return 4 * 4; return 4 * 4;
}; };
@ -169,56 +133,37 @@ uint32_t BufferElement::getTypeGL(const BufferElementType type)
case BufferElementType::None: case BufferElementType::None:
return GL_NONE; return GL_NONE;
case BufferElementType::Bool: case BufferElementType::Bool:
return GL_BOOL;
case BufferElementType::Bool2: case BufferElementType::Bool2:
return GL_BOOL;
case BufferElementType::Bool3: case BufferElementType::Bool3:
return GL_BOOL;
case BufferElementType::Bool4: case BufferElementType::Bool4:
return GL_BOOL; return GL_BOOL;
case BufferElementType::Int: case BufferElementType::Int:
return GL_INT;
case BufferElementType::Int2: case BufferElementType::Int2:
return GL_INT;
case BufferElementType::Int3: case BufferElementType::Int3:
return GL_INT;
case BufferElementType::Int4: case BufferElementType::Int4:
return GL_INT; return GL_INT;
case BufferElementType::Uint: case BufferElementType::Uint:
return GL_UNSIGNED_INT;
case BufferElementType::Uint2: case BufferElementType::Uint2:
return GL_UNSIGNED_INT;
case BufferElementType::Uint3: case BufferElementType::Uint3:
return GL_UNSIGNED_INT;
case BufferElementType::Uint4: case BufferElementType::Uint4:
return GL_UNSIGNED_INT; return GL_UNSIGNED_INT;
case BufferElementType::Float: case BufferElementType::Float:
return GL_FLOAT;
case BufferElementType::Vec2: case BufferElementType::Vec2:
return GL_FLOAT;
case BufferElementType::Vec3: case BufferElementType::Vec3:
return GL_FLOAT;
case BufferElementType::Vec4: case BufferElementType::Vec4:
return GL_FLOAT; return GL_FLOAT;
case BufferElementType::Double: case BufferElementType::VecDouble:
return GL_DOUBLE; case BufferElementType::VecDouble2:
case BufferElementType::Double2: case BufferElementType::VecDouble3:
return GL_DOUBLE; case BufferElementType::VecDouble4:
case BufferElementType::Double3:
return GL_DOUBLE;
case BufferElementType::Double4:
return GL_DOUBLE; return GL_DOUBLE;
case BufferElementType::Mat2: case BufferElementType::Mat2:
return GL_FLOAT;
case BufferElementType::Mat3: case BufferElementType::Mat3:
return GL_FLOAT;
case BufferElementType::Mat4: case BufferElementType::Mat4:
return GL_FLOAT; return GL_FLOAT;
case BufferElementType::DoubleMat2: case BufferElementType::MatDouble2:
return GL_DOUBLE; case BufferElementType::MatDouble3:
case BufferElementType::DoubleMat3: case BufferElementType::MatDouble4:
return GL_DOUBLE;
case BufferElementType::DoubleMat4:
return GL_DOUBLE; return GL_DOUBLE;
}; };

14
src/inferno/render/buffer.h

@ -18,13 +18,13 @@ namespace Inferno {
// https://www.khronos.org/opengl/wiki/Data_Type_(GLSL) // https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)
enum class BufferElementType { enum class BufferElementType {
None = 0, None = 0,
Bool, Bool2, Bool3, Bool4, // bvec Bool, Bool2, Bool3, Bool4, // bvec
Int, Int2, Int3, Int4, // ivec Int, Int2, Int3, Int4, // ivec
Uint, Uint2, Uint3, Uint4, // uvec Uint, Uint2, Uint3, Uint4, // uvec
Float, Vec2, Vec3, Vec4, // vec Float, Vec2, Vec3, Vec4, // vec
Double, Double2, Double3, Double4, // dvec VecDouble, VecDouble2, VecDouble3, VecDouble4, // dvec
Mat2, Mat3, Mat4, // mat Mat2, Mat3, Mat4, // mat
DoubleMat2, DoubleMat3, DoubleMat4, // dmat MatDouble2, MatDouble3, MatDouble4, // dmat
}; };
// clang-format on // clang-format on

Loading…
Cancel
Save