aboutsummaryrefslogtreecommitdiff
path: root/include/RenderBackend
diff options
context:
space:
mode:
Diffstat (limited to 'include/RenderBackend')
-rw-r--r--include/RenderBackend/OpenGL/DeviceFrame.hpp26
-rw-r--r--include/RenderBackend/OpenGL/DeviceMemory.hpp37
-rw-r--r--include/RenderBackend/OpenGL/ShaderFrame.hpp35
-rw-r--r--include/RenderBackend/OpenGL/ShaderProgram.hpp14
-rw-r--r--include/RenderBackend/OpenGL/Texture2D.hpp3
-rw-r--r--include/RenderBackend/OpenGL/Uniform.hpp2
6 files changed, 58 insertions, 59 deletions
diff --git a/include/RenderBackend/OpenGL/DeviceFrame.hpp b/include/RenderBackend/OpenGL/DeviceFrame.hpp
deleted file mode 100644
index 3fa7fe7..0000000
--- a/include/RenderBackend/OpenGL/DeviceFrame.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-#include "../../types.hpp"
-#include "../../utils.hpp"
-#include <vector>
-
-namespace amalgine
-{
- class DeviceMemory;
- class ShaderProgram;
-
- class DeviceFrame
- {
- DISABLE_COPY(DeviceFrame)
- public:
- DeviceFrame();
- ~DeviceFrame();
-
- // The returned pointers cleaned when the frame is cleaned. Do not deallocate the returned pointer!
- DeviceMemory* alloc();
- void draw(ShaderProgram *shader);
- private:
- u32 vertexArrayObjectId;
- std::vector<DeviceMemory*> buffers;
- };
-}
diff --git a/include/RenderBackend/OpenGL/DeviceMemory.hpp b/include/RenderBackend/OpenGL/DeviceMemory.hpp
index 5f593fc..802230d 100644
--- a/include/RenderBackend/OpenGL/DeviceMemory.hpp
+++ b/include/RenderBackend/OpenGL/DeviceMemory.hpp
@@ -5,6 +5,8 @@
#include "../../Triangle.hpp"
#include "../../Vec.hpp"
+#include <memory>
+
namespace amalgine {
enum class DeviceMemoryType {
NONE,
@@ -12,11 +14,10 @@ namespace amalgine {
VEC3
};
- class DeviceMemory
- {
+ class DeviceMemory {
DISABLE_COPY(DeviceMemory)
- friend class DeviceFrame;
- friend class ShaderProgram;
+ friend class ShaderFrame;
+ friend class std::default_delete<DeviceMemory>;
public:
enum class StorageType
{
@@ -30,26 +31,20 @@ namespace amalgine {
STREAM
};
- enum class PrimitiveType
- {
- TRIANGLE
- };
-
- //void copy(const DataView<f32> &data, StorageType storageType, PrimitiveType primitiveType = PrimitiveType::TRIANGLE);
- void copy(const DataView<vec2f> &texture_coords, StorageType storageType);
- void copy(const DataView<Triangle2D> &triangles, StorageType storageType);
- void copy(const DataView<Triangle3D> &triangles, StorageType storageType);
- void draw();
+ void set(const DataView<vec2f> &texture_coords, StorageType storageType);
+ void set(const DataView<Triangle2D> &triangles, StorageType storageType);
+ void set(const DataView<Triangle3D> &triangles, StorageType storageType);
- DeviceMemoryType get_type() const { return type; }
+ i32 get_num_vertices() const { return num_vertices; }
private:
- DeviceMemory();
+ DeviceMemory(u32 vertex_array_object_id, i32 attrib_location);
~DeviceMemory();
- void use() const;
+ void use();
private:
- u32 vertexBufferObjectId;
- u32 primitiveType;
- u32 numVertices;
- DeviceMemoryType type;
+ u32 vertex_array_object_id;
+ u32 vertex_buffer_object_id;
+ i32 attrib_location;
+ i32 num_vertices;
+ DeviceMemoryType memory_type;
};
}
diff --git a/include/RenderBackend/OpenGL/ShaderFrame.hpp b/include/RenderBackend/OpenGL/ShaderFrame.hpp
new file mode 100644
index 0000000..da0918e
--- /dev/null
+++ b/include/RenderBackend/OpenGL/ShaderFrame.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "../../Result.hpp"
+#include "../../types.hpp"
+#include "../../utils.hpp"
+#include "Uniform.hpp"
+#include "DeviceMemory.hpp"
+
+#include <map>
+#include <memory>
+#include <string>
+
+namespace amalgine {
+ class ShaderFrame {
+ DISABLE_COPY(ShaderFrame)
+ friend class ShaderProgram;
+ public:
+ ~ShaderFrame();
+ ShaderFrame(ShaderFrame &&other) = default;
+ ShaderFrame& operator=(ShaderFrame &&other) = default;
+
+ DeviceMemory* get_input_by_name(const char *name);
+ Result<Uniform> get_uniform_by_name(const char *name);
+
+ void draw();
+ private:
+ ShaderFrame(u32 shader_program_id);
+ private:
+ u32 shader_program_id;
+ u32 vertex_array_object_id;
+
+ // TODO: Use a const char* as a key instead
+ std::map<std::string, std::unique_ptr<DeviceMemory>> shader_inputs;
+ };
+}
diff --git a/include/RenderBackend/OpenGL/ShaderProgram.hpp b/include/RenderBackend/OpenGL/ShaderProgram.hpp
index 177e43c..a1db6a0 100644
--- a/include/RenderBackend/OpenGL/ShaderProgram.hpp
+++ b/include/RenderBackend/OpenGL/ShaderProgram.hpp
@@ -3,14 +3,10 @@
#include "../../Result.hpp"
#include "../../types.hpp"
#include "../../utils.hpp"
-#include "../../Vec.hpp"
-#include "Uniform.hpp"
-#include "DeviceMemory.hpp"
+#include "ShaderFrame.hpp"
-#include <vector>
#include <memory>
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/gtc/type_ptr.hpp>
+#include <vector>
namespace amalgine {
class Shader;
@@ -21,11 +17,7 @@ namespace amalgine {
public:
~ShaderProgram();
static Result<std::unique_ptr<ShaderProgram>> build(const std::vector<Shader*> &shaders);
-
- Result<Uniform> get_uniform_by_name(const char *name);
- int set_input_data(const char *name, const DeviceMemory &data);
-
- void use();
+ ShaderFrame create_frame();
private:
ShaderProgram(u32 shader_program_id);
private:
diff --git a/include/RenderBackend/OpenGL/Texture2D.hpp b/include/RenderBackend/OpenGL/Texture2D.hpp
index 48b613b..c0bfbd2 100644
--- a/include/RenderBackend/OpenGL/Texture2D.hpp
+++ b/include/RenderBackend/OpenGL/Texture2D.hpp
@@ -11,9 +11,12 @@ namespace amalgine
{
DISABLE_COPY(Texture2D)
public:
+ Texture2D();
// Not thread safe
Texture2D(Image *image);
~Texture2D();
+ Texture2D(Texture2D &&other);
+ Texture2D& operator=(Texture2D &&other);
i32 get_texture_id() const { return texture_id; }
private:
diff --git a/include/RenderBackend/OpenGL/Uniform.hpp b/include/RenderBackend/OpenGL/Uniform.hpp
index dbffa03..d6e6e64 100644
--- a/include/RenderBackend/OpenGL/Uniform.hpp
+++ b/include/RenderBackend/OpenGL/Uniform.hpp
@@ -11,7 +11,7 @@
namespace amalgine {
class Uniform {
DISABLE_COPY(Uniform)
- friend class ShaderProgram;
+ friend class ShaderFrame;
friend class Result<Uniform>;
public:
Uniform(Uniform&&) = default;