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!
This commit is contained in:
elipzer 2018-09-13 00:51:47 -04:00
parent 31e3d15ab1
commit 991b52b233
26 changed files with 588 additions and 59 deletions

View File

@ -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());
}
}
}

44
OpenGLEngine/BasicBatch.h Normal file
View File

@ -0,0 +1,44 @@
#pragma once
#include <vector>
#include "MeshTypes.h"
#include "Batch.h"
#include "Poseable.h"
namespace charcoal
{
namespace builtin
{
// TODO: Consider namespacing basic
class BasicBatch : public Batch<BasicVertex, Index, 1>
{
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<Poseable> m_pose_elements;
};
}
}

View File

@ -0,0 +1,6 @@
#version 430
out vec4 frag_color;
void main()
{
frag_color = vec4(1.0, 1.0, 1.0, 1.0);
}

View File

@ -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();
}
}
}

40
OpenGLEngine/BasicScene.h Normal file
View File

@ -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<BasicBatch> m_batches;
Camera3D m_camera;
};
}
}

View File

@ -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") {}
};
}
}

10
OpenGLEngine/BasicVS.glsl Normal file
View File

@ -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);
}

View File

@ -9,7 +9,7 @@
namespace charcoal namespace charcoal
{ {
template <typename VertexType, typename IndexType, int element_buffer_count = 0, typename Renderable = Renderable<VertexType, IndexType> > template <typename VertexType, typename IndexType, int element_buffer_count, typename Renderable = Renderable<VertexType, IndexType> >
class Batch class Batch
{ {
public: public:

22
OpenGLEngine/GLUtil.cpp Normal file
View File

@ -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]);
}
}
}
}

17
OpenGLEngine/GLUtil.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <glm/glm.hpp>
namespace charcoal
{
namespace builtin
{
namespace glutil
{
using namespace glm;
void clear_screen();
void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose = false);
}
}
}

View File

@ -8,23 +8,168 @@
#include "MeshTypes.h" #include "MeshTypes.h"
// TODO: Consider a mesh generator for every render type (i.e. basic::meshgenerator, lit::meshgenerator, etc.)
namespace charcoal namespace charcoal
{ {
namespace builtin namespace builtin
{ {
// Uses MeshFactory to generate meshes for the builtin vertex types. // Uses MeshFactory to generate meshes for the builtin vertex types.
class MeshGenerator namespace meshgenerator
{ {
private: template <typename VertexType, typename IndexType>
MeshGenerator() {} Mesh<VertexType, IndexType>* gen_cube_p(const DrawMode& draw_mode, float width, float height, float depth)
{
static_assert(std::is_base_of<Positioned, VertexType>::value, "VertexType must be Positioned");
Mesh<VertexType, IndexType>* 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<VertexType, IndexType>::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<VertexType, IndexType>::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<VertexType, IndexType>::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 // Creates a cube centered at the origin with specified width, height, and depth
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType>
Mesh<VertexType, IndexType>* MeshGenerator::gen_cube(const DrawMode& draw_mode, float width, float height, float depth) Mesh<VertexType, IndexType>* gen_cube_pn(const DrawMode& draw_mode, float width, float height, float depth)
{ {
static_assert(std::is_base_of<Positioned, VertexType>::value); static_assert(std::is_base_of<Positioned, VertexType>::value, "VertexType must be Positioned");
static_assert(std::is_base_of<Normaled, VertexType>::value); static_assert(std::is_base_of<Normaled, VertexType>::value, "VertexType must be Normaled");
Mesh<VertexType, IndexType>* mesh; Mesh<VertexType, IndexType>* mesh;
@ -50,7 +195,7 @@ namespace charcoal
switch (draw_mode) switch (draw_mode)
{ {
case DrawMode::DRAW_TRIANGLES: case DrawMode::DRAW_TRIANGLES:
mesh = MeshFactory<PNVertex, Index>::create_mesh(24, 36); mesh = MeshFactory<VertexType, IndexType>::create_mesh(24, 36);
mesh->vertices[0].set_normal(front); mesh->vertices[0].set_normal(front);
mesh->vertices[1].set_normal(front); mesh->vertices[1].set_normal(front);
mesh->vertices[2].set_normal(front); mesh->vertices[2].set_normal(front);
@ -172,6 +317,6 @@ namespace charcoal
} }
// TODO: Mesh<PNTVertex, Index>* gen_cube(const DrawMode& draw_mode, float width, float height, float depth); // TODO: Mesh<PNTVertex, Index>* gen_cube(const DrawMode& draw_mode, float width, float height, float depth);
}; }
} }
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "Renderable.h"
namespace charcoal namespace charcoal
{ {
@ -37,6 +38,17 @@ namespace charcoal
// Simple types that implement the interfaces // 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<BasicVertex, BasicIndex> BasicRenderable;
struct PNVertex : public Positioned, public Normaled struct PNVertex : public Positioned, public Normaled
{ {
void set_position(const Position& position) override { this->position = position; } void set_position(const Position& position) override { this->position = position; }

View File

@ -1,7 +1,12 @@
#include "MyApplication.h" #include "MyApplication.h"
MyApplication::MyApplication(int width, int height) 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() void MyApplication::init()
@ -10,6 +15,7 @@ void MyApplication::init()
m_simple_2d_scene.init(); m_simple_2d_scene.init();
m_simple_3d_scene.init(); m_simple_3d_scene.init();
m_simple_cube_scene.init(); m_simple_cube_scene.init();
m_builtin_basic_cube_scene.init();
m_p_current_scene = &m_basic_scene; m_p_current_scene = &m_basic_scene;
m_p_current_scene->use(); m_p_current_scene->use();
@ -33,6 +39,10 @@ void MyApplication::update(float delta_time, clock_t clock)
{ {
swap_scene(&m_simple_cube_scene); 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); m_p_current_scene->update(delta_time, clock);
} }

View File

@ -5,6 +5,7 @@
#include "MySimple2DScene.h" #include "MySimple2DScene.h"
#include "MySimple3DScene.h" #include "MySimple3DScene.h"
#include "MySimpleCubeScene.h" #include "MySimpleCubeScene.h"
#include "MyBuiltinBasicCubeScene.h"
using namespace charcoal; using namespace charcoal;
@ -33,5 +34,6 @@ private:
MySimple2DScene m_simple_2d_scene; MySimple2DScene m_simple_2d_scene;
MySimple3DScene m_simple_3d_scene; MySimple3DScene m_simple_3d_scene;
MySimpleCubeScene m_simple_cube_scene; MySimpleCubeScene m_simple_cube_scene;
MyBuiltinBasicCubeScene m_builtin_basic_cube_scene;
}; };

View File

@ -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();
}

View File

@ -1,13 +1,13 @@
#pragma once #pragma once
#include "ShaderProgram.h" #include "VertexFragmentShaderProgram.h"
#include "Shader.h" #include "Shader.h"
#include "Mesh.h" #include "Mesh.h"
#include "Renderable.h" #include "Renderable.h"
using namespace charcoal; using namespace charcoal;
class MyBasicShaderProgram : public ShaderProgram class MyBasicShaderProgram : public VertexFragmentShaderProgram
{ {
public: public:
struct Vertex struct Vertex
@ -31,9 +31,5 @@ public:
typedef Renderable<Vertex, Index> Renderable; typedef Renderable<Vertex, Index> Renderable;
typedef Mesh<Vertex, Index> Mesh; typedef Mesh<Vertex, Index> Mesh;
MyBasicShaderProgram(); MyBasicShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MyBasicVS.glsl", SHADER_PATH "MyBasicFS.glsl") {}
private:
Shader m_vertex_shader;
Shader m_fragment_shader;
}; };

View File

@ -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<BasicVertex, BasicIndex>(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)
}

View File

@ -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;
};

View File

@ -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();
}

View File

@ -1,13 +1,13 @@
#pragma once #pragma once
#include "ShaderProgram.h" #include "VertexFragmentShaderProgram.h"
#include "Shader.h" #include "Shader.h"
#include "Mesh.h" #include "Mesh.h"
#include "Renderable.h" #include "Renderable.h"
using namespace charcoal; using namespace charcoal;
class MySimpleShaderProgram : public ShaderProgram class MySimpleShaderProgram : public VertexFragmentShaderProgram
{ {
public: public:
struct Vertex struct Vertex
@ -31,9 +31,5 @@ public:
typedef Renderable<Vertex, Index> Renderable; typedef Renderable<Vertex, Index> Renderable;
typedef Mesh<Vertex, Index> Mesh; typedef Mesh<Vertex, Index> Mesh;
MySimpleShaderProgram(); MySimpleShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "MySimpleVS.glsl", SHADER_PATH "MySimpleFS.glsl") {}
private:
Shader m_vertex_shader;
Shader m_fragment_shader;
}; };

View File

@ -152,19 +152,22 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Application.cpp" /> <ClCompile Include="Application.cpp" />
<ClCompile Include="BasicBatch.cpp" />
<ClCompile Include="BasicScene.cpp" />
<ClCompile Include="Camera2D.cpp" /> <ClCompile Include="Camera2D.cpp" />
<ClCompile Include="Camera3D.cpp" /> <ClCompile Include="Camera3D.cpp" />
<ClCompile Include="FPS.cpp" /> <ClCompile Include="FPS.cpp" />
<ClCompile Include="VertexFragmentShaderProgram.cpp" />
<ClCompile Include="GLFWInputManager.cpp" /> <ClCompile Include="GLFWInputManager.cpp" />
<ClCompile Include="GLUtil.cpp" />
<ClCompile Include="InputManager.cpp" /> <ClCompile Include="InputManager.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="MyBuiltinBasicCubeScene.cpp" />
<ClCompile Include="MySimpleCubeScene.cpp" /> <ClCompile Include="MySimpleCubeScene.cpp" />
<ClCompile Include="MySimple3DScene.cpp" /> <ClCompile Include="MySimple3DScene.cpp" />
<ClCompile Include="MyApplication.cpp" /> <ClCompile Include="MyApplication.cpp" />
<ClCompile Include="MyBatch.cpp" /> <ClCompile Include="MyBatch.cpp" />
<ClCompile Include="MySimpleShaderProgram.cpp" />
<ClCompile Include="MySimple2DScene.cpp" /> <ClCompile Include="MySimple2DScene.cpp" />
<ClCompile Include="MyBasicShaderProgram.cpp" />
<ClCompile Include="MyBasicScene.cpp" /> <ClCompile Include="MyBasicScene.cpp" />
<ClCompile Include="Poseable.cpp" /> <ClCompile Include="Poseable.cpp" />
<ClCompile Include="Shader.cpp" /> <ClCompile Include="Shader.cpp" />
@ -177,6 +180,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Application.h" /> <ClInclude Include="Application.h" />
<ClInclude Include="BasicBatch.h" />
<ClInclude Include="BasicScene.h" />
<ClInclude Include="BasicShaderProgram.h" />
<ClInclude Include="Batch.h" /> <ClInclude Include="Batch.h" />
<ClInclude Include="Camera.h" /> <ClInclude Include="Camera.h" />
<ClInclude Include="Camera2D.h" /> <ClInclude Include="Camera2D.h" />
@ -185,11 +191,14 @@
<ClInclude Include="DrawMode.h" /> <ClInclude Include="DrawMode.h" />
<ClInclude Include="Exception.h" /> <ClInclude Include="Exception.h" />
<ClInclude Include="FPS.h" /> <ClInclude Include="FPS.h" />
<ClInclude Include="VertexFragmentShaderProgram.h" />
<ClInclude Include="GLFWInputManager.h" /> <ClInclude Include="GLFWInputManager.h" />
<ClInclude Include="GLUtil.h" />
<ClInclude Include="InputManager.h" /> <ClInclude Include="InputManager.h" />
<ClInclude Include="Mesh.h" /> <ClInclude Include="Mesh.h" />
<ClInclude Include="MeshFactory.h" /> <ClInclude Include="MeshFactory.h" />
<ClInclude Include="MeshGenerator.h" /> <ClInclude Include="MeshGenerator.h" />
<ClInclude Include="MyBuiltinBasicCubeScene.h" />
<ClInclude Include="MySimpleCubeScene.h" /> <ClInclude Include="MySimpleCubeScene.h" />
<ClInclude Include="MySimple3DScene.h" /> <ClInclude Include="MySimple3DScene.h" />
<ClInclude Include="MyApplication.h" /> <ClInclude Include="MyApplication.h" />
@ -208,10 +217,14 @@
<ClInclude Include="MeshTypes.h" /> <ClInclude Include="MeshTypes.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="BasicFS.glsl" />
<None Include="BasicVS.glsl" />
<None Include="MySimpleFS.glsl" /> <None Include="MySimpleFS.glsl" />
<None Include="MySimpleVS.glsl" /> <None Include="MySimpleVS.glsl" />
<None Include="MyBasicFS.glsl" /> <None Include="MyBasicFS.glsl" />
<None Include="MyBasicVS.glsl" /> <None Include="MyBasicVS.glsl" />
<None Include="PassthroughFS.glsl" />
<None Include="PassthroughVS.glsl" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -58,6 +58,9 @@
<Filter Include="Source Files\Engine\builtin"> <Filter Include="Source Files\Engine\builtin">
<UniqueIdentifier>{233b4bce-fc64-4ad1-994e-c986befa7ff2}</UniqueIdentifier> <UniqueIdentifier>{233b4bce-fc64-4ad1-994e-c986befa7ff2}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\Engine\builtin\Shaders">
<UniqueIdentifier>{ca004137-6425-4863-b91a-cf32988855be}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
@ -111,15 +114,24 @@
<ClCompile Include="MyBasicScene.cpp"> <ClCompile Include="MyBasicScene.cpp">
<Filter>Source Files\Example\Application</Filter> <Filter>Source Files\Example\Application</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MyBasicShaderProgram.cpp">
<Filter>Source Files\Example\Rendering</Filter>
</ClCompile>
<ClCompile Include="MySimpleShaderProgram.cpp">
<Filter>Source Files\Example\Rendering</Filter>
</ClCompile>
<ClCompile Include="MySimpleCubeScene.cpp"> <ClCompile Include="MySimpleCubeScene.cpp">
<Filter>Source Files\Example\Application</Filter> <Filter>Source Files\Example\Application</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="GLUtil.cpp">
<Filter>Source Files\Engine\builtin</Filter>
</ClCompile>
<ClCompile Include="VertexFragmentShaderProgram.cpp">
<Filter>Source Files\Engine\Rendering</Filter>
</ClCompile>
<ClCompile Include="BasicBatch.cpp">
<Filter>Source Files\Engine\builtin</Filter>
</ClCompile>
<ClCompile Include="BasicScene.cpp">
<Filter>Source Files\Engine\builtin</Filter>
</ClCompile>
<ClCompile Include="MyBuiltinBasicCubeScene.cpp">
<Filter>Source Files\Example\Application</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Exception.h"> <ClInclude Include="Exception.h">
@ -212,6 +224,24 @@
<ClInclude Include="MeshTypes.h"> <ClInclude Include="MeshTypes.h">
<Filter>Header Files\Engine\builtin</Filter> <Filter>Header Files\Engine\builtin</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="GLUtil.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="BasicShaderProgram.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="VertexFragmentShaderProgram.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="BasicBatch.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="BasicScene.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="MyBuiltinBasicCubeScene.h">
<Filter>Header Files\Example\Application</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="MySimpleVS.glsl"> <None Include="MySimpleVS.glsl">
@ -226,5 +256,17 @@
<None Include="MySimpleFS.glsl"> <None Include="MySimpleFS.glsl">
<Filter>Source Files\Example\Rendering\Shader Code</Filter> <Filter>Source Files\Example\Rendering\Shader Code</Filter>
</None> </None>
<None Include="BasicFS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter>
</None>
<None Include="BasicVS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter>
</None>
<None Include="PassthroughVS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter>
</None>
<None Include="PassthroughFS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,2 @@
// TODO
// Could be same as BasicFS.glsl ...

View File

@ -0,0 +1 @@
// TODO

View File

@ -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();
}
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <string>
#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;
};
}