From 991b52b2338f03192b9a6f694a2e8fe6be57fdf8 Mon Sep 17 00:00:00 2001 From: elipzer Date: Thu, 13 Sep 2018 00:51:47 -0400 Subject: [PATCH] Almost Finished Builtin Builtin general structure created. Added a builtin::BasicScene class for quick general testing of the engine on different systems. The builtin::BasicScene class greatly reduces the amount of code needed to be handled by the developer by offering a pre-made way to handle it. It even includes pre-made shaders! --- OpenGLEngine/BasicBatch.cpp | 43 +++++ OpenGLEngine/BasicBatch.h | 44 +++++ OpenGLEngine/BasicFS.glsl | 6 + OpenGLEngine/BasicScene.cpp | 67 ++++++++ OpenGLEngine/BasicScene.h | 40 +++++ OpenGLEngine/BasicShaderProgram.h | 15 ++ OpenGLEngine/BasicVS.glsl | 10 ++ OpenGLEngine/Batch.h | 2 +- OpenGLEngine/GLUtil.cpp | 22 +++ OpenGLEngine/GLUtil.h | 17 ++ OpenGLEngine/MeshGenerator.h | 163 ++++++++++++++++++- OpenGLEngine/MeshTypes.h | 12 ++ OpenGLEngine/MyApplication.cpp | 12 +- OpenGLEngine/MyApplication.h | 2 + OpenGLEngine/MyBasicShaderProgram.cpp | 13 -- OpenGLEngine/MyBasicShaderProgram.h | 10 +- OpenGLEngine/MyBuiltinBasicCubeScene.cpp | 16 ++ OpenGLEngine/MyBuiltinBasicCubeScene.h | 22 +++ OpenGLEngine/MySimpleShaderProgram.cpp | 13 -- OpenGLEngine/MySimpleShaderProgram.h | 10 +- OpenGLEngine/OpenGLEngine.vcxproj | 17 +- OpenGLEngine/OpenGLEngine.vcxproj.filters | 54 +++++- OpenGLEngine/PassthroughFS.glsl | 2 + OpenGLEngine/PassthroughVS.glsl | 1 + OpenGLEngine/VertexFragmentShaderProgram.cpp | 16 ++ OpenGLEngine/VertexFragmentShaderProgram.h | 18 ++ 26 files changed, 588 insertions(+), 59 deletions(-) create mode 100644 OpenGLEngine/BasicBatch.cpp create mode 100644 OpenGLEngine/BasicBatch.h create mode 100644 OpenGLEngine/BasicFS.glsl create mode 100644 OpenGLEngine/BasicScene.cpp create mode 100644 OpenGLEngine/BasicScene.h create mode 100644 OpenGLEngine/BasicShaderProgram.h create mode 100644 OpenGLEngine/BasicVS.glsl create mode 100644 OpenGLEngine/GLUtil.cpp create mode 100644 OpenGLEngine/GLUtil.h delete mode 100644 OpenGLEngine/MyBasicShaderProgram.cpp create mode 100644 OpenGLEngine/MyBuiltinBasicCubeScene.cpp create mode 100644 OpenGLEngine/MyBuiltinBasicCubeScene.h delete mode 100644 OpenGLEngine/MySimpleShaderProgram.cpp create mode 100644 OpenGLEngine/PassthroughFS.glsl create mode 100644 OpenGLEngine/PassthroughVS.glsl create mode 100644 OpenGLEngine/VertexFragmentShaderProgram.cpp create mode 100644 OpenGLEngine/VertexFragmentShaderProgram.h diff --git a/OpenGLEngine/BasicBatch.cpp b/OpenGLEngine/BasicBatch.cpp new file mode 100644 index 0000000..878e7fa --- /dev/null +++ b/OpenGLEngine/BasicBatch.cpp @@ -0,0 +1,43 @@ +#include "BasicBatch.h" + +namespace charcoal +{ + namespace builtin + { + void BasicBatch::setup_element_buffers() + { + glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]); + glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); + } + + void BasicBatch::setup_vao() + { + glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 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 + } + + void BasicBatch::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, 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()); + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/BasicBatch.h b/OpenGLEngine/BasicBatch.h new file mode 100644 index 0000000..817b480 --- /dev/null +++ b/OpenGLEngine/BasicBatch.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include "MeshTypes.h" +#include "Batch.h" +#include "Poseable.h" + +namespace charcoal +{ + namespace builtin + { + // TODO: Consider namespacing basic + class BasicBatch : public Batch + { + public: + BasicBatch( + BasicRenderable* renderable, + const SizeType& element_count + ) : BasicBatch(renderable, element_count, element_count) {} + + BasicBatch( + BasicRenderable* renderable, + const SizeType& element_count, + const SizeType& element_render_count + ) : Batch(renderable, element_render_count), m_pose_elements(element_count) {} + + virtual ~BasicBatch() {} + + Poseable& get_pose(const SizeType& index) { return m_pose_elements[index]; } + const Poseable& get_pose(const SizeType& index) const { return m_pose_elements[index]; } + + protected: + void setup_element_buffers() override; + + void setup_vao() override; + + void update_element_buffers() override; + + private: + std::vector m_pose_elements; + }; + } +} \ No newline at end of file diff --git a/OpenGLEngine/BasicFS.glsl b/OpenGLEngine/BasicFS.glsl new file mode 100644 index 0000000..e3a49de --- /dev/null +++ b/OpenGLEngine/BasicFS.glsl @@ -0,0 +1,6 @@ +#version 430 +out vec4 frag_color; +void main() +{ + frag_color = vec4(1.0, 1.0, 1.0, 1.0); +} \ No newline at end of file diff --git a/OpenGLEngine/BasicScene.cpp b/OpenGLEngine/BasicScene.cpp new file mode 100644 index 0000000..df32130 --- /dev/null +++ b/OpenGLEngine/BasicScene.cpp @@ -0,0 +1,67 @@ +#include "BasicScene.h" + +#include "stdafx.h" + +#include "GLUtil.h" + +namespace charcoal +{ + namespace builtin + { + BasicScene::BasicScene(Application& application) + : Scene(application), m_camera((float)TAU_1_4, (float)m_screen_size.x / (float)m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f)) + {} + + void BasicScene::init() + { + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->init(); + } + } + + void BasicScene::use() + { + // TODO: move to glutil + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + } + + void BasicScene::unuse() + { + + } + + void BasicScene::prerender() + { + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->prerender(); + } + m_camera.prerender(); + } + + void BasicScene::render() + { + // TODO: This is not rendering :( + glutil::clear_screen(); + m_shader_program.use(); + glutil::uniform_matrix(0, m_camera.get_world_to_view_matrix()); + for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) + { + iter->render(); + } + } + + BasicBatch* BasicScene::add_batch(BasicRenderable* renderable, int element_count) + { + return add_batch(renderable, element_count, element_count); + } + + BasicBatch* BasicScene::add_batch(BasicRenderable* renderable, int element_count, int element_render_count) + { + m_batches.emplace_back(renderable, element_count, element_render_count); + return &m_batches.back(); + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/BasicScene.h b/OpenGLEngine/BasicScene.h new file mode 100644 index 0000000..3a1730b --- /dev/null +++ b/OpenGLEngine/BasicScene.h @@ -0,0 +1,40 @@ +#pragma once + +#include "Scene.h" + +#include "BasicShaderProgram.h" +#include "BasicBatch.h" +#include "Camera3D.h" + +#include "constants.h" + +namespace charcoal +{ + namespace builtin + { + class BasicScene : public Scene + { + public: + BasicScene(Application& application); + ~BasicScene() {} + + void init() override; + + void use() override; + + void unuse() override; + + void prerender() override; + + void render() override; + + protected: + BasicBatch* add_batch(BasicRenderable* renderable, int element_count); + BasicBatch* add_batch(BasicRenderable* renderable, int element_count, int element_render_count); + + BasicShaderProgram m_shader_program; + std::vector m_batches; + Camera3D m_camera; + }; + } +} \ No newline at end of file diff --git a/OpenGLEngine/BasicShaderProgram.h b/OpenGLEngine/BasicShaderProgram.h new file mode 100644 index 0000000..8181135 --- /dev/null +++ b/OpenGLEngine/BasicShaderProgram.h @@ -0,0 +1,15 @@ +#pragma once + +#include "VertexFragmentShaderProgram.h" + +namespace charcoal +{ + namespace builtin + { + class BasicShaderProgram : public VertexFragmentShaderProgram + { + public: + BasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "BasicVS.glsl", SHADER_PATH "BasicFS.glsl") {} + }; + } +} diff --git a/OpenGLEngine/BasicVS.glsl b/OpenGLEngine/BasicVS.glsl new file mode 100644 index 0000000..70f1cdf --- /dev/null +++ b/OpenGLEngine/BasicVS.glsl @@ -0,0 +1,10 @@ +#version 430 +layout(location = 0) in vec3 vertex_position; +layout(location = 1) in mat4 model_to_world; + +layout(location = 0) uniform mat4 world_to_projection; + +void main() +{ + gl_Position = world_to_projection * model_to_world * vec4(vertex_position, 1.0); +} \ No newline at end of file diff --git a/OpenGLEngine/Batch.h b/OpenGLEngine/Batch.h index 93a5a58..e6454be 100644 --- a/OpenGLEngine/Batch.h +++ b/OpenGLEngine/Batch.h @@ -9,7 +9,7 @@ namespace charcoal { - template > + template > class Batch { public: diff --git a/OpenGLEngine/GLUtil.cpp b/OpenGLEngine/GLUtil.cpp new file mode 100644 index 0000000..8babb44 --- /dev/null +++ b/OpenGLEngine/GLUtil.cpp @@ -0,0 +1,22 @@ +#include "GLUtil.h" + +#include "stdafx.h" + +namespace charcoal +{ + namespace builtin + { + namespace glutil + { + void clear_screen() + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose) + { + glUniformMatrix4fv(uniform_index, 1, transpose ? GL_TRUE : GL_FALSE, &matrix[0][0]); + } + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/GLUtil.h b/OpenGLEngine/GLUtil.h new file mode 100644 index 0000000..d9eacbc --- /dev/null +++ b/OpenGLEngine/GLUtil.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace charcoal +{ + namespace builtin + { + namespace glutil + { + using namespace glm; + + void clear_screen(); + void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose = false); + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/MeshGenerator.h b/OpenGLEngine/MeshGenerator.h index 98fc4eb..a84f4dc 100644 --- a/OpenGLEngine/MeshGenerator.h +++ b/OpenGLEngine/MeshGenerator.h @@ -8,23 +8,168 @@ #include "MeshTypes.h" +// TODO: Consider a mesh generator for every render type (i.e. basic::meshgenerator, lit::meshgenerator, etc.) + namespace charcoal { namespace builtin { // Uses MeshFactory to generate meshes for the builtin vertex types. - class MeshGenerator + namespace meshgenerator { - private: - MeshGenerator() {} + template + Mesh* gen_cube_p(const DrawMode& draw_mode, float width, float height, float depth) + { + static_assert(std::is_base_of::value, "VertexType must be Positioned"); + + Mesh* mesh; + + float x = width / 2.0f; + float y = height / 2.0f; + float z = depth / 2.0f; + + Position pos0(-x, y, -z); // Front Left Top + Position pos1(-x, -y, -z); // Front Left Bottom + Position pos2(x, y, -z); // Front Right Top + Position pos3(x, -y, -z); // Front Right Bottom + Position pos4(-x, y, z); // Back Left Top + Position pos5(-x, -y, z); // Back Left Bottom + Position pos6(x, y, z); // Back Right Top + Position pos7(x, -y, z); // Back Right Bottom + + switch (draw_mode) + { + case DrawMode::DRAW_POINTS: + mesh = MeshFactory::create_mesh(8, 8); + mesh->vertices[0].set_position(pos0); + mesh->vertices[1].set_position(pos1); + mesh->vertices[2].set_position(pos2); + mesh->vertices[3].set_position(pos3); + mesh->vertices[4].set_position(pos4); + mesh->vertices[5].set_position(pos5); + mesh->vertices[6].set_position(pos6); + mesh->vertices[7].set_position(pos7); + mesh->indices[0] = 0; + mesh->indices[1] = 1; + mesh->indices[2] = 3; + mesh->indices[3] = 3; + mesh->indices[4] = 4; + mesh->indices[5] = 5; + mesh->indices[6] = 6; + mesh->indices[7] = 7; + return mesh; + case DrawMode::DRAW_LINES: + mesh = MeshFactory::create_mesh(8, 24); + mesh->vertices[0].set_position(pos0); + mesh->vertices[1].set_position(pos1); + mesh->vertices[2].set_position(pos2); + mesh->vertices[3].set_position(pos3); + mesh->vertices[4].set_position(pos4); + mesh->vertices[5].set_position(pos5); + mesh->vertices[6].set_position(pos6); + mesh->vertices[7].set_position(pos7); + // Front + mesh->indices[0] = 0; + mesh->indices[1] = 1; + mesh->indices[2] = 1; + mesh->indices[3] = 2; + mesh->indices[4] = 2; + mesh->indices[5] = 3; + mesh->indices[6] = 3; + mesh->indices[7] = 0; + // Back + mesh->indices[8] = 4; + mesh->indices[9] = 5; + mesh->indices[10] = 5; + mesh->indices[11] = 6; + mesh->indices[12] = 6; + mesh->indices[13] = 7; + mesh->indices[14] = 7; + mesh->indices[15] = 4; + // Connecting + mesh->indices[16] = 0; + mesh->indices[17] = 4; + mesh->indices[18] = 1; + mesh->indices[19] = 5; + mesh->indices[20] = 2; + mesh->indices[21] = 6; + mesh->indices[22] = 3; + mesh->indices[23] = 7; + return mesh; + case DrawMode::DRAW_TRIANGLES: + mesh = MeshFactory::create_mesh(8, 36); + mesh->vertices[0].set_position(pos0); + mesh->vertices[1].set_position(pos1); + mesh->vertices[2].set_position(pos2); + mesh->vertices[3].set_position(pos3); + mesh->vertices[4].set_position(pos4); + mesh->vertices[5].set_position(pos5); + mesh->vertices[6].set_position(pos6); + mesh->vertices[7].set_position(pos7); + // Counter Clockwise + // Front + mesh->indices[0] = 1; + mesh->indices[1] = 3; + mesh->indices[2] = 0; + mesh->indices[3] = 0; + mesh->indices[4] = 3; + mesh->indices[5] = 2; + // Right + mesh->indices[6] = 3; + mesh->indices[7] = 7; + mesh->indices[8] = 2; + mesh->indices[9] = 2; + mesh->indices[10] = 7; + mesh->indices[11] = 6; + // Back + mesh->indices[12] = 7; + mesh->indices[13] = 5; + mesh->indices[14] = 6; + mesh->indices[15] = 6; + mesh->indices[16] = 5; + mesh->indices[17] = 4; + // Left + mesh->indices[18] = 5; + mesh->indices[19] = 1; + mesh->indices[20] = 4; + mesh->indices[21] = 4; + mesh->indices[22] = 1; + mesh->indices[23] = 0; + // Top + mesh->indices[24] = 0; + mesh->indices[25] = 2; + mesh->indices[26] = 4; + mesh->indices[27] = 4; + mesh->indices[28] = 2; + mesh->indices[29] = 6; + // Bottom + mesh->indices[30] = 5; + mesh->indices[31] = 7; + mesh->indices[32] = 1; + mesh->indices[33] = 1; + mesh->indices[34] = 7; + mesh->indices[35] = 3; + return mesh; + case DrawMode::DRAW_LINE_STRIP: + case DrawMode::DRAW_LINE_LOOP: + case DrawMode::DRAW_TRIANGLE_STRIP: + case DrawMode::DRAW_TRIANGLE_FAN: + case DrawMode::DRAW_LINE_STRIP_ADJACENCY: + case DrawMode::DRAW_LINES_ADJACENCY: + case DrawMode::DRAW_TRIANGLE_STRIP_ADJACENCY: + case DrawMode::DRAW_TRIANGLES_ADJACENCY: + case DrawMode::DRAW_PATCHES: + default: + throw EXCEPTION("Unable to gen_cube for current draw mode: " + std::to_string(draw_mode)); + } + } - public: // Creates a cube centered at the origin with specified width, height, and depth template - Mesh* MeshGenerator::gen_cube(const DrawMode& draw_mode, float width, float height, float depth) + Mesh* gen_cube_pn(const DrawMode& draw_mode, float width, float height, float depth) { - static_assert(std::is_base_of::value); - static_assert(std::is_base_of::value); + static_assert(std::is_base_of::value, "VertexType must be Positioned"); + static_assert(std::is_base_of::value, "VertexType must be Normaled"); Mesh* mesh; @@ -50,7 +195,7 @@ namespace charcoal switch (draw_mode) { case DrawMode::DRAW_TRIANGLES: - mesh = MeshFactory::create_mesh(24, 36); + mesh = MeshFactory::create_mesh(24, 36); mesh->vertices[0].set_normal(front); mesh->vertices[1].set_normal(front); mesh->vertices[2].set_normal(front); @@ -172,6 +317,6 @@ namespace charcoal } // TODO: Mesh* gen_cube(const DrawMode& draw_mode, float width, float height, float depth); - }; + } } } diff --git a/OpenGLEngine/MeshTypes.h b/OpenGLEngine/MeshTypes.h index 9a0e4ac..7661d0f 100644 --- a/OpenGLEngine/MeshTypes.h +++ b/OpenGLEngine/MeshTypes.h @@ -1,6 +1,7 @@ #pragma once #include +#include "Renderable.h" namespace charcoal { @@ -37,6 +38,17 @@ namespace charcoal // Simple types that implement the interfaces + struct BasicVertex : public Positioned + { + void set_position(const Position& position) override { this->position = position; } + + Position position; + }; + + typedef Index BasicIndex; + + typedef Renderable BasicRenderable; + struct PNVertex : public Positioned, public Normaled { void set_position(const Position& position) override { this->position = position; } diff --git a/OpenGLEngine/MyApplication.cpp b/OpenGLEngine/MyApplication.cpp index e879ff4..c3cc5b2 100644 --- a/OpenGLEngine/MyApplication.cpp +++ b/OpenGLEngine/MyApplication.cpp @@ -1,7 +1,12 @@ #include "MyApplication.h" MyApplication::MyApplication(int width, int height) - : Application(width, height), m_basic_scene(*this), m_simple_2d_scene(*this), m_simple_3d_scene(*this), m_simple_cube_scene(*this) + : Application(width, height), + m_basic_scene(*this), + m_simple_2d_scene(*this), + m_simple_3d_scene(*this), + m_simple_cube_scene(*this), + m_builtin_basic_cube_scene(*this) {} void MyApplication::init() @@ -10,6 +15,7 @@ void MyApplication::init() m_simple_2d_scene.init(); m_simple_3d_scene.init(); m_simple_cube_scene.init(); + m_builtin_basic_cube_scene.init(); m_p_current_scene = &m_basic_scene; m_p_current_scene->use(); @@ -33,6 +39,10 @@ void MyApplication::update(float delta_time, clock_t clock) { swap_scene(&m_simple_cube_scene); } + else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_5)) + { + swap_scene(&m_builtin_basic_cube_scene); + } m_p_current_scene->update(delta_time, clock); } diff --git a/OpenGLEngine/MyApplication.h b/OpenGLEngine/MyApplication.h index 96250d5..002daa0 100644 --- a/OpenGLEngine/MyApplication.h +++ b/OpenGLEngine/MyApplication.h @@ -5,6 +5,7 @@ #include "MySimple2DScene.h" #include "MySimple3DScene.h" #include "MySimpleCubeScene.h" +#include "MyBuiltinBasicCubeScene.h" using namespace charcoal; @@ -33,5 +34,6 @@ private: MySimple2DScene m_simple_2d_scene; MySimple3DScene m_simple_3d_scene; MySimpleCubeScene m_simple_cube_scene; + MyBuiltinBasicCubeScene m_builtin_basic_cube_scene; }; diff --git a/OpenGLEngine/MyBasicShaderProgram.cpp b/OpenGLEngine/MyBasicShaderProgram.cpp deleted file mode 100644 index b133d14..0000000 --- a/OpenGLEngine/MyBasicShaderProgram.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "MyBasicShaderProgram.h" - -#include "Util.h" - -MyBasicShaderProgram::MyBasicShaderProgram() - : ShaderProgram(), - m_vertex_shader(Util::load_file(SHADER_PATH "MyBasicVS.glsl"), VERTEX_SHADER), - m_fragment_shader(Util::load_file(SHADER_PATH "MyBasicFS.glsl"), FRAGMENT_SHADER) -{ - attach_shader(m_vertex_shader); - attach_shader(m_fragment_shader); - link(); -} \ No newline at end of file diff --git a/OpenGLEngine/MyBasicShaderProgram.h b/OpenGLEngine/MyBasicShaderProgram.h index 5406134..27a0f01 100644 --- a/OpenGLEngine/MyBasicShaderProgram.h +++ b/OpenGLEngine/MyBasicShaderProgram.h @@ -1,13 +1,13 @@ #pragma once -#include "ShaderProgram.h" +#include "VertexFragmentShaderProgram.h" #include "Shader.h" #include "Mesh.h" #include "Renderable.h" using namespace charcoal; -class MyBasicShaderProgram : public ShaderProgram +class MyBasicShaderProgram : public VertexFragmentShaderProgram { public: struct Vertex @@ -31,9 +31,5 @@ public: typedef Renderable Renderable; typedef Mesh Mesh; - MyBasicShaderProgram(); - -private: - Shader m_vertex_shader; - Shader m_fragment_shader; + MyBasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MyBasicVS.glsl", SHADER_PATH "MyBasicFS.glsl") {} }; \ No newline at end of file diff --git a/OpenGLEngine/MyBuiltinBasicCubeScene.cpp b/OpenGLEngine/MyBuiltinBasicCubeScene.cpp new file mode 100644 index 0000000..929df2d --- /dev/null +++ b/OpenGLEngine/MyBuiltinBasicCubeScene.cpp @@ -0,0 +1,16 @@ +#include "MyBuiltinBasicCubeScene.h" + +#include "MeshGenerator.h" +#include "DrawMode.h" + +MyBuiltinBasicCubeScene::MyBuiltinBasicCubeScene(Application& application) + : BasicScene(application), + m_cube(meshgenerator::gen_cube_p(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DRAW_TRIANGLES) +{ + add_batch(&m_cube, 1); +} + +void MyBuiltinBasicCubeScene::update(float delta_time, clock_t clock) +{ + // Do nothing (for now) +} \ No newline at end of file diff --git a/OpenGLEngine/MyBuiltinBasicCubeScene.h b/OpenGLEngine/MyBuiltinBasicCubeScene.h new file mode 100644 index 0000000..51a39d4 --- /dev/null +++ b/OpenGLEngine/MyBuiltinBasicCubeScene.h @@ -0,0 +1,22 @@ +#pragma once + +#include "BasicScene.h" + +#include "BasicShaderProgram.h" +#include "BasicBatch.h" +#include "Camera3D.h" +#include "MeshTypes.h" + +using namespace charcoal; +using namespace charcoal::builtin; + +class MyBuiltinBasicCubeScene : public BasicScene +{ +public: + MyBuiltinBasicCubeScene(Application& application); + ~MyBuiltinBasicCubeScene() {} + + void update(float delta_time, clock_t clock) override; +private: + BasicRenderable m_cube; +}; \ No newline at end of file diff --git a/OpenGLEngine/MySimpleShaderProgram.cpp b/OpenGLEngine/MySimpleShaderProgram.cpp deleted file mode 100644 index 53bf15b..0000000 --- a/OpenGLEngine/MySimpleShaderProgram.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "MySimpleShaderProgram.h" - -#include "Util.h" - -MySimpleShaderProgram::MySimpleShaderProgram() - : ShaderProgram(), - m_vertex_shader(Util::load_file(SHADER_PATH "MySimpleVS.glsl"), VERTEX_SHADER), - m_fragment_shader(Util::load_file(SHADER_PATH "MySimpleFS.glsl"), FRAGMENT_SHADER) -{ - attach_shader(m_vertex_shader); - attach_shader(m_fragment_shader); - link(); -} diff --git a/OpenGLEngine/MySimpleShaderProgram.h b/OpenGLEngine/MySimpleShaderProgram.h index b149983..c49b8ec 100644 --- a/OpenGLEngine/MySimpleShaderProgram.h +++ b/OpenGLEngine/MySimpleShaderProgram.h @@ -1,13 +1,13 @@ #pragma once -#include "ShaderProgram.h" +#include "VertexFragmentShaderProgram.h" #include "Shader.h" #include "Mesh.h" #include "Renderable.h" using namespace charcoal; -class MySimpleShaderProgram : public ShaderProgram +class MySimpleShaderProgram : public VertexFragmentShaderProgram { public: struct Vertex @@ -31,9 +31,5 @@ public: typedef Renderable Renderable; typedef Mesh Mesh; - MySimpleShaderProgram(); - -private: - Shader m_vertex_shader; - Shader m_fragment_shader; + MySimpleShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MySimpleVS.glsl", SHADER_PATH "MySimpleFS.glsl") {} }; diff --git a/OpenGLEngine/OpenGLEngine.vcxproj b/OpenGLEngine/OpenGLEngine.vcxproj index 12bf742..bddb5ac 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj +++ b/OpenGLEngine/OpenGLEngine.vcxproj @@ -152,19 +152,22 @@ + + + + + - - @@ -177,6 +180,9 @@ + + + @@ -185,11 +191,14 @@ + + + @@ -208,10 +217,14 @@ + + + + diff --git a/OpenGLEngine/OpenGLEngine.vcxproj.filters b/OpenGLEngine/OpenGLEngine.vcxproj.filters index 915d100..35711f5 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj.filters +++ b/OpenGLEngine/OpenGLEngine.vcxproj.filters @@ -58,6 +58,9 @@ {233b4bce-fc64-4ad1-994e-c986befa7ff2} + + {ca004137-6425-4863-b91a-cf32988855be} + @@ -111,15 +114,24 @@ Source Files\Example\Application - - Source Files\Example\Rendering - - - Source Files\Example\Rendering - Source Files\Example\Application + + Source Files\Engine\builtin + + + Source Files\Engine\Rendering + + + Source Files\Engine\builtin + + + Source Files\Engine\builtin + + + Source Files\Example\Application + @@ -212,6 +224,24 @@ Header Files\Engine\builtin + + Header Files\Engine\builtin + + + Header Files\Engine\builtin + + + Header Files\Engine\Rendering + + + Header Files\Engine\builtin + + + Header Files\Engine\builtin + + + Header Files\Example\Application + @@ -226,5 +256,17 @@ Source Files\Example\Rendering\Shader Code + + Source Files\Engine\builtin\Shaders + + + Source Files\Engine\builtin\Shaders + + + Source Files\Engine\builtin\Shaders + + + Source Files\Engine\builtin\Shaders + \ No newline at end of file diff --git a/OpenGLEngine/PassthroughFS.glsl b/OpenGLEngine/PassthroughFS.glsl new file mode 100644 index 0000000..ce4c83b --- /dev/null +++ b/OpenGLEngine/PassthroughFS.glsl @@ -0,0 +1,2 @@ +// TODO +// Could be same as BasicFS.glsl ... \ No newline at end of file diff --git a/OpenGLEngine/PassthroughVS.glsl b/OpenGLEngine/PassthroughVS.glsl new file mode 100644 index 0000000..0ffdd02 --- /dev/null +++ b/OpenGLEngine/PassthroughVS.glsl @@ -0,0 +1 @@ +// TODO \ No newline at end of file diff --git a/OpenGLEngine/VertexFragmentShaderProgram.cpp b/OpenGLEngine/VertexFragmentShaderProgram.cpp new file mode 100644 index 0000000..1035041 --- /dev/null +++ b/OpenGLEngine/VertexFragmentShaderProgram.cpp @@ -0,0 +1,16 @@ +#include "VertexFragmentShaderProgram.h" + +#include "Util.h" + +namespace charcoal +{ + VertexFragmentShaderProgram::VertexFragmentShaderProgram(const std::string& vertex_shader_path, const std::string& fragment_shader_path) + : ShaderProgram(), + m_vertex_shader(Util::load_file(vertex_shader_path), VERTEX_SHADER), + m_fragment_shader(Util::load_file(fragment_shader_path), FRAGMENT_SHADER) + { + attach_shader(m_vertex_shader); + attach_shader(m_fragment_shader); + link(); + } +} \ No newline at end of file diff --git a/OpenGLEngine/VertexFragmentShaderProgram.h b/OpenGLEngine/VertexFragmentShaderProgram.h new file mode 100644 index 0000000..b13d00e --- /dev/null +++ b/OpenGLEngine/VertexFragmentShaderProgram.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "ShaderProgram.h" + +namespace charcoal +{ + class VertexFragmentShaderProgram : public ShaderProgram + { + public: + VertexFragmentShaderProgram(const std::string& vertex_shader_path, const std::string& fragment_shader_path); + private: + // Needed for their destructors + Shader m_vertex_shader; + Shader m_fragment_shader; + }; +} \ No newline at end of file