aboutsummaryrefslogtreecommitdiff
path: root/src/RenderBackend/OpenGL
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-02-22 08:55:48 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-18 15:22:10 +0100
commit9ab59b76c0ece5e261c0152af3f830f48532e103 (patch)
treeae66d456fa58d4f98ea74759bcc2bb9e2f50efae /src/RenderBackend/OpenGL
parentf2f8ccc1c24ab372ffe5e932780eeb1c49a4d277 (diff)
Fix rendering of character
Diffstat (limited to 'src/RenderBackend/OpenGL')
-rw-r--r--src/RenderBackend/OpenGL/ShaderFrame.cpp30
-rw-r--r--src/RenderBackend/OpenGL/Texture2D.cpp2
2 files changed, 30 insertions, 2 deletions
diff --git a/src/RenderBackend/OpenGL/ShaderFrame.cpp b/src/RenderBackend/OpenGL/ShaderFrame.cpp
index 3f7ff01..dc2653c 100644
--- a/src/RenderBackend/OpenGL/ShaderFrame.cpp
+++ b/src/RenderBackend/OpenGL/ShaderFrame.cpp
@@ -7,7 +7,22 @@ namespace amalgine {
}
ShaderFrame::~ShaderFrame() {
- glDeleteVertexArrays(1, &vertex_array_object_id);
+ if(vertex_array_object_id != -1)
+ glDeleteVertexArrays(1, &vertex_array_object_id);
+ }
+
+ ShaderFrame::ShaderFrame(ShaderFrame &&other) {
+ this->operator=(std::move(other));
+ }
+
+ ShaderFrame& ShaderFrame::operator=(ShaderFrame &&other) {
+ shader_program_id = other.shader_program_id;
+ vertex_array_object_id = other.vertex_array_object_id;
+ shader_inputs = std::move(other.shader_inputs);
+
+ other.shader_program_id = -1;
+ other.vertex_array_object_id = -1;
+ return *this;
}
DeviceMemory* ShaderFrame::get_input_by_name(const char *name) {
@@ -44,10 +59,23 @@ namespace amalgine {
glUseProgram(shader_program_id);
glBindVertexArray(vertex_array_object_id); // Set the active shader to use the data encapsulated by the vertex array object
// TODO: Cache this num_vertices count (and reset it when device memory has changed)
+#if 0
int num_vertices = 0;
for(const auto &it : shader_inputs) {
num_vertices = std::max(num_vertices, it.second->get_num_vertices());
}
+#endif
+ int num_vertices = 0;
+ for(const auto &it : shader_inputs) {
+ int new_num_vertices = std::max(num_vertices, it.second->get_num_vertices());
+#if 0
+ if(num_vertices != 0 && new_num_vertices != num_vertices) {
+ fprintf(stderr, "All inputs for shaders need to be of the same size!\n");
+ abort();
+ }
+#endif
+ num_vertices = new_num_vertices;
+ }
// TODO: Allow specifying mode different than GL_TRIANGLES
glDrawArrays(GL_TRIANGLES, 0, num_vertices);
}
diff --git a/src/RenderBackend/OpenGL/Texture2D.cpp b/src/RenderBackend/OpenGL/Texture2D.cpp
index 7d1b83c..089a5f1 100644
--- a/src/RenderBackend/OpenGL/Texture2D.cpp
+++ b/src/RenderBackend/OpenGL/Texture2D.cpp
@@ -72,9 +72,9 @@ namespace amalgine {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glGenerateMipmap(GL_TEXTURE_2D);
}
Texture2D::~Texture2D()