diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-27 21:52:21 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 15:21:48 +0100 |
commit | 2d8b61bf9fc36e933a0091e1098e62faf143412c (patch) | |
tree | 6b82990f2f61e0c55085ef65ebaa21e41e55dd43 /src | |
parent | ce271c4c6d0f9c440d90397c07eaa96b0443ff47 (diff) |
Add triangle type
Diffstat (limited to 'src')
-rw-r--r-- | src/RenderBackend/OpenGL/DeviceMemory.cpp | 12 | ||||
-rw-r--r-- | src/main.cpp | 21 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/RenderBackend/OpenGL/DeviceMemory.cpp b/src/RenderBackend/OpenGL/DeviceMemory.cpp index faf2943..fb9dec5 100644 --- a/src/RenderBackend/OpenGL/DeviceMemory.cpp +++ b/src/RenderBackend/OpenGL/DeviceMemory.cpp @@ -49,7 +49,7 @@ namespace amalgine // TODO: Bind vao here? glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); } - + /* void DeviceMemory::copy(const DataView<f32> &data, StorageType storageType, PrimitiveType primitiveType) { glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); @@ -57,11 +57,19 @@ namespace amalgine this->primitiveType = getOpenglPrimitiveType(primitiveType); numVertices = getPrimitiveTypePointsPerVertices(primitiveType); } + */ + void DeviceMemory::copy(const DataView<Triangle2D> &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; + } void DeviceMemory::draw() { if(primitiveType == 0) throw DeviceMemoryEmpty("Unable to draw buffer as no data has been copied to device memory"); - glDrawArrays(primitiveType, 0, 3); + glDrawArrays(primitiveType, 0, numVertices); } } diff --git a/src/main.cpp b/src/main.cpp index 0e72df0..a04fb99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "../include/RenderBackend/OpenGL/ShaderProgram.hpp" #include "../include/RenderBackend/OpenGL/DeviceMemory.hpp" #include "../include/RenderBackend/OpenGL/DeviceFrame.hpp" +#include "../include/Triangle2D.hpp" // TODO: Disallow shader variables that begin with "gl_" as reserved variables // start with that. What about hlsl? @@ -29,17 +30,17 @@ int main() DeviceFrame frame; - f32 verticesRaw[] = - { - 0.0f, 0.5f, - 0.5f, -0.5f, - -0.5f, -0.5f - }; - DeviceMemory *triangle = frame.alloc(); - DataView<f32> vertices(verticesRaw, 6); - triangle->copy(vertices, DeviceMemory::StorageType::STATIC); + Triangle2D cpuTriangle( + Vertex2D(0.0f, 0.5f), + Vertex2D(0.5f, -0.5f), + Vertex2D(-0.5f, -0.5f) + ); + + DeviceMemory *gpuTriangle = frame.alloc(); + DataView<Triangle2D> triangles(&cpuTriangle, 1); + gpuTriangle->copy(triangles, DeviceMemory::StorageType::STATIC); - CompiledVertexShader *vertexShader = createVertexShader(*triangle); + CompiledVertexShader *vertexShader = createVertexShader(*gpuTriangle); CompiledPixelShader *pixelShader = createPixelShader(); ShaderProgram shaderProgram; |