diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-27 20:54:27 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-27 20:54:27 -0400 |
commit | cc05fdc7396532b329f30decde5583853da92a44 (patch) | |
tree | fc05dd91ef0245acfea1dcf539d4c968a081b5c5 /frontend/shared_cpp/OrthographicRenderer.h | |
parent | 58488f8eabcc61089e0ae4297f38f10cc28d78c7 (diff) |
Drawing an ellipse
Diffstat (limited to 'frontend/shared_cpp/OrthographicRenderer.h')
-rw-r--r-- | frontend/shared_cpp/OrthographicRenderer.h | 49 |
1 files changed, 8 insertions, 41 deletions
diff --git a/frontend/shared_cpp/OrthographicRenderer.h b/frontend/shared_cpp/OrthographicRenderer.h index c72639e..0cdfc78 100644 --- a/frontend/shared_cpp/OrthographicRenderer.h +++ b/frontend/shared_cpp/OrthographicRenderer.h @@ -1,9 +1,12 @@ #pragma once +#include "WebglContext.h" #include "types.h" #include "Shader.h" #include "mathlib.h" +struct WebglContext; + struct OrthographicRenderer { Mat4x4 projection; uint32 shader; @@ -18,7 +21,7 @@ struct OrthographicRenderer { int32 model; } uniforms; - void load(); + void load(WebglContext* context); void render(); void unload(); }; @@ -28,50 +31,14 @@ struct OrthographicVertex { Vector4 color; }; -template <uint32 N> struct OrthographicShape { uint32 vao; uint32 vbo; - OrthographicVertex vertices[N]; + uint32 numVertices = 0; + OrthographicVertex* vertices = NULL; Mat4x4 model; - void load(OrthographicRenderer* renderer); + void load(OrthographicVertex* vertices, uint32 numVertices, OrthographicRenderer* renderer); void render(OrthographicRenderer* renderer); void unload(); -}; - -template <uint32 N> -void OrthographicShape<N>::load(OrthographicRenderer* renderer) { - useShader(renderer->shader); - - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - glGenBuffers(1, &vbo); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, N * sizeof(OrthographicVertex), &vertices[0], GL_STATIC_DRAW); - - glEnableVertexAttribArray(renderer->attributes.position); - glVertexAttribPointer(renderer->attributes.position, 2, GL_FLOAT, GL_FALSE, sizeof(OrthographicVertex), (GLvoid *)0); - - glEnableVertexAttribArray(renderer->attributes.color); - glVertexAttribPointer(renderer->attributes.color, 4, GL_FLOAT, GL_FALSE, sizeof(OrthographicVertex), (GLvoid *)offsetof(OrthographicVertex, color)); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0); -} - -template <uint32 N> -void OrthographicShape<N>::render(OrthographicRenderer* renderer) { - setShaderMat4(renderer->uniforms.model, model); - - glBindVertexArray(vao); - glDrawArrays(GL_TRIANGLES, 0, 3); - glBindVertexArray(0); -} - -template <uint32 N> -void OrthographicShape<N>::unload() { - glDeleteVertexArrays(1, &vao); - glDeleteBuffers(1, &vbo); -}
\ No newline at end of file +};
\ No newline at end of file |