Testing textures and events
This commit is contained in:
@ -7,4 +7,7 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
RenderPipeline.cpp
|
||||
)
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(mesh)
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
#include "util/flag.hpp"
|
||||
#include "display/Color.hpp"
|
||||
#include "event/Event.hpp"
|
||||
|
||||
#define RENDER_TARGET_CLEAR_FLAG_COLOR FLAG_DEFINE(0)
|
||||
#define RENDER_TARGET_CLEAR_FLAG_DEPTH FLAG_DEFINE(1)
|
||||
@ -13,6 +14,8 @@
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
public:
|
||||
Event<RenderTarget &, float_t, float_t> eventRenderTargetResized;
|
||||
|
||||
/**
|
||||
* Return the width of the render target.
|
||||
*
|
||||
|
19
src/dawn/display/_Texture.hpp
Normal file
19
src/dawn/display/_Texture.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class ITexture {
|
||||
public:
|
||||
virtual int32_t getWidth() = 0;
|
||||
virtual int32_t getHeight() = 0;
|
||||
virtual void setSize(int32_t width, int32_t height) = 0;
|
||||
virtual void fill(struct Color) = 0;
|
||||
virtual bool_t isReady() = 0;
|
||||
virtual void buffer(struct Color pixels[]) = 0;
|
||||
};
|
||||
}
|
11
src/dawn/display/mesh/CMakeLists.txt
Normal file
11
src/dawn/display/mesh/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TriangleMesh.cpp
|
||||
QuadMesh.cpp
|
||||
)
|
38
src/dawn/display/mesh/QuadMesh.cpp
Normal file
38
src/dawn/display/mesh/QuadMesh.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void QuadMesh::bufferQuadMeshWithZ(
|
||||
Mesh &mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z, int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
mesh.bufferPositions(
|
||||
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
|
||||
glm::vec3(xy0, z),
|
||||
glm::vec3(xy1.x, xy0.y, z),
|
||||
glm::vec3(xy0.x, xy1.y, z),
|
||||
glm::vec3(xy1, z)
|
||||
}}
|
||||
);
|
||||
|
||||
mesh.bufferCoordinates(
|
||||
verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
|
||||
uv0, glm::vec2(uv1.x, uv0.y),
|
||||
glm::vec2(uv0.x, uv1.y), uv1
|
||||
}}
|
||||
);
|
||||
|
||||
mesh.bufferIndices(
|
||||
indiceStart, std::array<meshindice_t, QUAD_INDICE_COUNT>{{
|
||||
verticeStart, verticeStart + 1, verticeStart + 2,
|
||||
verticeStart + 1, verticeStart + 2, verticeStart + 3
|
||||
}}
|
||||
);
|
||||
}
|
53
src/dawn/display/mesh/QuadMesh.hpp
Normal file
53
src/dawn/display/mesh/QuadMesh.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define QUAD_VERTICE_COUNT 4
|
||||
#define QUAD_INDICE_COUNT 6
|
||||
#define QUAD_INDICE_PER_QUAD 2
|
||||
|
||||
namespace Dawn {
|
||||
class QuadMesh {
|
||||
public:
|
||||
/**
|
||||
* Buffers the vertices of a quad onto a primitive.
|
||||
*
|
||||
* @param primitive The primitive to buffer to.
|
||||
* @param xy0 The lower X and Y coordinate.
|
||||
* @param uv0 The lower Xand Y texture coordinate.
|
||||
* @param xy1 The higher X and Y coordinate.
|
||||
* @param uv1 The higher X and Y texture coordinate.
|
||||
* @param z The Z position of the coordinates.
|
||||
* @param verticeStart Start vertice to buffer to.
|
||||
* @param indiceStart Start indice to buffer to.
|
||||
*/
|
||||
static void bufferQuadMeshWithZ(
|
||||
Mesh &mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z, int32_t verticeStart, int32_t indiceStart
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffers the vertices of a quad onto a primitive.
|
||||
*
|
||||
* @param primitive The primitive to buffer to.
|
||||
* @param xy0 The lower X and Y coordinate.
|
||||
* @param uv0 The lower Xand Y texture coordinate.
|
||||
* @param xy1 The higher X and Y coordinate.
|
||||
* @param uv1 The higher X and Y texture coordinate.
|
||||
* @param verticeStart Start vertice to buffer to.
|
||||
* @param indiceStart Start indice to buffer to.
|
||||
*/
|
||||
static void bufferQuadMesh(
|
||||
Mesh &mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
);
|
||||
};
|
||||
}
|
25
src/dawn/display/mesh/TriangleMesh.cpp
Normal file
25
src/dawn/display/mesh/TriangleMesh.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "display/mesh/TriangleMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void TriangleMesh::createTriangleMesh(Mesh &mesh) {
|
||||
mesh.createBuffers(3, 3);
|
||||
mesh.bufferPositions(0, std::array<glm::vec3, 3>{{
|
||||
glm::vec3(-0.5f, -0.5f, 0),
|
||||
glm::vec3(0.5f, -0.5f, 0),
|
||||
glm::vec3(0, 0.5f, 0)
|
||||
}});
|
||||
mesh.bufferCoordinates(0, std::array<glm::vec2, 3>{{
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 0)
|
||||
}});
|
||||
mesh.bufferIndices(0, std::array<meshindice_t,3>{{
|
||||
0, 1, 2
|
||||
}});
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Material;
|
||||
@ -13,7 +13,8 @@ namespace Dawn {
|
||||
SHADER_PARAMETER_TYPE_MATRIX,
|
||||
SHADER_PARAMETER_TYPE_BOOLEAN,
|
||||
SHADER_PARAMETER_TYPE_COLOR,
|
||||
SHADER_PARAMETER_TYPE_VECTOR3
|
||||
SHADER_PARAMETER_TYPE_VECTOR3,
|
||||
SHADER_PARAMETER_TYPE_TEXTURE
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -93,5 +94,13 @@ namespace Dawn {
|
||||
* @param vector Vector to set.
|
||||
*/
|
||||
virtual void setVector3(T parameter, glm::vec3 vector) = 0;
|
||||
|
||||
/**
|
||||
* Attaches a texture to the currently bound shader.
|
||||
*
|
||||
* @param parameter parameter to set the texture on to.
|
||||
* @param texture Texture to bind to the parameter.
|
||||
*/
|
||||
virtual void setTexture(T parameter, std::shared_ptr<Texture> texture)=0;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user