diff --git a/OpenGLEngine/BasicBatch.cpp b/OpenGLEngine/BasicBatch.cpp index 128ac8c..155baae 100644 --- a/OpenGLEngine/BasicBatch.cpp +++ b/OpenGLEngine/BasicBatch.cpp @@ -4,26 +4,29 @@ namespace charcoal { namespace builtin { - void BasicBatch::setup_vao() + namespace basic { - glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(BasicVertex), NULL); - glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - glEnableVertexAttribArray(3); - glEnableVertexAttribArray(4); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); - glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); + void Batch::setup_vao() + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL); + glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glEnableVertexAttribArray(3); + glEnableVertexAttribArray(4); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); + glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); - glVertexAttribDivisor(0, 0); // Send the mesh data once - glVertexAttribDivisor(1, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(0, 0); // Send the mesh data once + glVertexAttribDivisor(1, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn + } } } } diff --git a/OpenGLEngine/BasicBatch.h b/OpenGLEngine/BasicBatch.h index 3a84228..22f7087 100644 --- a/OpenGLEngine/BasicBatch.h +++ b/OpenGLEngine/BasicBatch.h @@ -1,30 +1,33 @@ #pragma once #include "PoseableBatch.h" -#include "BuiltinTypes.h" +#include "BasicTypes.h" namespace charcoal { namespace builtin { - class BasicBatch : public PoseableBatch + namespace basic { - public: - BasicBatch( - BasicRenderable* renderable, - int element_count - ) : PoseableBatch(renderable, element_count) - {} + class Batch : public PoseableBatch + { + public: + Batch( + Renderable* renderable, + int element_count + ) : PoseableBatch(renderable, element_count) + {} - BasicBatch( - BasicRenderable* renderable, - int element_count, - int element_render_count - ) : PoseableBatch(renderable, element_count, element_render_count) - {} + Batch( + Renderable* renderable, + int element_count, + int element_render_count + ) : PoseableBatch(renderable, element_count, element_render_count) + {} - protected: - void setup_vao() override; - }; + protected: + void setup_vao() override; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/BasicScene.cpp b/OpenGLEngine/BasicScene.cpp index 31d56d1..87bf190 100644 --- a/OpenGLEngine/BasicScene.cpp +++ b/OpenGLEngine/BasicScene.cpp @@ -9,36 +9,39 @@ namespace charcoal { namespace builtin { - void BasicScene::init() + namespace basic { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::init() { - BasicBatch& batch = *iter; - batch.init(); - add_prerenderable(&batch); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + Batch& batch = *iter; + batch.init(); + add_prerenderable(&batch); + } } - } - void BasicScene::use() - { - // TODO: move to glutil - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - } - - void BasicScene::unuse() - { - - } - - void BasicScene::render() - { - glutil::clear_screen(); - m_shader_program.use(); - glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::use() { - iter->render(); + // TODO: move to glutil + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + } + + void Scene::unuse() + { + + } + + void Scene::render() + { + glutil::clear_screen(); + m_shader_program.use(); + glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->render(); + } } } } diff --git a/OpenGLEngine/BasicScene.h b/OpenGLEngine/BasicScene.h index 61ca859..28ad936 100644 --- a/OpenGLEngine/BasicScene.h +++ b/OpenGLEngine/BasicScene.h @@ -2,10 +2,11 @@ #include +#include "Application.h" #include "AutoPrerenderingScene.h" #include "BasicShaderProgram.h" -#include "BuiltinTypes.h" +#include "BasicTypes.h" #include "Camera.h" #include "Batched.h" #include "BasicBatch.h" @@ -16,26 +17,29 @@ namespace charcoal { namespace builtin { - class BasicScene : public AutoPrerenderingScene, public Batched + namespace basic { - public: - BasicScene(Application& application) : AutoPrerenderingScene(application) {} - virtual ~BasicScene() {} + class Scene : public AutoPrerenderingScene, public Batched + { + public: + Scene(Application& application) : AutoPrerenderingScene(application) {} + virtual ~Scene() {} - void init() override; + void init() override; - void use() override; + void use() override; - void unuse() override; + void unuse() override; - void render() override; + void render() override; - protected: - void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } + protected: + void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } - private: - BasicShaderProgram m_shader_program; - const Camera* m_p_camera = nullptr; - }; + private: + ShaderProgram m_shader_program; + const Camera* m_p_camera = nullptr; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/BasicShaderProgram.h b/OpenGLEngine/BasicShaderProgram.h index 8181135..82ee15b 100644 --- a/OpenGLEngine/BasicShaderProgram.h +++ b/OpenGLEngine/BasicShaderProgram.h @@ -6,10 +6,13 @@ namespace charcoal { namespace builtin { - class BasicShaderProgram : public VertexFragmentShaderProgram + namespace basic { - public: - BasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "BasicVS.glsl", SHADER_PATH "BasicFS.glsl") {} - }; + class ShaderProgram : public VertexFragmentShaderProgram + { + public: + ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "BasicVS.glsl", SHADER_PATH "BasicFS.glsl") {} + }; + } } } diff --git a/OpenGLEngine/BasicTypes.h b/OpenGLEngine/BasicTypes.h new file mode 100644 index 0000000..d9cab10 --- /dev/null +++ b/OpenGLEngine/BasicTypes.h @@ -0,0 +1,16 @@ +#pragma once + +#include "BuiltinTypes.h" + +namespace charcoal +{ + namespace builtin + { + namespace basic + { + typedef PVertex Vertex; + typedef Index Index; + typedef RenderableT Renderable; + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/Batch.h b/OpenGLEngine/Batch.h index deda0c5..2d11ac9 100644 --- a/OpenGLEngine/Batch.h +++ b/OpenGLEngine/Batch.h @@ -5,11 +5,13 @@ #include #include +#include "Renderable.h" + #include "Exception.h" namespace charcoal { - template > + template > class Batch { public: diff --git a/OpenGLEngine/BuiltinBatch.h b/OpenGLEngine/BuiltinBatch.h index d9cc323..b2c170c 100644 --- a/OpenGLEngine/BuiltinBatch.h +++ b/OpenGLEngine/BuiltinBatch.h @@ -7,16 +7,16 @@ namespace charcoal { namespace builtin { - template > - class Batch : public Prerenderable, public charcoal::Batch + template > + class Batch : public Prerenderable, public charcoal::Batch { public: Batch( - const Renderable* renderable, + const RenderableT* renderable, int element_render_count - ) : charcoal::Batch(renderable, element_render_count) {} + ) : charcoal::Batch(renderable, element_render_count) {} - void prerender() override { charcoal::Batch::prerender(); } + void prerender() override { charcoal::Batch::prerender(); } }; } } \ No newline at end of file diff --git a/OpenGLEngine/BuiltinTypes.h b/OpenGLEngine/BuiltinTypes.h index 0c2e1a7..76d65e3 100644 --- a/OpenGLEngine/BuiltinTypes.h +++ b/OpenGLEngine/BuiltinTypes.h @@ -99,23 +99,5 @@ namespace charcoal Position position; UV uv; }; - - // typedefs for builtin types - - typedef PVertex BasicVertex; - typedef Index BasicIndex; - typedef Renderable BasicRenderable; - - typedef PNMVertex LitVertex; - typedef Index LitIndex; - typedef Renderable LitRenderable; - - typedef PNMVertex LitShadowedVertex; - typedef Index LitShadowedIndex; - typedef Renderable LitShadowedRenderable; - - typedef PTVertex TexturedVertex; - typedef Index TexturedIndex; - typedef TextureRenderable TexturedRenderable; } } \ No newline at end of file diff --git a/OpenGLEngine/LitBatch.cpp b/OpenGLEngine/LitBatch.cpp index 501c977..747024f 100644 --- a/OpenGLEngine/LitBatch.cpp +++ b/OpenGLEngine/LitBatch.cpp @@ -4,32 +4,35 @@ namespace charcoal { namespace builtin { - void LitBatch::setup_vao() + namespace lit { - glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, position))); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, normal))); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, material))); - glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); - glEnableVertexAttribArray(3); - glEnableVertexAttribArray(4); - glEnableVertexAttribArray(5); - glEnableVertexAttribArray(6); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); - glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); - glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); - glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); + void Batch::setup_vao() + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, position))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, normal))); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, material))); + glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); + glEnableVertexAttribArray(3); + glEnableVertexAttribArray(4); + glEnableVertexAttribArray(5); + glEnableVertexAttribArray(6); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); + glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); + glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); + glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); - glVertexAttribDivisor(0, 0); // Send the mesh data once - glVertexAttribDivisor(1, 0); // Send the mesh data once - glVertexAttribDivisor(2, 0); // Send the mesh data once - glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(0, 0); // Send the mesh data once + glVertexAttribDivisor(1, 0); // Send the mesh data once + glVertexAttribDivisor(2, 0); // Send the mesh data once + glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn + } } } } \ No newline at end of file diff --git a/OpenGLEngine/LitBatch.h b/OpenGLEngine/LitBatch.h index f20afa1..902ec08 100644 --- a/OpenGLEngine/LitBatch.h +++ b/OpenGLEngine/LitBatch.h @@ -1,30 +1,33 @@ #pragma once #include "PoseableBatch.h" -#include "BuiltinTypes.h" +#include "LitTypes.h" namespace charcoal { namespace builtin { - class LitBatch : public PoseableBatch + namespace lit { - public: - LitBatch( - LitRenderable* renderable, - int element_count - ) : PoseableBatch(renderable, element_count) - {} + class Batch : public PoseableBatch + { + public: + Batch( + Renderable* renderable, + int element_count + ) : PoseableBatch(renderable, element_count) + {} - LitBatch( - LitRenderable* renderable, - int element_count, - int element_render_count - ) : PoseableBatch(renderable, element_count, element_render_count) - {} + Batch( + Renderable* renderable, + int element_count, + int element_render_count + ) : PoseableBatch(renderable, element_count, element_render_count) + {} - protected: - void setup_vao() override; - }; + protected: + void setup_vao() override; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/LitScene.cpp b/OpenGLEngine/LitScene.cpp index a1e03db..18304fd 100644 --- a/OpenGLEngine/LitScene.cpp +++ b/OpenGLEngine/LitScene.cpp @@ -10,39 +10,42 @@ namespace charcoal { namespace builtin { - void LitScene::init() + namespace lit { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::init() { - LitBatch& batch = *iter; - batch.init(); - add_prerenderable(&batch); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + Batch& batch = *iter; + batch.init(); + add_prerenderable(&batch); + } } - } - void LitScene::use() - { - // TODO: move to glutil - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - } - - void LitScene::unuse() - { - - } - - void LitScene::render() - { - glutil::clear_screen(); - m_shader_program.use(); - glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); - glutil::uniform_vec3(4, m_p_camera->get_position()); - glutil::uniform_uint(5, (unsigned int)m_lights.size()); - glutil::uniform_lights(6, m_lights); - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::use() { - iter->render(); + // TODO: move to glutil + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + } + + void Scene::unuse() + { + + } + + void Scene::render() + { + glutil::clear_screen(); + m_shader_program.use(); + glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); + glutil::uniform_vec3(4, m_p_camera->get_position()); + glutil::uniform_uint(5, (unsigned int)m_lights.size()); + glutil::uniform_lights(6, m_lights); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->render(); + } } } } diff --git a/OpenGLEngine/LitScene.h b/OpenGLEngine/LitScene.h index bbe499c..f464b3b 100644 --- a/OpenGLEngine/LitScene.h +++ b/OpenGLEngine/LitScene.h @@ -3,7 +3,7 @@ #include #include "AutoPrerenderingScene.h" -#include "BuiltinTypes.h" +#include "LitTypes.h" #include "Camera.h" #include "Batched.h" #include "LitBatch.h" @@ -13,41 +13,44 @@ namespace charcoal { namespace builtin { - // A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model ) - class LitScene : public AutoPrerenderingScene, public Batched + namespace lit { - public: - LitScene(Application& application) : AutoPrerenderingScene(application) {} - virtual ~LitScene() {} - - void init() override; - - void use() override; - - void unuse() override; - - void render() override; - - protected: - void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } - - Light& add_light( - const Position& position, - const Light::Power& power, - const ColorRGB ambient, - const ColorRGB diffuse, - const ColorRGB specular, - const Light::Fade& fade - ) + // A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model ) + class Scene : public AutoPrerenderingScene, public Batched { - m_lights.emplace_back(position, power, ambient, diffuse, specular, fade); - return m_lights.back(); - } + public: + Scene(Application& application) : AutoPrerenderingScene(application) {} + virtual ~Scene() {} - private: - LitShaderProgram m_shader_program; - const Camera* m_p_camera = nullptr; - std::vector m_lights; - }; + void init() override; + + void use() override; + + void unuse() override; + + void render() override; + + protected: + void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } + + Light& add_light( + const Position& position, + const Light::Power& power, + const ColorRGB ambient, + const ColorRGB diffuse, + const ColorRGB specular, + const Light::Fade& fade + ) + { + m_lights.emplace_back(position, power, ambient, diffuse, specular, fade); + return m_lights.back(); + } + + private: + ShaderProgram m_shader_program; + const Camera* m_p_camera = nullptr; + std::vector m_lights; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/LitShaderProgram.h b/OpenGLEngine/LitShaderProgram.h index 12d207c..1c8b589 100644 --- a/OpenGLEngine/LitShaderProgram.h +++ b/OpenGLEngine/LitShaderProgram.h @@ -6,11 +6,14 @@ namespace charcoal { namespace builtin { - // TODO: Add constatns for the uniform and vertex attribute locations (for all shader programs) - class LitShaderProgram : public VertexFragmentShaderProgram + namespace lit { - public: - LitShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {} - }; + // TODO: Add constants for the uniform and vertex attribute locations (for all shader programs) + class ShaderProgram : public VertexFragmentShaderProgram + { + public: + ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {} + }; + } } } diff --git a/OpenGLEngine/LitShadowedBatch.cpp b/OpenGLEngine/LitShadowedBatch.cpp index 4c5c274..70f666b 100644 --- a/OpenGLEngine/LitShadowedBatch.cpp +++ b/OpenGLEngine/LitShadowedBatch.cpp @@ -4,32 +4,35 @@ namespace charcoal { namespace builtin { - void LitShadowedBatch::setup_vao() + namespace litshadowed { - glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, position))); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, normal))); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(LitVertex), (void*)(offsetof(LitVertex, material))); - glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); - glEnableVertexAttribArray(3); - glEnableVertexAttribArray(4); - glEnableVertexAttribArray(5); - glEnableVertexAttribArray(6); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); - glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); - glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); - glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); + void Batch::setup_vao() + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, position))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, normal))); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, material))); + glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); + glEnableVertexAttribArray(3); + glEnableVertexAttribArray(4); + glEnableVertexAttribArray(5); + glEnableVertexAttribArray(6); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); + glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); + glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); + glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); - glVertexAttribDivisor(0, 0); // Send the mesh data once - glVertexAttribDivisor(1, 0); // Send the mesh data once - glVertexAttribDivisor(2, 0); // Send the mesh data once - glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(0, 0); // Send the mesh data once + glVertexAttribDivisor(1, 0); // Send the mesh data once + glVertexAttribDivisor(2, 0); // Send the mesh data once + glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(6, 1); // Send the offset data for each instance drawn + } } } } \ No newline at end of file diff --git a/OpenGLEngine/LitShadowedBatch.h b/OpenGLEngine/LitShadowedBatch.h index b67e9ab..01cb843 100644 --- a/OpenGLEngine/LitShadowedBatch.h +++ b/OpenGLEngine/LitShadowedBatch.h @@ -1,30 +1,33 @@ #pragma once #include "PoseableBatch.h" -#include "BuiltinTypes.h" +#include "LitShadowedTypes.h" namespace charcoal { namespace builtin { - class LitShadowedBatch : public PoseableBatch + namespace litshadowed { - public: - LitShadowedBatch( - LitRenderable* renderable, - int element_count - ) : PoseableBatch(renderable, element_count) - {} + class Batch : public PoseableBatch + { + public: + Batch( + Renderable* renderable, + int element_count + ) : PoseableBatch(renderable, element_count) + {} - LitShadowedBatch( - LitRenderable* renderable, - int element_count, - int element_render_count - ) : PoseableBatch(renderable, element_count, element_render_count) - {} + Batch( + Renderable* renderable, + int element_count, + int element_render_count + ) : PoseableBatch(renderable, element_count, element_render_count) + {} - protected: - void setup_vao() override; - }; + protected: + void setup_vao() override; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/LitShadowedScene.cpp b/OpenGLEngine/LitShadowedScene.cpp index da2f22e..dcc5f17 100644 --- a/OpenGLEngine/LitShadowedScene.cpp +++ b/OpenGLEngine/LitShadowedScene.cpp @@ -10,39 +10,42 @@ namespace charcoal { namespace builtin { - void LitShadowedScene::init() + namespace litshadowed { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::init() { - LitShadowedBatch& batch = *iter; - batch.init(); - add_prerenderable(&batch); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + Batch& batch = *iter; + batch.init(); + add_prerenderable(&batch); + } } - } - void LitShadowedScene::use() - { - // TODO: move to glutil - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - } - - void LitShadowedScene::unuse() - { - - } - - void LitShadowedScene::render() - { - glutil::clear_screen(); - m_shader_program.use(); - glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); - glutil::uniform_vec3(4, m_p_camera->get_position()); - glutil::uniform_uint(5, (unsigned int)m_lights.size()); - glutil::uniform_lights(6, m_lights); - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::use() { - iter->render(); + // TODO: move to glutil + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + } + + void Scene::unuse() + { + + } + + void Scene::render() + { + glutil::clear_screen(); + m_shader_program.use(); + glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); + glutil::uniform_vec3(4, m_p_camera->get_position()); + glutil::uniform_uint(5, (unsigned int)m_lights.size()); + glutil::uniform_lights(6, m_lights); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->render(); + } } } } diff --git a/OpenGLEngine/LitShadowedScene.h b/OpenGLEngine/LitShadowedScene.h index 782e0b1..aad3a6f 100644 --- a/OpenGLEngine/LitShadowedScene.h +++ b/OpenGLEngine/LitShadowedScene.h @@ -3,7 +3,7 @@ #include #include "AutoPrerenderingScene.h" -#include "BuiltinTypes.h" +#include "LitShadowedTypes.h" #include "Camera.h" #include "Batched.h" #include "LitShadowedBatch.h" @@ -13,41 +13,44 @@ namespace charcoal { namespace builtin { - // A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model ) - class LitShadowedScene : public AutoPrerenderingScene, public Batched + namespace litshadowed { - public: - LitShadowedScene(Application& application) : AutoPrerenderingScene(application) {} - virtual ~LitShadowedScene() {} - - void init() override; - - void use() override; - - void unuse() override; - - void render() override; - - protected: - void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } - - Light& add_light( - const Position& position, - const Light::Power& power, - const ColorRGB ambient, - const ColorRGB diffuse, - const ColorRGB specular, - const Light::Fade& fade - ) + // A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model ) + class Scene : public AutoPrerenderingScene, public Batched { - m_lights.emplace_back(position, power, ambient, diffuse, specular, fade); - return m_lights.back(); - } + public: + Scene(Application& application) : AutoPrerenderingScene(application) {} + virtual ~Scene() {} - private: - LitShadowedShaderProgram m_shader_program; - const Camera* m_p_camera = nullptr; - std::vector m_lights; - }; + void init() override; + + void use() override; + + void unuse() override; + + void render() override; + + protected: + void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } + + Light& add_light( + const Position& position, + const Light::Power& power, + const ColorRGB ambient, + const ColorRGB diffuse, + const ColorRGB specular, + const Light::Fade& fade + ) + { + m_lights.emplace_back(position, power, ambient, diffuse, specular, fade); + return m_lights.back(); + } + + private: + ShaderProgram m_shader_program; + const Camera* m_p_camera = nullptr; + std::vector m_lights; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/LitShadowedShaderProgram.h b/OpenGLEngine/LitShadowedShaderProgram.h index 613634d..15c8429 100644 --- a/OpenGLEngine/LitShadowedShaderProgram.h +++ b/OpenGLEngine/LitShadowedShaderProgram.h @@ -6,11 +6,14 @@ namespace charcoal { namespace builtin { - // TODO: Add constatns for the uniform and vertex attribute locations (for all shader programs) - class LitShadowedShaderProgram : public VertexFragmentShaderProgram + namespace litshadowed { - public: - LitShadowedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitShadowedVS.glsl", SHADER_PATH "LitShadowedFS.glsl") {} - }; + // TODO: Add constants for the uniform and vertex attribute locations (for all shader programs) + class ShaderProgram : public VertexFragmentShaderProgram + { + public: + ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitShadowedVS.glsl", SHADER_PATH "LitShadowedFS.glsl") {} + }; + } } } diff --git a/OpenGLEngine/LitShadowedTypes.h b/OpenGLEngine/LitShadowedTypes.h new file mode 100644 index 0000000..c528009 --- /dev/null +++ b/OpenGLEngine/LitShadowedTypes.h @@ -0,0 +1,17 @@ +#pragma once + +#include "BuiltinTypes.h" + +namespace charcoal +{ + namespace builtin + { + namespace litshadowed + { + typedef PNMVertex Vertex; + typedef Index Index; + typedef RenderableT Renderable; + typedef Light Light; + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/LitTypes.h b/OpenGLEngine/LitTypes.h new file mode 100644 index 0000000..47a8c1d --- /dev/null +++ b/OpenGLEngine/LitTypes.h @@ -0,0 +1,17 @@ +#pragma once + +#include "BuiltinTypes.h" + +namespace charcoal +{ + namespace builtin + { + namespace lit + { + typedef PNMVertex Vertex; + typedef Index Index; + typedef RenderableT Renderable; + typedef Light Light; + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/MyBasicShaderProgram.h b/OpenGLEngine/MyBasicShaderProgram.h index 27a0f01..2a62625 100644 --- a/OpenGLEngine/MyBasicShaderProgram.h +++ b/OpenGLEngine/MyBasicShaderProgram.h @@ -28,7 +28,7 @@ public: float a = 1.0f; }; typedef unsigned int Index; - typedef Renderable Renderable; + typedef RenderableT RenderableT; typedef Mesh Mesh; MyBasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MyBasicVS.glsl", SHADER_PATH "MyBasicFS.glsl") {} diff --git a/OpenGLEngine/MyBatch.h b/OpenGLEngine/MyBatch.h index 9c3cf96..5504445 100644 --- a/OpenGLEngine/MyBatch.h +++ b/OpenGLEngine/MyBatch.h @@ -12,12 +12,12 @@ class MyBatch : public charcoal::Batch(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES), + : basic::Scene(application), + m_shape(meshgenerator::gen_cube_p(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES), m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f)), m_batch(add_batch(&m_shape, 1)) { diff --git a/OpenGLEngine/MyBuiltinCubeScene.h b/OpenGLEngine/MyBuiltinCubeScene.h index ebed1b2..f9ffa2d 100644 --- a/OpenGLEngine/MyBuiltinCubeScene.h +++ b/OpenGLEngine/MyBuiltinCubeScene.h @@ -6,14 +6,14 @@ using namespace charcoal; using namespace charcoal::builtin; -class MyBuiltinCubeScene : public BasicScene +class MyBuiltinCubeScene : public basic::Scene { public: MyBuiltinCubeScene(Application& application); void update(float delta_time, clock_t clock) override; private: - BasicRenderable m_shape; + basic::Renderable m_shape; builtin::Camera3D m_camera; - BasicBatch& m_batch; + basic::Batch& m_batch; }; \ No newline at end of file diff --git a/OpenGLEngine/MyBuiltinLitScene.cpp b/OpenGLEngine/MyBuiltinLitScene.cpp index 9edef45..a3a2f61 100644 --- a/OpenGLEngine/MyBuiltinLitScene.cpp +++ b/OpenGLEngine/MyBuiltinLitScene.cpp @@ -5,10 +5,10 @@ #include "constants.h" MyBuiltinLitScene::MyBuiltinLitScene(Application& application) - : LitScene(application), + : lit::Scene(application), m_shape( - meshgenerator::set_material( - meshgenerator::gen_cube_pn(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), + meshgenerator::set_material( + meshgenerator::gen_cube_pn(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), Material(1.0f, 1.0f, 0.2f, 1.0f) ), DrawMode::DRAW_TRIANGLES ), diff --git a/OpenGLEngine/MyBuiltinLitScene.h b/OpenGLEngine/MyBuiltinLitScene.h index 6ca074e..c23436d 100644 --- a/OpenGLEngine/MyBuiltinLitScene.h +++ b/OpenGLEngine/MyBuiltinLitScene.h @@ -6,14 +6,15 @@ using namespace charcoal; using namespace charcoal::builtin; -class MyBuiltinLitScene : public LitScene +// TODO: Use the lit namespace in builtin +class MyBuiltinLitScene : public lit::Scene { public: MyBuiltinLitScene(Application& application); void update(float delta_time, clock_t clock) override; private: - LitRenderable m_shape; + lit::Renderable m_shape; builtin::Camera3D m_camera; - LitBatch& m_batch; + lit::Batch& m_batch; }; \ No newline at end of file diff --git a/OpenGLEngine/MyBuiltinLitShadowedScene.cpp b/OpenGLEngine/MyBuiltinLitShadowedScene.cpp index 982b5cd..f585032 100644 --- a/OpenGLEngine/MyBuiltinLitShadowedScene.cpp +++ b/OpenGLEngine/MyBuiltinLitShadowedScene.cpp @@ -5,10 +5,10 @@ #include "constants.h" MyBuiltinLitShadowedScene::MyBuiltinLitShadowedScene(Application& application) - : LitShadowedScene(application), + : litshadowed::Scene(application), m_shape( - meshgenerator::set_material( - meshgenerator::gen_cube_pn(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), + meshgenerator::set_material( + meshgenerator::gen_cube_pn(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), Material(1.0f, 1.0f, 0.2f, 1.0f) ), DrawMode::DRAW_TRIANGLES ), diff --git a/OpenGLEngine/MyBuiltinLitShadowedScene.h b/OpenGLEngine/MyBuiltinLitShadowedScene.h index 9203205..32e2c04 100644 --- a/OpenGLEngine/MyBuiltinLitShadowedScene.h +++ b/OpenGLEngine/MyBuiltinLitShadowedScene.h @@ -6,14 +6,14 @@ using namespace charcoal; using namespace charcoal::builtin; -class MyBuiltinLitShadowedScene : public LitShadowedScene +class MyBuiltinLitShadowedScene : public litshadowed::Scene { public: MyBuiltinLitShadowedScene(Application& application); void update(float delta_time, clock_t clock) override; private: - LitShadowedRenderable m_shape; + litshadowed::Renderable m_shape; builtin::Camera3D m_camera; - LitShadowedBatch& m_batch; + litshadowed::Batch& m_batch; }; \ No newline at end of file diff --git a/OpenGLEngine/MyBuiltinTexturedScene.cpp b/OpenGLEngine/MyBuiltinTexturedScene.cpp index c0dd10d..52eea9c 100644 --- a/OpenGLEngine/MyBuiltinTexturedScene.cpp +++ b/OpenGLEngine/MyBuiltinTexturedScene.cpp @@ -6,9 +6,9 @@ #include "constants.h" MyBuiltinTexturedScene::MyBuiltinTexturedScene(Application& application) - : TexturedScene(application), + : textured::Scene(application), m_shape( - meshgenerator::gen_cube_pt(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), + meshgenerator::gen_cube_pt(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), texturegenerator::gen_quick_cube_texture(), texturegenerator::gen_quick_sampler(), DrawMode::DRAW_TRIANGLES diff --git a/OpenGLEngine/MyBuiltinTexturedScene.h b/OpenGLEngine/MyBuiltinTexturedScene.h index d0fd181..74402c6 100644 --- a/OpenGLEngine/MyBuiltinTexturedScene.h +++ b/OpenGLEngine/MyBuiltinTexturedScene.h @@ -6,14 +6,14 @@ using namespace charcoal; using namespace charcoal::builtin; -class MyBuiltinTexturedScene : public TexturedScene +class MyBuiltinTexturedScene : public textured::Scene { public: MyBuiltinTexturedScene(Application& application); void update(float delta_time, clock_t clock) override; private: - TexturedRenderable m_shape; + textured::Renderable m_shape; builtin::Camera3D m_camera; - TexturedBatch& m_batch; + textured::Batch& m_batch; }; \ No newline at end of file diff --git a/OpenGLEngine/MySimple2DScene.h b/OpenGLEngine/MySimple2DScene.h index 1df87b8..c09adea 100644 --- a/OpenGLEngine/MySimple2DScene.h +++ b/OpenGLEngine/MySimple2DScene.h @@ -29,7 +29,7 @@ public: private: MySimpleShaderProgram m_shader_program; - MySimpleShaderProgram::Renderable m_shape; + MySimpleShaderProgram::RenderableT m_shape; MyBatch m_batch; Camera2D m_camera; }; \ No newline at end of file diff --git a/OpenGLEngine/MySimple3DScene.h b/OpenGLEngine/MySimple3DScene.h index 2070f95..107f417 100644 --- a/OpenGLEngine/MySimple3DScene.h +++ b/OpenGLEngine/MySimple3DScene.h @@ -29,7 +29,7 @@ public: private: MySimpleShaderProgram m_shader_program; - MySimpleShaderProgram::Renderable m_shape; + MySimpleShaderProgram::RenderableT m_shape; MyBatch m_batch; charcoal::Camera3D m_camera; }; diff --git a/OpenGLEngine/MySimpleCubeScene.h b/OpenGLEngine/MySimpleCubeScene.h index 80daf5e..d8420cc 100644 --- a/OpenGLEngine/MySimpleCubeScene.h +++ b/OpenGLEngine/MySimpleCubeScene.h @@ -29,7 +29,7 @@ public: private: MySimpleShaderProgram m_shader_program; - MySimpleShaderProgram::Renderable m_shape; + MySimpleShaderProgram::RenderableT m_shape; MyBatch m_batch; charcoal::Camera3D m_camera; }; diff --git a/OpenGLEngine/MySimpleShaderProgram.h b/OpenGLEngine/MySimpleShaderProgram.h index c49b8ec..2be1a33 100644 --- a/OpenGLEngine/MySimpleShaderProgram.h +++ b/OpenGLEngine/MySimpleShaderProgram.h @@ -28,7 +28,7 @@ public: float a = 1.0f; }; typedef unsigned int Index; - typedef Renderable Renderable; + typedef RenderableT RenderableT; typedef Mesh Mesh; MySimpleShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MySimpleVS.glsl", SHADER_PATH "MySimpleFS.glsl") {} diff --git a/OpenGLEngine/OpenGLEngine.vcxproj b/OpenGLEngine/OpenGLEngine.vcxproj index 2519a8d..cc6cedc 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj +++ b/OpenGLEngine/OpenGLEngine.vcxproj @@ -195,6 +195,7 @@ + @@ -213,6 +214,8 @@ + + @@ -222,6 +225,7 @@ + diff --git a/OpenGLEngine/OpenGLEngine.vcxproj.filters b/OpenGLEngine/OpenGLEngine.vcxproj.filters index 879f2bc..ab29a17 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj.filters +++ b/OpenGLEngine/OpenGLEngine.vcxproj.filters @@ -371,6 +371,18 @@ Header Files\Example\Application + + Header Files\Engine\builtin\Basic + + + Header Files\Engine\builtin\Lit + + + Header Files\Engine\builtin\Textured + + + Header Files\Engine\builtin\LitShadowed + diff --git a/OpenGLEngine/PoseableBatch.h b/OpenGLEngine/PoseableBatch.h index a102d25..1635b2f 100644 --- a/OpenGLEngine/PoseableBatch.h +++ b/OpenGLEngine/PoseableBatch.h @@ -9,22 +9,22 @@ namespace charcoal { namespace builtin { - template > - class PoseableBatch : public builtin::Batch + template > + class PoseableBatch : public builtin::Batch { public: // TODO: Figure out how to get rid of this typename garbage. If that it figured out, m_element_buffers should get fixed. PoseableBatch( - Renderable* renderable, + RenderableT* renderable, int element_count ) : PoseableBatch(renderable, element_count, element_count) {} PoseableBatch( - Renderable* renderable, + RenderableT* renderable, int element_count, int element_render_count - ) : builtin::Batch(renderable, element_render_count), m_pose_elements(element_count) + ) : builtin::Batch(renderable, element_render_count), m_pose_elements(element_count) {} virtual ~PoseableBatch() {} @@ -35,14 +35,14 @@ namespace charcoal protected: void setup_element_buffers() { - glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch::m_element_buffers[0]); + glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch::m_element_buffers[0]); glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); } void update_element_buffers() { // TODO: There are probably better ways to do this. Should check with the old engine to see what I did there. - glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch::m_element_buffers[0]); + glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch::m_element_buffers[0]); glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, m_pose_elements.size() * sizeof(Poseable), m_pose_elements.data()); } diff --git a/OpenGLEngine/Renderable.h b/OpenGLEngine/Renderable.h index c0342dd..ef958ba 100644 --- a/OpenGLEngine/Renderable.h +++ b/OpenGLEngine/Renderable.h @@ -11,14 +11,14 @@ namespace charcoal { template - class Renderable + class RenderableT { public: typedef VertexType VertexType; typedef IndexType IndexType; typedef Mesh MeshType; - Renderable(const MeshType* mesh, const DrawMode& draw_mode) + RenderableT(const MeshType* mesh, const DrawMode& draw_mode) : m_p_mesh(mesh), m_draw_mode(draw_mode) {} diff --git a/OpenGLEngine/TextureRenderable.h b/OpenGLEngine/TextureRenderable.h index 7e72d06..e9f5c6f 100644 --- a/OpenGLEngine/TextureRenderable.h +++ b/OpenGLEngine/TextureRenderable.h @@ -7,11 +7,11 @@ namespace charcoal { template - class TextureRenderable : public Renderable + class TextureRenderable : public RenderableT { public: - TextureRenderable(const Renderable::MeshType* mesh, Texture* texture, Sampler* sampler, const DrawMode& draw_mode) - : Renderable(mesh, draw_mode), m_p_texture(texture), m_p_sampler(sampler) + TextureRenderable(const RenderableT::MeshType* mesh, Texture* texture, Sampler* sampler, const DrawMode& draw_mode) + : RenderableT(mesh, draw_mode), m_p_texture(texture), m_p_sampler(sampler) {} const Texture* get_texture() const { return m_p_texture; } diff --git a/OpenGLEngine/TexturedBatch.cpp b/OpenGLEngine/TexturedBatch.cpp index e2fa913..1a8d479 100644 --- a/OpenGLEngine/TexturedBatch.cpp +++ b/OpenGLEngine/TexturedBatch.cpp @@ -4,36 +4,39 @@ namespace charcoal { namespace builtin { - void TexturedBatch::preprender() const + namespace textured { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_p_renderable->get_texture()->get_texture()); - glBindSampler(0, m_p_renderable->get_sampler()->get_sampler()); - } + void Batch::preprender() const + { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_p_renderable->get_texture()->get_texture()); + glBindSampler(0, m_p_renderable->get_sampler()->get_sampler()); + } - void TexturedBatch::setup_vao() - { - glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void*)offsetof(TexturedVertex, position)); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void*)offsetof(TexturedVertex, uv)); - glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); - glEnableVertexAttribArray(2); - glEnableVertexAttribArray(3); - glEnableVertexAttribArray(4); - glEnableVertexAttribArray(5); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); - glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); - glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); + void Batch::setup_vao() + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position)); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, uv)); + glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); + glEnableVertexAttribArray(2); + glEnableVertexAttribArray(3); + glEnableVertexAttribArray(4); + glEnableVertexAttribArray(5); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4))); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4))); + glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4))); + glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4))); - glVertexAttribDivisor(0, 0); // Send the mesh data once - glVertexAttribDivisor(1, 0); // Send the mesh data once - glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn - glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(0, 0); // Send the mesh data once + glVertexAttribDivisor(1, 0); // Send the mesh data once + glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn + glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn + } } } } diff --git a/OpenGLEngine/TexturedBatch.h b/OpenGLEngine/TexturedBatch.h index 949eb8c..0ffc2b3 100644 --- a/OpenGLEngine/TexturedBatch.h +++ b/OpenGLEngine/TexturedBatch.h @@ -1,32 +1,35 @@ #pragma once #include "PoseableBatch.h" -#include "BuiltinTypes.h" +#include "TexturedTypes.h" namespace charcoal { namespace builtin { - class TexturedBatch : public PoseableBatch + namespace textured { - public: - TexturedBatch( - TexturedRenderable* renderable, - int element_count - ) : PoseableBatch(renderable, element_count) - {} + class Batch : public PoseableBatch + { + public: + Batch( + Renderable* renderable, + int element_count + ) : PoseableBatch(renderable, element_count) + {} - TexturedBatch( - TexturedRenderable* renderable, - int element_count, - int element_render_count - ) : PoseableBatch(renderable, element_count, element_render_count) - {} + Batch( + Renderable* renderable, + int element_count, + int element_render_count + ) : PoseableBatch(renderable, element_count, element_render_count) + {} - void preprender() const override; + void preprender() const override; - protected: - void setup_vao() override; - }; + protected: + void setup_vao() override; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/TexturedScene.cpp b/OpenGLEngine/TexturedScene.cpp index fd76eec..15777a5 100644 --- a/OpenGLEngine/TexturedScene.cpp +++ b/OpenGLEngine/TexturedScene.cpp @@ -9,37 +9,40 @@ namespace charcoal { namespace builtin { - void TexturedScene::init() + namespace textured { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::init() { - TexturedBatch& batch = *iter; - batch.init(); - add_prerenderable(&batch); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + Batch& batch = *iter; + batch.init(); + add_prerenderable(&batch); + } } - } - void TexturedScene::use() - { - // TODO: move to glutil - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - } - - void TexturedScene::unuse() - { - - } - - void TexturedScene::render() - { - glutil::clear_screen(); - m_shader_program.use(); - glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); - glutil::uniform_int(4, 0); // The textured batch uses GL_TEXTURE0 - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + void Scene::use() { - iter->render(); + // TODO: move to glutil + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + } + + void Scene::unuse() + { + + } + + void Scene::render() + { + glutil::clear_screen(); + m_shader_program.use(); + glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); + glutil::uniform_int(4, 0); // The textured batch uses GL_TEXTURE0 + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->render(); + } } } } diff --git a/OpenGLEngine/TexturedScene.h b/OpenGLEngine/TexturedScene.h index 5582809..1f47742 100644 --- a/OpenGLEngine/TexturedScene.h +++ b/OpenGLEngine/TexturedScene.h @@ -14,26 +14,29 @@ namespace charcoal { namespace builtin { - class TexturedScene : public AutoPrerenderingScene, public Batched + namespace textured { - public: - TexturedScene(Application& application) : AutoPrerenderingScene(application) {} - virtual ~TexturedScene() {} + class Scene : public AutoPrerenderingScene, public Batched + { + public: + Scene(Application& application) : AutoPrerenderingScene(application) {} + virtual ~Scene() {} - void init() override; + void init() override; - void use() override; + void use() override; - void unuse() override; + void unuse() override; - void render() override; + void render() override; - protected: - void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } + protected: + void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } - private: - TexturedShaderProgram m_shader_program; - const Camera* m_p_camera = nullptr; - }; + private: + ShaderProgram m_shader_program; + const Camera* m_p_camera = nullptr; + }; + } } } \ No newline at end of file diff --git a/OpenGLEngine/TexturedShaderProgram.h b/OpenGLEngine/TexturedShaderProgram.h index 2301f7b..7f014a4 100644 --- a/OpenGLEngine/TexturedShaderProgram.h +++ b/OpenGLEngine/TexturedShaderProgram.h @@ -6,10 +6,13 @@ namespace charcoal { namespace builtin { - class TexturedShaderProgram : public VertexFragmentShaderProgram + namespace textured { - public: - TexturedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {} - }; + class ShaderProgram : public VertexFragmentShaderProgram + { + public: + ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {} + }; + } } } diff --git a/OpenGLEngine/TexturedTypes.h b/OpenGLEngine/TexturedTypes.h new file mode 100644 index 0000000..2bdeb59 --- /dev/null +++ b/OpenGLEngine/TexturedTypes.h @@ -0,0 +1,17 @@ +#pragma once + +#include "TextureRenderable.h" +#include "BuiltinTypes.h" + +namespace charcoal +{ + namespace builtin + { + namespace textured + { + typedef PTVertex Vertex; + typedef Index Index; + typedef TextureRenderable Renderable; + } + } +} \ No newline at end of file