About to have to look at shader code again.

This commit is contained in:
2023-11-13 01:42:00 -06:00
parent e3c484d20d
commit 214082d00f
12 changed files with 171 additions and 60 deletions

View File

@ -33,6 +33,12 @@ namespace Dawn {
uint32_t fontSize;
flag_t style;
/**
* Overload for the less than operator.
*
* @param r Right hand side of the operator.
* @return True if the left hand side is less than the right hand side.
*/
bool operator < (const struct TrueTypeFaceTextureStyle& r) const {
return std::tie(fontSize, style) < std::tie(r.fontSize, r.style);
}

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "CapsuleMesh.hpp"
#include "util/mathutils.hpp"
using namespace Dawn;

View File

@ -5,11 +5,21 @@
#pragma once
#include "display/mesh/Mesh.hpp"
#include "util/mathutils.hpp"
namespace Dawn {
class CapsuleMesh {
protected:
/**
* Calculates a ring of vertices within a capsule.
*
* @param segments Count of segments in the ring.
* @param height Height of the ring.
* @param radius Radius of the ring.
* @param dr The delta radius of the ring.
* @param y The y position of the ring.
* @param dy The delta y position of the ring.
* @param positions The positions vector to push the positions to.
*/
static void calculateRing(
const int32_t segments,
const float_t height,
@ -21,6 +31,13 @@ namespace Dawn {
);
public:
/**
* Creates a capsule mesh.
*
* @param mesh Mesh to instanciate.
* @param radius Radius of the capsule.
* @param height Height of the capsule.
*/
static void create(
Mesh &mesh,
const float_t radius,

View File

@ -12,6 +12,15 @@
namespace Dawn {
class CubeMesh {
public:
/**
* Buffers cube mesh vertices onto a mesh.
*
* @param mesh Mesh to buffer onto.
* @param pos Position of the cube.
* @param size Size of the cube.
* @param verticeStart Starting vertice index.
* @param indiceStart Starting indice index.
*/
static void buffer(
Mesh &mesh,
const glm::vec3 pos,

View File

@ -4,14 +4,15 @@
// https://opensource.org/licenses/MIT
#include "SphereMesh.hpp"
#include "util/mathutils.hpp"
using namespace Dawn;
void SphereMesh::createSphere(
Mesh *mesh,
float_t radius,
int32_t slices,
int32_t stacks
Mesh &mesh,
const float_t radius,
const int32_t slices,
const int32_t stacks
) {
std::vector<glm::vec3> positions;
@ -53,7 +54,7 @@ void SphereMesh::createSphere(
}
}
mesh->createBuffers(positions.size(), indices.size());
mesh->bufferPositions(0, positions.data(), positions.size());
mesh->bufferIndices(0, indices.data(), indices.size());
mesh.createBuffers(positions.size(), indices.size());
mesh.bufferPositions(0, positions.data(), positions.size());
mesh.bufferIndices(0, indices.data(), indices.size());
}

View File

@ -5,16 +5,23 @@
#pragma once
#include "display/mesh/Mesh.hpp"
#include "util/mathutils.hpp"
namespace Dawn {
class SphereMesh {
public:
/**
* Creates a sphere mesh.
*
* @param mesh Mesh to instanciate.
* @param radius Radius of the sphere.
* @param slices How many horizontal slices to make.
* @param stacks How many vertical stacks to make.
*/
static void createSphere(
Mesh *mesh,
float_t radius,
int32_t slices,
int32_t stacks
Mesh &mesh,
const float_t radius,
const int32_t slices,
const int32_t stacks
);
};
}

View File

@ -7,9 +7,7 @@
using namespace Dawn;
void TriangleMesh::createTriangleMesh(Mesh *mesh) {
assertNotNull(mesh, "TriangleMesh::createTriangleMesh: Mesh cannot be null");
void TriangleMesh::createTriangleMesh(Mesh &mesh) {
glm::vec3 positions[3] = {
glm::vec3(-0.5f, -0.5f, 0),
glm::vec3(0.5f, -0.5f, 0),
@ -26,8 +24,8 @@ void TriangleMesh::createTriangleMesh(Mesh *mesh) {
0, 1, 2
};
mesh->createBuffers(3, 3);
mesh->bufferPositions(0, positions, 3);
mesh->bufferCoordinates(0, coordinates, 3);
mesh->bufferIndices(0, indices, 3);
mesh.createBuffers(3, 3);
mesh.bufferPositions(0, positions, 3);
mesh.bufferCoordinates(0, coordinates, 3);
mesh.bufferIndices(0, indices, 3);
}

View File

@ -14,6 +14,6 @@ namespace Dawn {
*
* @param mesh Mesh to initialize as a triangle.
*/
static void createTriangleMesh(Mesh *mesh);
static void createTriangleMesh(Mesh &mesh);
};
}

View File

@ -4,8 +4,6 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "display/mesh/Mesh.hpp"
#include "display/IRenderManager.hpp"
#include "display/Texture.hpp"
#include "display/shader/ShaderParameterBuffer.hpp"
@ -33,7 +31,10 @@ namespace Dawn {
* @param buffer Buffer to bind.
*/
template<typename J>
void setParameterBuffer(shaderbufferslot_t slot, ShaderParameterBuffer<J> *buffer);
void setParameterBuffer(
const shaderbufferslot_t slot,
const ShaderParameterBuffer<J> &buffer
);
/**
* Set's a specific shader parameter to a matrix.
@ -41,7 +42,10 @@ namespace Dawn {
* @param parameter parameter on the shader to set.
* @param matrix Matrix to apply.
*/
virtual void setMatrix(T parameter, glm::mat4 matrix) = 0;
virtual void setMatrix(
const T parameter,
const glm::mat4 matrix
) = 0;
/**
* Attaches a boolean to a shader.
@ -49,7 +53,10 @@ namespace Dawn {
* @param parameter parameter to set.
* @param value Value to set.
*/
virtual void setBoolean(T parameter, bool_t value) = 0;
virtual void setBoolean(
const T parameter,
const bool_t value
) = 0;
/**
* Set a color on to the shader.
@ -57,7 +64,10 @@ namespace Dawn {
* @param parameter parameter to set the color to.
* @param color Color to set.
*/
virtual void setColor(T parameter, struct Color color) = 0;
virtual void setColor(
const T parameter,
const struct Color color
) = 0;
/**
* Set a 3D vector on to the shader.
@ -65,7 +75,10 @@ namespace Dawn {
* @param parameter parameter to set the vector to.
* @param vector Vector to set.
*/
virtual void setVector3(T parameter, glm::vec3 vector) = 0;
virtual void setVector3(
const T parameter,
const glm::vec3 vector
) = 0;
/**
* Attaches a texture to the currently bound shader.
@ -73,7 +86,10 @@ namespace Dawn {
* @param parameter parameter to set the texture on to.
* @param texture Texture slot to bind to the parameter.
*/
virtual void setTexture(T parameter, textureslot_t texture) = 0;
virtual void setTexture(
const T parameter,
const textureslot_t texture
) = 0;
/**
* Sets a floating point value to the shader.
@ -81,6 +97,16 @@ namespace Dawn {
* @param parameter Paramater to set the float ont o.
* @param Float to bind.
*/
virtual void setFloat(T parameter, float_t value) = 0;
virtual void setFloat(
const T parameter,
const float_t value
) = 0;
/**
* Destroys/Cleans up the shader.
*/
virtual ~IShader() {
}
};
}

View File

@ -20,6 +20,6 @@ namespace Dawn {
*
* @param location Location to bind this buffer to.
*/
virtual void bind(L location) = 0;
virtual void bind(const L location) = 0;
};
}