diff --git a/CharcoalBuiltin/BasicBatch.cpp b/CharcoalBuiltin/BasicBatch.cpp index 155baae..4d0b059 100644 --- a/CharcoalBuiltin/BasicBatch.cpp +++ b/CharcoalBuiltin/BasicBatch.cpp @@ -6,26 +6,13 @@ namespace charcoal { namespace basic { - void Batch::setup_vao() + void Batch::setup_vao_vertex() { 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); } } } diff --git a/CharcoalBuiltin/BasicBatch.h b/CharcoalBuiltin/BasicBatch.h index 807bc44..bc9b702 100644 --- a/CharcoalBuiltin/BasicBatch.h +++ b/CharcoalBuiltin/BasicBatch.h @@ -1,7 +1,7 @@ #pragma once -#include "PoseableBatch.h" #include "BasicTypes.h" +#include "PoseableBatch.h" namespace charcoal { @@ -9,13 +9,12 @@ namespace charcoal { namespace basic { - class Batch : public PoseableBatch + class Batch : public PoseableBatch { public: - using PoseableBatch::PoseableBatch; - + using PoseableBatch::PoseableBatch; protected: - void setup_vao() override; + virtual void setup_vao_vertex() override; }; } } diff --git a/CharcoalBuiltin/BasicScene.cpp b/CharcoalBuiltin/BasicScene.cpp index 573f07e..10b8914 100644 --- a/CharcoalBuiltin/BasicScene.cpp +++ b/CharcoalBuiltin/BasicScene.cpp @@ -37,7 +37,7 @@ namespace charcoal { glutil::clear_screen(); m_shader_program.use(); - glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); + glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix()); for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) { iter->render(); diff --git a/CharcoalBuiltin/BasicScene.h b/CharcoalBuiltin/BasicScene.h index bfc8931..0977713 100644 --- a/CharcoalBuiltin/BasicScene.h +++ b/CharcoalBuiltin/BasicScene.h @@ -10,8 +10,9 @@ #include "BasicShaderProgram.h" #include "BasicTypes.h" -#include "Batched.h" #include "BasicBatch.h" +#include "Batched.h" +#include "WithCamera.h" namespace charcoal { @@ -19,7 +20,7 @@ namespace charcoal { namespace basic { - class Scene : public AutoPrerenderingScene, public Batched + class Scene : public AutoPrerenderingScene, public Batched, public WithCamera { public: Scene(Application& application) : AutoPrerenderingScene(application) {} @@ -32,12 +33,8 @@ namespace charcoal void render() override; - protected: - void set_camera(const Camera* p_camera) { m_p_camera = p_camera; } - private: ShaderProgram m_shader_program; - const Camera* m_p_camera = nullptr; }; } } diff --git a/CharcoalBuiltin/BasicTypes.h b/CharcoalBuiltin/BasicTypes.h index d9cab10..2970e94 100644 --- a/CharcoalBuiltin/BasicTypes.h +++ b/CharcoalBuiltin/BasicTypes.h @@ -2,6 +2,7 @@ #include "BuiltinTypes.h" + namespace charcoal { namespace builtin diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj b/CharcoalBuiltin/CharcoalBuiltin.vcxproj index c1ba263..cac8d28 100644 --- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj +++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj @@ -143,15 +143,6 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\" - - - - - - - - - @@ -166,30 +157,9 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\" - - - - - - - - - - - - - - - - - - - - - diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters index d6b066a..b64462e 100644 --- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters +++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters @@ -19,18 +19,6 @@ {1dbc28a4-b52f-4171-a385-79490dfa9b0a} - - {4a034e10-73da-44fe-8308-b6a63b41c920} - - - {b2538cf1-c4a2-40b6-9cef-8a937208aaf2} - - - {f255fa90-53ea-4a64-9d44-ca9d9013bc3f} - - - {2c58c0aa-d1ef-4d03-825c-0b8a08672e78} - {5df56e70-8319-4228-b684-c38dd8730bd2} @@ -43,24 +31,6 @@ {e167753a-dc8e-4c92-ad62-22b272484656} - - {2823fbc0-59e9-4b79-a7a5-15fd5de29516} - - - {f3e1fe4f-dd8b-44ff-b427-379d34eb5b02} - - - {f6f4656e-2a26-4232-b147-a83a2a766e6a} - - - {5f931ae6-23b1-43df-a4d8-e7f134d755c8} - - - {d1604903-a209-427a-a879-3278b9fe8088} - - - {eecad623-46fa-4c24-b93d-c8d77002608e} - @@ -78,62 +48,8 @@ Source Files\Scenes\Basic - - Source Files\Scenes\Image - - - Source Files\Scenes\Lit - - - Source Files\Scenes\Lit - - - Source Files\Scenes\LitShadowed - - - Source Files\Scenes\LitShadowed - - - Source Files\Scenes\Textured - - - Source Files\Scenes\Textured - - - Source Files\Scenes\Specified - - - Source Files\Scenes\Specified - - - Header Files\Scenes\Textured - - - Header Files\Scenes\Textured - - - Header Files\Scenes\Textured - - - Header Files\Scenes\Textured - - - Header Files\Scenes\LitShadowed - - - Header Files\Scenes\LitShadowed - - - Header Files\Scenes\LitShadowed - - - Header Files\Scenes\LitShadowed - - - Header Files\Scenes\Basic - Header Files\Scenes\Basic @@ -143,24 +59,6 @@ Header Files\Scenes\Basic - - Header Files\Scenes\Image - - - Header Files\Scenes\Image - - - Header Files\Scenes\Image - - - Header Files\Scenes\Lit - - - Header Files\Scenes\Lit - - - Header Files\Scenes\Lit - Header Files\General @@ -185,9 +83,6 @@ Header Files\General - - Header Files\General - Header Files\General @@ -200,23 +95,8 @@ Header Files\General - - Header Files\Scenes\Lit - - - Header Files\General - - - Header Files\General - - - Header Files\Scenes\Specified - - - Header Files\Scenes\Specified - - - Header Files\Scenes\Specified + + Header Files\Scenes\Basic \ No newline at end of file diff --git a/CharcoalBuiltin/ImageScene.cpp b/CharcoalBuiltin/ImageScene.cpp deleted file mode 100644 index f9e091e..0000000 --- a/CharcoalBuiltin/ImageScene.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "ImageScene.h" - -#include -#include - -#include "GLUtil.h" - -namespace charcoal -{ - namespace builtin - { - namespace image - { - void Scene::init() - { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - Batch& batch = *iter; - batch.init(); - add_prerenderable(&batch); - } - } - - void Scene::use() - { - // 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, get_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(); - } - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/ImageScene.h b/CharcoalBuiltin/ImageScene.h deleted file mode 100644 index 500cb23..0000000 --- a/CharcoalBuiltin/ImageScene.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "AutoPrerenderingScene.h" -#include "WithCamera.h" -#include "Batched.h" - -#include "SpriteBatch.h" -#include "ImageShaderProgram.h" -#include "ImageTypes.h" - -namespace charcoal -{ - namespace builtin - { - namespace image - { - class Scene : public AutoPrerenderingScene, public WithCamera, public Batched - { - public: - Scene(Application& application) : AutoPrerenderingScene(application) {} - - void init() override; - - void use() override; - - void unuse() override; - - void render() override; - - private: - ShaderProgram m_shader_program; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/ImageShaderProgram.h b/CharcoalBuiltin/ImageShaderProgram.h deleted file mode 100644 index 16675dc..0000000 --- a/CharcoalBuiltin/ImageShaderProgram.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -namespace charcoal -{ - namespace builtin - { - namespace image - { - class ShaderProgram : public VertexFragmentShaderProgram - { - public: - ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "ImageVS.glsl", SHADER_PATH "ImageFS.glsl") {} - }; - } - } -} diff --git a/CharcoalBuiltin/ImageTypes.h b/CharcoalBuiltin/ImageTypes.h deleted file mode 100644 index 3f41753..0000000 --- a/CharcoalBuiltin/ImageTypes.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "BuiltinTypes.h" - -#include "SpriteBatch.h" - -namespace charcoal -{ - namespace builtin - { - namespace image - { - typedef PTVertex Vertex; - typedef Index Index; - typedef TextureRenderable Renderable; - typedef SpriteBatch Batch; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitBatch.cpp b/CharcoalBuiltin/LitBatch.cpp deleted file mode 100644 index 747024f..0000000 --- a/CharcoalBuiltin/LitBatch.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "LitBatch.h" - -namespace charcoal -{ - namespace builtin - { - namespace lit - { - 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 - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitBatch.h b/CharcoalBuiltin/LitBatch.h deleted file mode 100644 index 55d96c7..0000000 --- a/CharcoalBuiltin/LitBatch.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "PoseableBatch.h" -#include "LitTypes.h" - -namespace charcoal -{ - namespace builtin - { - namespace lit - { - class Batch : public PoseableBatch - { - public: - using PoseableBatch::PoseableBatch; - - protected: - void setup_vao() override; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitScene.cpp b/CharcoalBuiltin/LitScene.cpp deleted file mode 100644 index 41d910b..0000000 --- a/CharcoalBuiltin/LitScene.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "LitScene.h" - -#include -#include -#include - -#include "GLUtil.h" - -namespace charcoal -{ - namespace builtin - { - namespace lit - { - void Scene::init() - { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - Batch& batch = *iter; - batch.init(); - add_prerenderable(&batch); - } - } - - void Scene::use() - { - // 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(); - } - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitScene.h b/CharcoalBuiltin/LitScene.h deleted file mode 100644 index 7db52cc..0000000 --- a/CharcoalBuiltin/LitScene.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include - -#include - -#include "AutoPrerenderingScene.h" -#include "LitTypes.h" -#include "Batched.h" -#include "LitBatch.h" -#include "LitShaderProgram.h" - -namespace charcoal -{ - namespace builtin - { - namespace lit - { - // A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model ) - class Scene : public AutoPrerenderingScene, public Batched - { - public: - Scene(Application& application) : AutoPrerenderingScene(application) {} - - 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/CharcoalBuiltin/LitShaderProgram.h b/CharcoalBuiltin/LitShaderProgram.h deleted file mode 100644 index bb8b4f4..0000000 --- a/CharcoalBuiltin/LitShaderProgram.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -namespace charcoal -{ - namespace builtin - { - namespace lit - { - // 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/CharcoalBuiltin/LitShadowedBatch.cpp b/CharcoalBuiltin/LitShadowedBatch.cpp deleted file mode 100644 index 70f666b..0000000 --- a/CharcoalBuiltin/LitShadowedBatch.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "LitShadowedBatch.h" - -namespace charcoal -{ - namespace builtin - { - namespace litshadowed - { - 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 - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitShadowedBatch.h b/CharcoalBuiltin/LitShadowedBatch.h deleted file mode 100644 index 4f313a4..0000000 --- a/CharcoalBuiltin/LitShadowedBatch.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "PoseableBatch.h" -#include "LitShadowedTypes.h" - -namespace charcoal -{ - namespace builtin - { - namespace litshadowed - { - class Batch : public PoseableBatch - { - public: - using PoseableBatch::PoseableBatch; - - protected: - void setup_vao() override; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitShadowedScene.cpp b/CharcoalBuiltin/LitShadowedScene.cpp deleted file mode 100644 index fcf4583..0000000 --- a/CharcoalBuiltin/LitShadowedScene.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "LitShadowedScene.h" - -#include -#include -#include - -#include "GLUtil.h" - -namespace charcoal -{ - namespace builtin - { - namespace litshadowed - { - void Scene::init() - { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - Batch& batch = *iter; - batch.init(); - add_prerenderable(&batch); - } - } - - void Scene::use() - { - // 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(); - } - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/LitShadowedScene.h b/CharcoalBuiltin/LitShadowedScene.h deleted file mode 100644 index 49e6c0f..0000000 --- a/CharcoalBuiltin/LitShadowedScene.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include - -#include - -#include "AutoPrerenderingScene.h" -#include "LitShadowedTypes.h" -#include "Batched.h" -#include "LitShadowedBatch.h" -#include "LitShadowedShaderProgram.h" - -namespace charcoal -{ - namespace builtin - { - namespace litshadowed - { - // A scene lit by the Phong Reflection Model (See https://en.wikipedia.org/wiki/Phong_reflection_model ) - class Scene : public AutoPrerenderingScene, public Batched - { - public: - Scene(Application& application) : AutoPrerenderingScene(application) {} - - 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/CharcoalBuiltin/LitShadowedShaderProgram.h b/CharcoalBuiltin/LitShadowedShaderProgram.h deleted file mode 100644 index 5758951..0000000 --- a/CharcoalBuiltin/LitShadowedShaderProgram.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -namespace charcoal -{ - namespace builtin - { - namespace litshadowed - { - // 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/CharcoalBuiltin/LitShadowedTypes.h b/CharcoalBuiltin/LitShadowedTypes.h deleted file mode 100644 index c528009..0000000 --- a/CharcoalBuiltin/LitShadowedTypes.h +++ /dev/null @@ -1,17 +0,0 @@ -#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/CharcoalBuiltin/LitTypes.h b/CharcoalBuiltin/LitTypes.h deleted file mode 100644 index 47a8c1d..0000000 --- a/CharcoalBuiltin/LitTypes.h +++ /dev/null @@ -1,17 +0,0 @@ -#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/CharcoalBuiltin/Poseable2DBatch.h b/CharcoalBuiltin/Poseable2DBatch.h deleted file mode 100644 index 38b63ff..0000000 --- a/CharcoalBuiltin/Poseable2DBatch.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "PoseableBatch.h" - -namespace charcoal -{ - namespace builtin - { - // This has to be made completely seperately in order to avoid the vtable that gets added if Poseable is abstracted between - // 2D and 3D - template > - class Poseable2DBatch : public PoseableBatch - { - public: - using PoseableBatch::PoseableBatch; - - Poseable2D& get_pose(int index) - { - Poseable& pose = PoseableBatch::get_pose(index); - Poseable* p_pose = &pose; - Poseable2D* p_pose_2d = reinterpret_cast(p_pose); // Can do this since both are just mat4 wrappers - return *p_pose_2d; - } - const Poseable2D& get_pose(int index) const - { - Poseable& pose = PoseableBatch::get_pose(index); - Poseable* p_pose = &pose; - Poseable2D* p_pose_2d = reinterpret_cast(p_pose); // Can do this since both are just mat4 wrappers - return *p_pose_2d; - } - }; - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/PoseableBatch.h b/CharcoalBuiltin/PoseableBatch.h index d18327a..c8307d0 100644 --- a/CharcoalBuiltin/PoseableBatch.h +++ b/CharcoalBuiltin/PoseableBatch.h @@ -10,7 +10,7 @@ namespace charcoal namespace builtin { // Note: If anything is changed in this file, it must also be changed in Poseable2DBatch - template > + template > class PoseableBatch : public builtin::Batch { public: @@ -24,30 +24,55 @@ namespace charcoal 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_orientation_elements(element_count) {} virtual ~PoseableBatch() {} - Poseable& get_pose(int index) { return m_pose_elements[index]; } - const Poseable& get_pose(int index) const { return m_pose_elements[index]; } + void reset_rendered() { charcoal::Batch::m_element_render_count = 0; } + + void add_rendered(const Poseable& poseable) { m_orientation_elements[charcoal::Batch::m_element_render_count++] = poseable.get_orientation_matrix(); } protected: void setup_element_buffers() { glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch::m_element_buffers[0]); - glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), 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]); - 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()); + glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, m_orientation_elements.size() * sizeof(mat4), m_orientation_elements.data()); } - std::vector m_pose_elements; + virtual void setup_vao_vertex() = 0; + + void setup_vao() override + { + setup_vao_vertex(); + + glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch::m_element_buffers[0]); + + glEnableVertexAttribArray(orientation_attrib_offset + 0); + glEnableVertexAttribArray(orientation_attrib_offset + 1); + glEnableVertexAttribArray(orientation_attrib_offset + 2); + glEnableVertexAttribArray(orientation_attrib_offset + 3); + + glVertexAttribPointer(orientation_attrib_offset + 0, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(0 * sizeof(mat4::col_type))); + glVertexAttribPointer(orientation_attrib_offset + 1, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(1 * sizeof(mat4::col_type))); + glVertexAttribPointer(orientation_attrib_offset + 2, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(2 * sizeof(mat4::col_type))); + glVertexAttribPointer(orientation_attrib_offset + 3, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(3 * sizeof(mat4::col_type))); + + glVertexAttribDivisor(orientation_attrib_offset + 0, 1); // Send the orientation data for each instance drawn + glVertexAttribDivisor(orientation_attrib_offset + 1, 1); // Send the orientation data for each instance drawn + glVertexAttribDivisor(orientation_attrib_offset + 2, 1); // Send the orientation data for each instance drawn + glVertexAttribDivisor(orientation_attrib_offset + 3, 1); // Send the orientation data for each instance drawn + } + + std::vector m_orientation_elements; }; } } \ No newline at end of file diff --git a/CharcoalBuiltin/SpecifiedBatch.cpp b/CharcoalBuiltin/SpecifiedBatch.cpp deleted file mode 100644 index 939f204..0000000 --- a/CharcoalBuiltin/SpecifiedBatch.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "SpecifiedBatch.h" - -namespace charcoal -{ - namespace builtin - { - namespace specified - { - 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 - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/SpecifiedBatch.h b/CharcoalBuiltin/SpecifiedBatch.h deleted file mode 100644 index 91cc724..0000000 --- a/CharcoalBuiltin/SpecifiedBatch.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "SpecifiedPoseableBatch.h" -#include "SpecifiedTypes.h" - -namespace charcoal -{ - namespace builtin - { - namespace specified - { - class Batch : public SpecifiedPoseableBatch - { - protected: - void setup_vao() override; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/SpecifiedPoseable.h b/CharcoalBuiltin/SpecifiedPoseable.h deleted file mode 100644 index bb9a715..0000000 --- a/CharcoalBuiltin/SpecifiedPoseable.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -namespace charcoal -{ - namespace builtin - { - template - class SpecifiedPoseable : public Poseable - { - public: - SpecifiedPoseable(SpecifiedPoseableBatchType& batch) : m_batch(batch) - {} - - void render() - { - m_batch.add_specified_poseable(this); - } - - private: - SpecifiedPoseableBatchType& m_batch; - }; - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/SpecifiedPoseableBatch.h b/CharcoalBuiltin/SpecifiedPoseableBatch.h deleted file mode 100644 index 4b42307..0000000 --- a/CharcoalBuiltin/SpecifiedPoseableBatch.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "PoseableBatch.h" - -#include "SpecifiedPoseable.h" - -namespace charcoal -{ - namespace builtin - { - // Note: If anything is changed in this file, it must also be changed in Poseable2DBatch - template > - class SpecifiedPoseableBatch : public PoseableBatch - { - public: - using PoseableBatch::PoseableBatch; - - void reset() - { - m_element_render_count = 0; - } - - void add_specified_poseable(SpecifiedPoseable >* poseable) - { - PoseableBatch::m_pose_elements[m_element_render_count++].set_orientation_matrix(poseable->get_orientation_matrix()); - } - }; - } -} diff --git a/CharcoalBuiltin/SpecifiedScene.cpp b/CharcoalBuiltin/SpecifiedScene.cpp deleted file mode 100644 index eafab8c..0000000 --- a/CharcoalBuiltin/SpecifiedScene.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "SpecifiedScene.h" - -#include - -#include "GLUtil.h" - -namespace charcoal -{ - namespace builtin - { - namespace specified - { - void Scene::init() - { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - Batch& batch = *iter; - batch.init(); - add_prerenderable(&batch); - } - } - - void Scene::use() - { - // 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, get_camera()->get_world_to_view_matrix()); - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - iter->render(); - } - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/SpecifiedScene.h b/CharcoalBuiltin/SpecifiedScene.h deleted file mode 100644 index 7ab96c4..0000000 --- a/CharcoalBuiltin/SpecifiedScene.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "SpecifiedTypes.h" -#include "SpecifiedBatch.h" - -#include "AutoPrerenderingScene.h" -#include "Batched.h" -#include "WithCamera.h" - -namespace charcoal -{ - namespace builtin - { - namespace specified - { - class Scene : public AutoPrerenderingScene, public Batched, public WithCamera - { - public: - Scene(Application& application) : AutoPrerenderingScene(application) {} - - void init() override; - - void use() override; - - void unuse() override; - - void render() override; - - private: - ShaderProgram m_shader_program; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/SpecifiedTypes.h b/CharcoalBuiltin/SpecifiedTypes.h deleted file mode 100644 index a26050c..0000000 --- a/CharcoalBuiltin/SpecifiedTypes.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "BuiltinTypes.h" - -#include "BasicTypes.h" -#include "BasicShaderProgram.h" - -namespace charcoal -{ - namespace builtin - { - namespace specified - { - // Just use the basic types - - typedef basic::Vertex Vertex; - typedef basic::Index Index; - typedef basic::Renderable Renderable; - - typedef basic::ShaderProgram ShaderProgram; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/SpriteBatch.h b/CharcoalBuiltin/SpriteBatch.h index 5395962..37f0928 100644 --- a/CharcoalBuiltin/SpriteBatch.h +++ b/CharcoalBuiltin/SpriteBatch.h @@ -3,19 +3,19 @@ #include #include -#include "Poseable2DBatch.h" +#include "PoseableBatch.h" namespace charcoal { namespace builtin { template - class SpriteBatch : public Poseable2DBatch > + class SpriteBatch : public PoseableBatch > { public: // Note: This is VERY similar to builtin::textured::Batch // Note: Uses GL_TEXTURE0. The uniform for this texture should be set in the scene before rendering. - using Poseable2DBatch >::Poseable2DBatch; + using PoseableBatch >::PoseableBatch; void preprender() const override { @@ -24,32 +24,6 @@ namespace charcoal glBindTexture(GL_TEXTURE_2D, charcoal::Batch >::m_p_renderable->get_texture()->get_texture()); glBindSampler(0, charcoal::Batch >::m_p_renderable->get_sampler()->get_sampler()); } - - protected: - void setup_vao() override - { - glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch >::m_vertex_vbo); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)position_offset); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)uv_offset); - glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch >::m_element_buffers[0]); - glEnableVertexAttribArray(2); - glEnableVertexAttribArray(3); - glEnableVertexAttribArray(4); - glEnableVertexAttribArray(5); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(0 * sizeof(vec4))); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(1 * sizeof(vec4))); - glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(2 * sizeof(vec4))); - glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (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 - } }; } } diff --git a/CharcoalBuiltin/TexturedBatch.cpp b/CharcoalBuiltin/TexturedBatch.cpp deleted file mode 100644 index 1a8d479..0000000 --- a/CharcoalBuiltin/TexturedBatch.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "TexturedBatch.h" - -namespace charcoal -{ - namespace builtin - { - namespace textured - { - 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 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 - } - } - } -} diff --git a/CharcoalBuiltin/TexturedBatch.h b/CharcoalBuiltin/TexturedBatch.h deleted file mode 100644 index 440be21..0000000 --- a/CharcoalBuiltin/TexturedBatch.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "PoseableBatch.h" -#include "TexturedTypes.h" - -namespace charcoal -{ - namespace builtin - { - namespace textured - { - class Batch : public PoseableBatch - { - public: - using PoseableBatch::PoseableBatch; - - void preprender() const override; - - protected: - void setup_vao() override; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/TexturedScene.cpp b/CharcoalBuiltin/TexturedScene.cpp deleted file mode 100644 index b02588b..0000000 --- a/CharcoalBuiltin/TexturedScene.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "TexturedScene.h" - -#include -#include - -#include "GLUtil.h" - -namespace charcoal -{ - namespace builtin - { - namespace textured - { - void Scene::init() - { - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - Batch& batch = *iter; - batch.init(); - add_prerenderable(&batch); - } - } - - void Scene::use() - { - // 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); // Sprite batches all use GL_TEXTURE0 so set this to 0 - for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) - { - iter->render(); - } - } - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/TexturedScene.h b/CharcoalBuiltin/TexturedScene.h deleted file mode 100644 index 0f24613..0000000 --- a/CharcoalBuiltin/TexturedScene.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include - -#include - -#include "AutoPrerenderingScene.h" -#include "Batched.h" -#include "TexturedBatch.h" -#include "TexturedShaderProgram.h" - -namespace charcoal -{ - namespace builtin - { - namespace textured - { - class Scene : public AutoPrerenderingScene, public Batched - { - public: - Scene(Application& application) : AutoPrerenderingScene(application) {} - - 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; } - - private: - ShaderProgram m_shader_program; - const Camera* m_p_camera = nullptr; - }; - } - } -} \ No newline at end of file diff --git a/CharcoalBuiltin/TexturedShaderProgram.h b/CharcoalBuiltin/TexturedShaderProgram.h deleted file mode 100644 index 00d6ef5..0000000 --- a/CharcoalBuiltin/TexturedShaderProgram.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -namespace charcoal -{ - namespace builtin - { - namespace textured - { - class ShaderProgram : public VertexFragmentShaderProgram - { - public: - ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {} - }; - } - } -} diff --git a/CharcoalBuiltin/TexturedTypes.h b/CharcoalBuiltin/TexturedTypes.h deleted file mode 100644 index ff65d70..0000000 --- a/CharcoalBuiltin/TexturedTypes.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -#include "BuiltinTypes.h" - -namespace charcoal -{ - namespace builtin - { - namespace textured - { - typedef PTVertex Vertex; - typedef Index Index; - typedef TextureRenderable Renderable; - } - } -} \ No newline at end of file diff --git a/Example/Example.vcxproj b/Example/Example.vcxproj index c6edfb5..6fda776 100644 --- a/Example/Example.vcxproj +++ b/Example/Example.vcxproj @@ -24,14 +24,9 @@ - - - - - @@ -39,15 +34,10 @@ - - - - - 15.0 diff --git a/Example/Example.vcxproj.filters b/Example/Example.vcxproj.filters index 312ff1d..7f8e50a 100644 --- a/Example/Example.vcxproj.filters +++ b/Example/Example.vcxproj.filters @@ -27,18 +27,6 @@ Source Files - - Source Files - - - Source Files - - - Source Files - - - Source Files - Source Files @@ -51,9 +39,6 @@ Source Files - - Source Files - @@ -74,18 +59,6 @@ Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files @@ -95,8 +68,5 @@ Header Files - - Header Files - \ No newline at end of file diff --git a/Example/MyApplication.cpp b/Example/MyApplication.cpp index 2dc5886..c3cc5b2 100644 --- a/Example/MyApplication.cpp +++ b/Example/MyApplication.cpp @@ -6,11 +6,7 @@ MyApplication::MyApplication(int width, int height) m_simple_2d_scene(*this), m_simple_3d_scene(*this), m_simple_cube_scene(*this), - m_builtin_basic_cube_scene(*this), - m_builtin_lit_scene(*this), - m_builtin_textured_scene(*this), - m_builtin_lit_shadowed_scene(*this), - m_builtin_image_scene(*this) + m_builtin_basic_cube_scene(*this) {} void MyApplication::init() @@ -20,10 +16,6 @@ void MyApplication::init() m_simple_3d_scene.init(); m_simple_cube_scene.init(); m_builtin_basic_cube_scene.init(); - m_builtin_lit_scene.init(); - m_builtin_textured_scene.init(); - m_builtin_lit_shadowed_scene.init(); - m_builtin_image_scene.init(); m_p_current_scene = &m_basic_scene; m_p_current_scene->use(); @@ -51,22 +43,6 @@ void MyApplication::update(float delta_time, clock_t clock) { swap_scene(&m_builtin_basic_cube_scene); } - else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_6)) - { - swap_scene(&m_builtin_lit_scene); - } - else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_7)) - { - swap_scene(&m_builtin_textured_scene); - } - else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_8)) - { - swap_scene(&m_builtin_lit_shadowed_scene); - } - else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_9)) - { - swap_scene(&m_builtin_image_scene); - } m_p_current_scene->update(delta_time, clock); } diff --git a/Example/MyApplication.h b/Example/MyApplication.h index 32fce1c..9e81b3c 100644 --- a/Example/MyApplication.h +++ b/Example/MyApplication.h @@ -8,15 +8,10 @@ #include "MySimple3DScene.h" #include "MySimpleCubeScene.h" #include "MyBuiltinCubeScene.h" -#include "MyBuiltinLitScene.h" -#include "MyBuiltinTexturedScene.h" -#include "MyBuiltinLitShadowedScene.h" -#include "MyBuiltinImageScene.h" using namespace charcoal; -class MyApplication : - public Application +class MyApplication : public Application { public: MyApplication(int width = -1, int height = -1); @@ -41,9 +36,5 @@ private: MySimple3DScene m_simple_3d_scene; MySimpleCubeScene m_simple_cube_scene; MyBuiltinCubeScene m_builtin_basic_cube_scene; - MyBuiltinLitScene m_builtin_lit_scene; - MyBuiltinTexturedScene m_builtin_textured_scene; - MyBuiltinLitShadowedScene m_builtin_lit_shadowed_scene; // Currently a WIP - MyBuiltinImageScene m_builtin_image_scene; }; diff --git a/Example/MyBuiltinCubeScene.cpp b/Example/MyBuiltinCubeScene.cpp index 5939924..9f77ae7 100644 --- a/Example/MyBuiltinCubeScene.cpp +++ b/Example/MyBuiltinCubeScene.cpp @@ -8,7 +8,7 @@ MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application) : 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)) + m_batch(add_batch(&m_shape, 2)) { add_prerenderable(&m_camera); set_camera(&m_camera); @@ -30,11 +30,11 @@ void MyBuiltinCubeScene::update(float delta_time, clock_t clock) radians = (float)TAU * c / intervals; - { - Poseable& pose = m_batch.get_pose(0); - pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time); - pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); - } + m_pose_a.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time); + m_pose_a.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); + + m_pose_b.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time); + m_pose_b.update_position(vec3(-3 * (float)cos(radians), 0.0f, 0.0f)); vec3 camera_translation(0.0f, 0.0f, 0.0f); @@ -51,5 +51,9 @@ void MyBuiltinCubeScene::update(float delta_time, clock_t clock) m_camera.translate(camera_translation * delta_time); m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)TAU_1_8 * delta_time); + + m_batch.reset_rendered(); + m_batch.add_rendered(m_pose_a); + m_batch.add_rendered(m_pose_b); } diff --git a/Example/MyBuiltinCubeScene.h b/Example/MyBuiltinCubeScene.h index 931a2f7..9acaaa1 100644 --- a/Example/MyBuiltinCubeScene.h +++ b/Example/MyBuiltinCubeScene.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -16,4 +17,7 @@ private: basic::Renderable m_shape; builtin::Camera3D m_camera; basic::Batch& m_batch; + + Poseable m_pose_a; + Poseable m_pose_b; }; \ No newline at end of file diff --git a/Example/MyBuiltinImageScene.cpp b/Example/MyBuiltinImageScene.cpp deleted file mode 100644 index 814cc3f..0000000 --- a/Example/MyBuiltinImageScene.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "MyBuiltinImageScene.h" - -#include -#include -#include -#include - -MyBuiltinImageScene::MyBuiltinImageScene(Application& application) - : image::Scene(application), - m_image(image_loader::load_file(IMAGE_PATH "uber.png")), - m_image_renderable( - meshgenerator::gen_rect_pt(DRAW_TRIANGLES, (float)m_image.width, (float)m_image.height), - TextureFactory::gen_image_texture(m_image), - texturegenerator::gen_quick_sampler(), - DrawMode::DRAW_TRIANGLES - ), - m_camera(m_screen_size), - m_batch(add_batch(&m_image_renderable, 1)) -{ - add_prerenderable(&m_camera); - set_camera(&m_camera); -} - -void MyBuiltinImageScene::update(float delta_time, clock_t clock) -{ - float brightness; - float radians; - - clock_t c; - const clock_t intervals = 512 * CLOCKS_PER_SEC / 100; - const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100; - c = clock % intervals; - if (c < half_interval) - brightness = (float)c / half_interval; - else - brightness = (float)(intervals - c) / half_interval; - - radians = (float)TAU * c / intervals; - - { - Poseable2D& pose = m_batch.get_pose(0); - // pose.rotate((float)TAU_1_4 * delta_time); TODO - pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); - } - - vec3 camera_translation(0.0f, 0.0f, 0.0f); - - if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1; - if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1; - - float camera_rotation = 0.0f; - if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1; - if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1; - - m_camera.translate(camera_translation * delta_time); - // m_camera.rotate(vec3(0.0f, 0.0f, 1.0f), camera_rotation * (float)TAU_1_8 * delta_time); TODO -} - diff --git a/Example/MyBuiltinImageScene.h b/Example/MyBuiltinImageScene.h deleted file mode 100644 index 2a6d922..0000000 --- a/Example/MyBuiltinImageScene.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include -#include - -using namespace charcoal; -using namespace charcoal::builtin; - -class MyBuiltinImageScene : public image::Scene -{ -public: - MyBuiltinImageScene(Application& application); - - void update(float delta_time, clock_t clock) override; -private: - image_loader::ImageRGBA m_image; - image::Renderable m_image_renderable; - builtin::Camera2D m_camera; - image::Batch& m_batch; -}; \ No newline at end of file diff --git a/Example/MyBuiltinLitScene.cpp b/Example/MyBuiltinLitScene.cpp deleted file mode 100644 index d0bb353..0000000 --- a/Example/MyBuiltinLitScene.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "MyBuiltinLitScene.h" - -#include -#include - -MyBuiltinLitScene::MyBuiltinLitScene(Application& application) - : lit::Scene(application), - m_shape( - 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 - ), - 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)) -{ - add_prerenderable(&m_camera); - set_camera(&m_camera); - - add_light( - Position(0.0f, 2.0f, -2.0f), - Light::Power(0.2f, 1.0f, 1.0f), - ColorRGB(1.0f, 1.0f, 1.0f), - ColorRGB(1.0f, 1.0f, 1.0f), - ColorRGB(1.0f, 1.0f, 1.0f), - Light::Fade(1.0f, 0.1f, 0.01f) - ); -} - -void MyBuiltinLitScene::update(float delta_time, clock_t clock) -{ - float brightness; - float radians; - - clock_t c; - const clock_t intervals = 512 * CLOCKS_PER_SEC / 100; - const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100; - c = clock % intervals; - if (c < half_interval) - brightness = (float)c / half_interval; - else - brightness = (float)(intervals - c) / half_interval; - - radians = (float)TAU * c / intervals; - - { - Poseable& pose = m_batch.get_pose(0); - pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_8 * delta_time); - pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); - } - - vec3 camera_translation(0.0f, 0.0f, 0.0f); - - if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1; - if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1; - if (m_input_manager.is_key_down(GLFW_KEY_Q)) camera_translation.z -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_E)) camera_translation.z += 1; - - float camera_rotation = 0.0f; - if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1; - if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1; - - m_camera.translate(camera_translation * delta_time); - m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)TAU_1_8 * delta_time); -} - diff --git a/Example/MyBuiltinLitScene.h b/Example/MyBuiltinLitScene.h deleted file mode 100644 index 283056e..0000000 --- a/Example/MyBuiltinLitScene.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include - -using namespace charcoal; -using namespace charcoal::builtin; - -// 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: - lit::Renderable m_shape; - builtin::Camera3D m_camera; - lit::Batch& m_batch; -}; \ No newline at end of file diff --git a/Example/MyBuiltinLitShadowedScene.cpp b/Example/MyBuiltinLitShadowedScene.cpp deleted file mode 100644 index 25aaa81..0000000 --- a/Example/MyBuiltinLitShadowedScene.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "MyBuiltinLitShadowedScene.h" - -#include -#include - -MyBuiltinLitShadowedScene::MyBuiltinLitShadowedScene(Application& application) - : litshadowed::Scene(application), - m_cube( - 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 - ), - m_plane( - meshgenerator::set_material( - meshgenerator::gen_plane_pn(DRAW_TRIANGLES, 4.0f, 4.0f), - Material(1.0f, 1.0f, 0.2f, 1.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_cube_batch(add_batch(&m_cube, 1)), - m_plane_batch(add_batch(&m_plane, 1)) -{ - add_prerenderable(&m_camera); - set_camera(&m_camera); - - add_light( - Position(0.0f, 2.0f, -2.0f), - Light::Power(0.2f, 1.0f, 1.0f), - ColorRGB(1.0f, 1.0f, 1.0f), - ColorRGB(1.0f, 1.0f, 1.0f), - ColorRGB(1.0f, 1.0f, 1.0f), - Light::Fade(1.0f, 0.1f, 0.01f) - ); -} - -void MyBuiltinLitShadowedScene::update(float delta_time, clock_t clock) -{ - float brightness; - float radians; - - clock_t c; - const clock_t intervals = 512 * CLOCKS_PER_SEC / 100; - const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100; - c = clock % intervals; - if (c < half_interval) - brightness = (float)c / half_interval; - else - brightness = (float)(intervals - c) / half_interval; - - radians = (float)TAU * c / intervals; - - { - Poseable& pose = m_cube_batch.get_pose(0); - pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_8 * delta_time); - pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); - } - - vec3 camera_translation(0.0f, 0.0f, 0.0f); - - if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1; - if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1; - if (m_input_manager.is_key_down(GLFW_KEY_Q)) camera_translation.z -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_E)) camera_translation.z += 1; - - float camera_rotation = 0.0f; - if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1; - if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1; - - m_camera.translate(camera_translation * delta_time); - m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)TAU_1_8 * delta_time); -} - diff --git a/Example/MyBuiltinLitShadowedScene.h b/Example/MyBuiltinLitShadowedScene.h deleted file mode 100644 index 226b651..0000000 --- a/Example/MyBuiltinLitShadowedScene.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include - -using namespace charcoal; -using namespace charcoal::builtin; - -class MyBuiltinLitShadowedScene : public litshadowed::Scene -{ -public: - MyBuiltinLitShadowedScene(Application& application); - - void update(float delta_time, clock_t clock) override; -private: - litshadowed::Renderable m_cube; - litshadowed::Renderable m_plane; - builtin::Camera3D m_camera; - litshadowed::Batch& m_cube_batch; - litshadowed::Batch& m_plane_batch; -}; \ No newline at end of file diff --git a/Example/MyBuiltinTexturedScene.cpp b/Example/MyBuiltinTexturedScene.cpp deleted file mode 100644 index 6920691..0000000 --- a/Example/MyBuiltinTexturedScene.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "MyBuiltinTexturedScene.h" - -#include -#include -#include - -MyBuiltinTexturedScene::MyBuiltinTexturedScene(Application& application) - : textured::Scene(application), - m_shape( - meshgenerator::gen_cube_pt(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), - texturegenerator::gen_quick_cube_texture(), - texturegenerator::gen_quick_sampler(), - 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)) -{ - add_prerenderable(&m_camera); - set_camera(&m_camera); -} - -void MyBuiltinTexturedScene::update(float delta_time, clock_t clock) -{ - float brightness; - float radians; - - clock_t c; - const clock_t intervals = 512 * CLOCKS_PER_SEC / 100; - const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100; - c = clock % intervals; - if (c < half_interval) - brightness = (float)c / half_interval; - else - brightness = (float)(intervals - c) / half_interval; - - radians = (float)TAU * c / intervals; - - { - Poseable& pose = m_batch.get_pose(0); - pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_4 * delta_time); - pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f)); - } - - vec3 camera_translation(0.0f, 0.0f, 0.0f); - - if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1; - if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1; - if (m_input_manager.is_key_down(GLFW_KEY_Q)) camera_translation.z -= 1; - if (m_input_manager.is_key_down(GLFW_KEY_E)) camera_translation.z += 1; - - float camera_rotation = 0.0f; - if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1; - if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1; - - m_camera.translate(camera_translation * delta_time); - m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)TAU_1_8 * delta_time); -} - diff --git a/Example/MyBuiltinTexturedScene.h b/Example/MyBuiltinTexturedScene.h deleted file mode 100644 index 72a123d..0000000 --- a/Example/MyBuiltinTexturedScene.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include - -using namespace charcoal; -using namespace charcoal::builtin; - -class MyBuiltinTexturedScene : public textured::Scene -{ -public: - MyBuiltinTexturedScene(Application& application); - - void update(float delta_time, clock_t clock) override; -private: - textured::Renderable m_shape; - builtin::Camera3D m_camera; - textured::Batch& m_batch; -}; \ No newline at end of file diff --git a/Example/MySpecifiedScene.cpp b/Example/MySpecifiedScene.cpp deleted file mode 100644 index 9fbb296..0000000 --- a/Example/MySpecifiedScene.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "MySpecifiedScene.h" - -#include - -#include - -MyBuiltinSpecifiedScene::MyBuiltinSpecifiedScene(Application& application) - : specified::Scene(application), - m_shape(meshgenerator::gen_cube_p(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), 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, 2)), - m_pose_a(m_batch), - m_pose_b(m_batch) -{ - add_prerenderable(&m_camera); - set_camera(&m_camera); - - m_pose_a.update_position(glm::vec3(-4.0f, 0.0f, 0.0f)); - m_pose_a.update_position(glm::vec3(4.0f, 0.0f, 0.0f)); -} - -void MyBuiltinSpecifiedScene::update(float delta_time, clock_t clock) -{ - m_batch.reset(); - m_pose_a.render(); -} \ No newline at end of file diff --git a/Example/MySpecifiedScene.h b/Example/MySpecifiedScene.h deleted file mode 100644 index 8c2b980..0000000 --- a/Example/MySpecifiedScene.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include - -using namespace charcoal; -using namespace charcoal::builtin; - -class MyBuiltinSpecifiedScene : public specified::Scene -{ -public: - MyBuiltinSpecifiedScene(Application& application); - - void update(float delta_time, clock_t clock) override; - -private: - basic::Renderable m_shape; - builtin::Camera3D m_camera; - specified::Batch& m_batch; - - SpecifiedPoseable m_pose_a; - SpecifiedPoseable m_pose_b; -}; \ No newline at end of file