diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-02-14 10:43:26 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 15:22:09 +0100 |
commit | 83c78e2b5cc9b0cb737ec3785722ae280bd29b65 (patch) | |
tree | 8c1f522bc19d4adc7df849fe09f8afc9513f9d65 /src/RenderBackend/OpenGL | |
parent | 23a37b2cdd8ffde8bb85a4159888bf3a7ec35966 (diff) |
Use shader from file..
Diffstat (limited to 'src/RenderBackend/OpenGL')
-rw-r--r-- | src/RenderBackend/OpenGL/DeviceMemory.cpp | 9 | ||||
-rw-r--r-- | src/RenderBackend/OpenGL/ShaderProgram.cpp | 19 | ||||
-rw-r--r-- | src/RenderBackend/OpenGL/Uniform.cpp | 24 |
3 files changed, 44 insertions, 8 deletions
diff --git a/src/RenderBackend/OpenGL/DeviceMemory.cpp b/src/RenderBackend/OpenGL/DeviceMemory.cpp index 2d40569..f071cd8 100644 --- a/src/RenderBackend/OpenGL/DeviceMemory.cpp +++ b/src/RenderBackend/OpenGL/DeviceMemory.cpp @@ -65,6 +65,15 @@ namespace amalgine numVertices = triangles.size * 3; type = DeviceMemoryType::VEC2; } + + void DeviceMemory::copy(const DataView<Triangle3D> &triangles, StorageType storageType) + { + glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); + glBufferData(GL_ARRAY_BUFFER, triangles.getByteSize(), triangles.data, getOpenglStorageType(storageType)); + primitiveType = GL_TRIANGLES; + numVertices = triangles.size * 3; + type = DeviceMemoryType::VEC3; + } void DeviceMemory::draw() { diff --git a/src/RenderBackend/OpenGL/ShaderProgram.cpp b/src/RenderBackend/OpenGL/ShaderProgram.cpp index e613668..389a929 100644 --- a/src/RenderBackend/OpenGL/ShaderProgram.cpp +++ b/src/RenderBackend/OpenGL/ShaderProgram.cpp @@ -64,13 +64,13 @@ namespace amalgine { return Result<std::unique_ptr<ShaderProgram>>::Ok(std::move(shader_program)); } - int ShaderProgram::set_uniform(const char *name, const vec3f &value) { - GLint uniformId = glGetUniformLocation(program_id, name); - if(uniformId == -1) - return -1; - use(); - glUniform3f(uniformId, value.x, value.y, value.z); - return 0; + Result<Uniform> ShaderProgram::get_uniform_by_name(const char *name) { + GLint uniform_id = glGetUniformLocation(program_id, name); + if(uniform_id == -1) + return Result<Uniform>::Err(std::string("Uniform with name ") + name + " was not found"); + + Uniform uniform(uniform_id, program_id); + return Result<Uniform>::Ok(std::move(uniform)); } int ShaderProgram::set_vertex_input(const char *name, const DeviceMemory &data) { @@ -88,7 +88,10 @@ namespace amalgine { glVertexAttribPointer(attrib_location, 2, GL_FLOAT, GL_FALSE, 0, 0); break; } - case DeviceMemoryType::VEC3: assert(false); return -1; + case DeviceMemoryType::VEC3: { + glVertexAttribPointer(attrib_location, 3, GL_FLOAT, GL_FALSE, 0, 0); + break; + } } glEnableVertexAttribArray(attrib_location); return 0; diff --git a/src/RenderBackend/OpenGL/Uniform.cpp b/src/RenderBackend/OpenGL/Uniform.cpp new file mode 100644 index 0000000..67cf3c6 --- /dev/null +++ b/src/RenderBackend/OpenGL/Uniform.cpp @@ -0,0 +1,24 @@ +#include "../../../include/RenderBackend/OpenGL/Uniform.hpp" +#include "../../../include/RenderBackend/OpenGL/opengl.hpp" + +namespace amalgine { + Uniform::~Uniform() {} + + void Uniform::set(const vec3f &value) { + use(); + glUniform3f(uniform_id, value.x, value.y, value.z); + } + + void Uniform::set(const glm::mat4 &value) { + use(); + glUniformMatrix4fv(uniform_id, 1, GL_FALSE, glm::value_ptr(value)); + } + + Uniform::Uniform(i32 uniform_id, u32 shader_program_id) : uniform_id(uniform_id), program_id(shader_program_id) { + + } + + void Uniform::use() { + glUseProgram(program_id); + } +}
\ No newline at end of file |