Added Ambient Lighting for LitScene
This commit is contained in:
parent
ada349c0a2
commit
af20d28442
@ -1,43 +0,0 @@
|
|||||||
#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, sizeof(BasicVertex), NULL);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glEnableVertexAttribArray(2);
|
|
||||||
glEnableVertexAttribArray(3);
|
|
||||||
glEnableVertexAttribArray(4);
|
|
||||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
|
|
||||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
|
|
||||||
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
|
|
||||||
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "MeshTypes.h"
|
|
||||||
#include "BuiltinBatch.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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -41,16 +41,5 @@ namespace charcoal
|
|||||||
iter->render();
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,8 +5,9 @@
|
|||||||
#include "AutoPrerenderingScene.h"
|
#include "AutoPrerenderingScene.h"
|
||||||
|
|
||||||
#include "BasicShaderProgram.h"
|
#include "BasicShaderProgram.h"
|
||||||
#include "BasicBatch.h"
|
#include "BuiltinTypes.h"
|
||||||
#include "Camera2D.h"
|
#include "Camera2D.h"
|
||||||
|
#include "Batched.h"
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ namespace charcoal
|
|||||||
{
|
{
|
||||||
namespace builtin
|
namespace builtin
|
||||||
{
|
{
|
||||||
class BasicScene : public AutoPrerenderingScene
|
class BasicScene : public AutoPrerenderingScene, public Batched<BasicRenderable, BasicBatch>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BasicScene(Application& application) : AutoPrerenderingScene(application) {}
|
BasicScene(Application& application) : AutoPrerenderingScene(application) {}
|
||||||
@ -31,13 +32,8 @@ namespace charcoal
|
|||||||
protected:
|
protected:
|
||||||
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
|
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
|
||||||
|
|
||||||
BasicBatch& add_batch(BasicRenderable* renderable, int element_count);
|
|
||||||
|
|
||||||
BasicBatch& add_batch(BasicRenderable* renderable, int element_count, int element_render_count);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BasicShaderProgram m_shader_program;
|
BasicShaderProgram m_shader_program;
|
||||||
std::vector<BasicBatch> m_batches;
|
|
||||||
const Camera* m_p_camera = nullptr;
|
const Camera* m_p_camera = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,9 @@ namespace charcoal
|
|||||||
class Batch
|
class Batch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef GLsizei SizeType;
|
|
||||||
|
|
||||||
Batch(
|
Batch(
|
||||||
const Renderable* renderable,
|
const Renderable* renderable,
|
||||||
const SizeType& element_render_count
|
int element_render_count
|
||||||
)
|
)
|
||||||
: m_p_renderable(renderable), m_element_render_count(element_render_count), m_element_buffers(element_buffer_count)
|
: m_p_renderable(renderable), m_element_render_count(element_render_count), m_element_buffers(element_buffer_count)
|
||||||
{
|
{
|
||||||
@ -91,14 +89,14 @@ namespace charcoal
|
|||||||
glBindVertexArray(NULL);
|
glBindVertexArray(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_element_render_count(const SizeType& element_render_count)
|
void set_element_render_count(int element_render_count)
|
||||||
{
|
{
|
||||||
m_element_render_count = element_render_count;
|
m_element_render_count = element_render_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Renderable* get_renderable() const { return m_p_renderable; }
|
const Renderable* get_renderable() const { return m_p_renderable; }
|
||||||
|
|
||||||
SizeType get_element_render_count() const { return m_element_render_count; }
|
int get_element_render_count() const { return m_element_render_count; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup_element_buffers() {}
|
virtual void setup_element_buffers() {}
|
||||||
@ -108,7 +106,7 @@ namespace charcoal
|
|||||||
virtual void update_element_buffers() {}
|
virtual void update_element_buffers() {}
|
||||||
|
|
||||||
const Renderable* m_p_renderable;
|
const Renderable* m_p_renderable;
|
||||||
SizeType m_element_render_count;
|
int m_element_render_count;
|
||||||
|
|
||||||
GLuint m_vertex_vbo;
|
GLuint m_vertex_vbo;
|
||||||
std::vector<GLuint> m_element_buffers;
|
std::vector<GLuint> m_element_buffers;
|
||||||
|
25
OpenGLEngine/Batched.h
Normal file
25
OpenGLEngine/Batched.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace charcoal
|
||||||
|
{
|
||||||
|
namespace builtin
|
||||||
|
{
|
||||||
|
template <typename RenderableType, typename BatchType>
|
||||||
|
class Batched
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
BatchType& add_batch(RenderableType* renderable, int element_count)
|
||||||
|
{
|
||||||
|
return add_batch(renderable, element_count, element_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
BatchType& add_batch(RenderableType* renderable, int element_count, int element_render_count)
|
||||||
|
{
|
||||||
|
m_batches.emplace_back(renderable, element_count, element_render_count);
|
||||||
|
return m_batches.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<BatchType> m_batches;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ namespace charcoal
|
|||||||
public:
|
public:
|
||||||
Batch(
|
Batch(
|
||||||
const Renderable* renderable,
|
const Renderable* renderable,
|
||||||
const charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>::SizeType& element_render_count
|
int element_render_count
|
||||||
) : charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>(renderable, element_render_count) {}
|
) : charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>(renderable, element_render_count) {}
|
||||||
|
|
||||||
void prerender() override { charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>::prerender(); }
|
void prerender() override { charcoal::Batch<VertexType, IndexType, element_buffer_count, Renderable>::prerender(); }
|
||||||
|
61
OpenGLEngine/BuiltinTypes.h
Normal file
61
OpenGLEngine/BuiltinTypes.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include "Renderable.h"
|
||||||
|
#include "PoseableBatch.h"
|
||||||
|
#include "VertexFragmentShaderProgram.h"
|
||||||
|
|
||||||
|
namespace charcoal
|
||||||
|
{
|
||||||
|
namespace builtin
|
||||||
|
{
|
||||||
|
using namespace glm;
|
||||||
|
|
||||||
|
typedef vec3 Position;
|
||||||
|
typedef vec3 Normal;
|
||||||
|
typedef vec4 ColorRGBA;
|
||||||
|
typedef vec3 ColorRGB;
|
||||||
|
typedef vec2 UV;
|
||||||
|
|
||||||
|
typedef unsigned int Index;
|
||||||
|
|
||||||
|
// Generic Vertices
|
||||||
|
|
||||||
|
struct PVertex
|
||||||
|
{
|
||||||
|
void set_position(const Position& position) { this->position = position; }
|
||||||
|
|
||||||
|
Position position;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PNVertex
|
||||||
|
{
|
||||||
|
void set_position(const Position& position) { this->position = position; }
|
||||||
|
void set_normal(const Normal& normal) { this->normal = normal; }
|
||||||
|
|
||||||
|
Position position;
|
||||||
|
Normal normal;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Other Data Types
|
||||||
|
|
||||||
|
struct Light
|
||||||
|
{
|
||||||
|
Light(const ColorRGB& ambient) : ambient(ambient) {}
|
||||||
|
|
||||||
|
ColorRGB ambient;
|
||||||
|
};
|
||||||
|
|
||||||
|
// typedefs for builtin types
|
||||||
|
|
||||||
|
typedef PVertex BasicVertex;
|
||||||
|
typedef Index BasicIndex;
|
||||||
|
typedef Renderable<BasicVertex, BasicIndex> BasicRenderable;
|
||||||
|
typedef PoseableBatch<BasicVertex, BasicIndex> BasicBatch;
|
||||||
|
|
||||||
|
typedef PNVertex LitVertex;
|
||||||
|
typedef Index LitIndex;
|
||||||
|
typedef Renderable<LitVertex, LitIndex> LitRenderable;
|
||||||
|
typedef PoseableBatch<LitVertex, LitIndex> LitBatch;
|
||||||
|
}
|
||||||
|
}
|
@ -13,10 +13,31 @@ namespace charcoal
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uniform_int(int uniform_index, int value)
|
||||||
|
{
|
||||||
|
glUniform1i(uniform_index, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uniform_uint(int uniform_index, unsigned int value)
|
||||||
|
{
|
||||||
|
glUniform1ui(uniform_index, value);
|
||||||
|
}
|
||||||
|
|
||||||
void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose)
|
void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose)
|
||||||
{
|
{
|
||||||
glUniformMatrix4fv(uniform_index, 1, transpose ? GL_TRUE : GL_FALSE, &matrix[0][0]);
|
glUniformMatrix4fv(uniform_index, 1, transpose ? GL_TRUE : GL_FALSE, &matrix[0][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uniform_lights(int uniform_index, const std::vector<Light>& lights)
|
||||||
|
{
|
||||||
|
const int ambient_size = 1;
|
||||||
|
int current_location = uniform_index;
|
||||||
|
for (std::vector<Light>::size_type i = 0; i < lights.size(); ++i)
|
||||||
|
{
|
||||||
|
glUniform3fv(current_location, 1, &lights[i].ambient[0]);
|
||||||
|
current_location += ambient_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "BuiltinTypes.h"
|
||||||
|
|
||||||
namespace charcoal
|
namespace charcoal
|
||||||
{
|
{
|
||||||
@ -11,7 +14,10 @@ namespace charcoal
|
|||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
void clear_screen();
|
void clear_screen();
|
||||||
|
void uniform_int(int uniform_index, int value);
|
||||||
|
void uniform_uint(int uniform_index, unsigned int value);
|
||||||
void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose = false);
|
void uniform_matrix(int uniform_index, const mat4& matrix, bool transpose = false);
|
||||||
|
void uniform_lights(int uniform_index, const std::vector<Light>& lights); // TODO: This may want to be moved somewhere else
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
20
OpenGLEngine/LitFS.glsl
Normal file
20
OpenGLEngine/LitFS.glsl
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#version 430
|
||||||
|
|
||||||
|
struct Light
|
||||||
|
{
|
||||||
|
vec3 ambient;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 16
|
||||||
|
layout(location = 4) uniform Light lights[MAX_LIGHTS];
|
||||||
|
layout(location = 20) uniform uint num_lights;
|
||||||
|
|
||||||
|
out vec4 frag_color;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 accum = vec3(0.0);
|
||||||
|
for (uint i = 0; i < MAX_LIGHTS && i < num_lights; ++i) {
|
||||||
|
accum = accum + lights[i].ambient;
|
||||||
|
}
|
||||||
|
frag_color = vec4(accum, 1.0);
|
||||||
|
}
|
53
OpenGLEngine/LitScene.cpp
Normal file
53
OpenGLEngine/LitScene.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "LitScene.h"
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include "Util.h"
|
||||||
|
#include "GLUtil.h"
|
||||||
|
#include "MeshFactory.h"
|
||||||
|
|
||||||
|
namespace charcoal
|
||||||
|
{
|
||||||
|
namespace builtin
|
||||||
|
{
|
||||||
|
void LitScene::init()
|
||||||
|
{
|
||||||
|
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
|
||||||
|
{
|
||||||
|
LitBatch& batch = *iter;
|
||||||
|
batch.init();
|
||||||
|
add_prerenderable(&batch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LitScene::use()
|
||||||
|
{
|
||||||
|
// TODO: move to glutil
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LitScene::unuse()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LitScene::render()
|
||||||
|
{
|
||||||
|
glutil::clear_screen();
|
||||||
|
m_shader_program.use();
|
||||||
|
CHECK_GL_ERR();
|
||||||
|
glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix());
|
||||||
|
CHECK_GL_ERR();
|
||||||
|
glutil::uniform_lights(4, m_lights);
|
||||||
|
CHECK_GL_ERR();
|
||||||
|
glutil::uniform_uint(20, m_lights.size());
|
||||||
|
CHECK_GL_ERR();
|
||||||
|
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
|
||||||
|
{
|
||||||
|
iter->render();
|
||||||
|
}
|
||||||
|
CHECK_GL_ERR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
OpenGLEngine/LitScene.h
Normal file
40
OpenGLEngine/LitScene.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "AutoPrerenderingScene.h"
|
||||||
|
#include "BuiltinTypes.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
#include "Batched.h"
|
||||||
|
#include "LitShaderProgram.h"
|
||||||
|
|
||||||
|
namespace charcoal
|
||||||
|
{
|
||||||
|
namespace builtin
|
||||||
|
{
|
||||||
|
class LitScene : public AutoPrerenderingScene, public Batched<LitRenderable, LitBatch>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LitScene(Application& application) : AutoPrerenderingScene(application) {}
|
||||||
|
virtual ~LitScene() {}
|
||||||
|
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
void use() override;
|
||||||
|
|
||||||
|
void unuse() override;
|
||||||
|
|
||||||
|
void render() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
|
||||||
|
|
||||||
|
void add_light(const ColorRGB& ambient) { m_lights.emplace_back(ambient); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
LitShaderProgram m_shader_program;
|
||||||
|
const Camera* m_p_camera = nullptr;
|
||||||
|
std::vector<Light> m_lights;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
16
OpenGLEngine/LitShaderProgram.h
Normal file
16
OpenGLEngine/LitShaderProgram.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "VertexFragmentShaderProgram.h"
|
||||||
|
|
||||||
|
namespace charcoal
|
||||||
|
{
|
||||||
|
namespace builtin
|
||||||
|
{
|
||||||
|
// TODO: Add constatns for the uniform and vertex attribute locations (for all shader programs)
|
||||||
|
class LitShaderProgram : public VertexFragmentShaderProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LitShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
10
OpenGLEngine/LitVS.glsl
Normal file
10
OpenGLEngine/LitVS.glsl
Normal 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);
|
||||||
|
}
|
@ -3,11 +3,8 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "MeshFactory.h"
|
#include "MeshFactory.h"
|
||||||
|
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
|
||||||
#include "MeshTypes.h"
|
|
||||||
|
|
||||||
// TODO: Consider a mesh generator for every render type (i.e. basic::meshgenerator, lit::meshgenerator, etc.)
|
// TODO: Consider a mesh generator for every render type (i.e. basic::meshgenerator, lit::meshgenerator, etc.)
|
||||||
|
|
||||||
namespace charcoal
|
namespace charcoal
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include "Renderable.h"
|
|
||||||
|
|
||||||
namespace charcoal
|
|
||||||
{
|
|
||||||
namespace builtin
|
|
||||||
{
|
|
||||||
using namespace glm;
|
|
||||||
|
|
||||||
typedef vec3 Position;
|
|
||||||
typedef vec3 Normal;
|
|
||||||
typedef vec4 Color;
|
|
||||||
typedef vec2 UV;
|
|
||||||
|
|
||||||
typedef unsigned int Index;
|
|
||||||
|
|
||||||
// Simple types that implement the interfaces
|
|
||||||
|
|
||||||
struct BasicVertex
|
|
||||||
{
|
|
||||||
BasicVertex() : BasicVertex({ 0.0f, 0.0f, 0.0f }) {}
|
|
||||||
BasicVertex(const Position& position) : position(position) {}
|
|
||||||
|
|
||||||
void set_position(const Position& position) { this->position = position; }
|
|
||||||
|
|
||||||
Position position;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef Index BasicIndex;
|
|
||||||
|
|
||||||
typedef Renderable<BasicVertex, BasicIndex> BasicRenderable;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,8 @@ MyApplication::MyApplication(int width, int height)
|
|||||||
m_simple_2d_scene(*this),
|
m_simple_2d_scene(*this),
|
||||||
m_simple_3d_scene(*this),
|
m_simple_3d_scene(*this),
|
||||||
m_simple_cube_scene(*this),
|
m_simple_cube_scene(*this),
|
||||||
m_builtin_basic_cube_scene(*this)
|
m_builtin_basic_cube_scene(*this),
|
||||||
|
m_builtin_lit_scene(*this)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void MyApplication::init()
|
void MyApplication::init()
|
||||||
@ -16,6 +17,7 @@ void MyApplication::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_builtin_basic_cube_scene.init();
|
||||||
|
m_builtin_lit_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();
|
||||||
@ -43,6 +45,10 @@ void MyApplication::update(float delta_time, clock_t clock)
|
|||||||
{
|
{
|
||||||
swap_scene(&m_builtin_basic_cube_scene);
|
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);
|
||||||
|
}
|
||||||
m_p_current_scene->update(delta_time, clock);
|
m_p_current_scene->update(delta_time, clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "MySimple3DScene.h"
|
#include "MySimple3DScene.h"
|
||||||
#include "MySimpleCubeScene.h"
|
#include "MySimpleCubeScene.h"
|
||||||
#include "MyBuiltinCubeScene.h"
|
#include "MyBuiltinCubeScene.h"
|
||||||
|
#include "MyBuiltinLitScene.h"
|
||||||
|
|
||||||
using namespace charcoal;
|
using namespace charcoal;
|
||||||
|
|
||||||
@ -35,5 +36,6 @@ private:
|
|||||||
MySimple3DScene m_simple_3d_scene;
|
MySimple3DScene m_simple_3d_scene;
|
||||||
MySimpleCubeScene m_simple_cube_scene;
|
MySimpleCubeScene m_simple_cube_scene;
|
||||||
MyBuiltinCubeScene m_builtin_basic_cube_scene;
|
MyBuiltinCubeScene m_builtin_basic_cube_scene;
|
||||||
|
MyBuiltinLitScene m_builtin_lit_scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,23 +8,23 @@
|
|||||||
|
|
||||||
using namespace charcoal;
|
using namespace charcoal;
|
||||||
|
|
||||||
class MyBatch : public Batch<MySimpleShaderProgram::Vertex, MySimpleShaderProgram::Index, 2>
|
class MyBatch : public charcoal::Batch<MySimpleShaderProgram::Vertex, MySimpleShaderProgram::Index, 2>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyBatch(
|
MyBatch(
|
||||||
const MySimpleShaderProgram::Renderable* renderable,
|
const MySimpleShaderProgram::Renderable* renderable,
|
||||||
const SizeType& element_count
|
int element_count
|
||||||
) : MyBatch(renderable, element_count, element_count) {}
|
) : MyBatch(renderable, element_count, element_count) {}
|
||||||
|
|
||||||
MyBatch(
|
MyBatch(
|
||||||
const MySimpleShaderProgram::Renderable* renderable,
|
const MySimpleShaderProgram::Renderable* renderable,
|
||||||
const SizeType& element_count,
|
int element_count,
|
||||||
const SizeType& element_render_count
|
int element_render_count
|
||||||
) : Batch(renderable, element_render_count), m_color_elements(element_count), m_poseable_elements(element_count) {}
|
) : Batch(renderable, element_render_count), m_color_elements(element_count), m_poseable_elements(element_count) {}
|
||||||
|
|
||||||
MySimpleShaderProgram::Color& get_color(const SizeType& index) { return m_color_elements[index]; }
|
MySimpleShaderProgram::Color& get_color(int index) { return m_color_elements[index]; }
|
||||||
|
|
||||||
Poseable& get_pose(const SizeType& index) { return m_poseable_elements[index]; }
|
Poseable& get_pose(int index) { return m_poseable_elements[index]; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setup_element_buffers() override;
|
void setup_element_buffers() override;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "MeshGenerator.h"
|
#include "MeshGenerator.h"
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
|
MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
|
||||||
: BasicScene(application),
|
: BasicScene(application),
|
||||||
m_shape(meshgenerator::gen_cube_p<BasicVertex, BasicIndex>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES),
|
m_shape(meshgenerator::gen_cube_p<BasicVertex, BasicIndex>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES),
|
||||||
|
58
OpenGLEngine/MyBuiltinLitScene.cpp
Normal file
58
OpenGLEngine/MyBuiltinLitScene.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "MyBuiltinLitScene.h"
|
||||||
|
|
||||||
|
#include "MeshGenerator.h"
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
MyBuiltinLitScene::MyBuiltinLitScene(Application& application)
|
||||||
|
: LitScene(application),
|
||||||
|
m_shape(meshgenerator::gen_cube_p<LitVertex, LitIndex>(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))
|
||||||
|
{
|
||||||
|
add_prerenderable(&m_camera);
|
||||||
|
set_camera(&m_camera);
|
||||||
|
|
||||||
|
add_light(ColorRGB(0.0f, 0.0f, 1.0f));
|
||||||
|
add_light(ColorRGB(0.0f, 1.0f, 0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
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_2 * 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);
|
||||||
|
}
|
||||||
|
|
19
OpenGLEngine/MyBuiltinLitScene.h
Normal file
19
OpenGLEngine/MyBuiltinLitScene.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "LitScene.h"
|
||||||
|
#include "BuiltinCamera3D.h"
|
||||||
|
|
||||||
|
using namespace charcoal;
|
||||||
|
using namespace charcoal::builtin;
|
||||||
|
|
||||||
|
class MyBuiltinLitScene : public LitScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyBuiltinLitScene(Application& application);
|
||||||
|
|
||||||
|
void update(float delta_time, clock_t clock) override;
|
||||||
|
private:
|
||||||
|
LitRenderable m_shape;
|
||||||
|
builtin::Camera3D m_camera;
|
||||||
|
LitBatch& m_batch;
|
||||||
|
};
|
@ -153,17 +153,17 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Application.cpp" />
|
<ClCompile Include="Application.cpp" />
|
||||||
<ClCompile Include="AutoPrerenderingScene.cpp" />
|
<ClCompile Include="AutoPrerenderingScene.cpp" />
|
||||||
<ClCompile Include="BasicBatch.cpp" />
|
|
||||||
<ClCompile Include="BasicScene.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="LitScene.cpp" />
|
||||||
<ClCompile Include="MyBuiltinCubeScene.cpp" />
|
<ClCompile Include="MyBuiltinCubeScene.cpp" />
|
||||||
<ClCompile Include="VertexFragmentShaderProgram.cpp" />
|
|
||||||
<ClCompile Include="GLFWInputManager.cpp" />
|
<ClCompile Include="GLFWInputManager.cpp" />
|
||||||
<ClCompile Include="GLUtil.cpp" />
|
<ClCompile Include="GLUtil.cpp" />
|
||||||
<ClCompile Include="InputManager.cpp" />
|
<ClCompile Include="InputManager.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
|
<ClCompile Include="MyBuiltinLitScene.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" />
|
||||||
@ -178,16 +178,17 @@
|
|||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Util.cpp" />
|
<ClCompile Include="Util.cpp" />
|
||||||
|
<ClCompile Include="VertexFragmentShaderProgram.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Application.h" />
|
<ClInclude Include="Application.h" />
|
||||||
<ClInclude Include="AutoPrerenderingScene.h" />
|
<ClInclude Include="AutoPrerenderingScene.h" />
|
||||||
<ClInclude Include="BasicBatch.h" />
|
|
||||||
<ClInclude Include="BasicScene.h" />
|
<ClInclude Include="BasicScene.h" />
|
||||||
<ClInclude Include="BasicShaderProgram.h" />
|
<ClInclude Include="BasicShaderProgram.h" />
|
||||||
<ClInclude Include="Batch.h" />
|
<ClInclude Include="Batch.h" />
|
||||||
<ClInclude Include="BuiltinCamera3D.h" />
|
<ClInclude Include="Batched.h" />
|
||||||
<ClInclude Include="BuiltinBatch.h" />
|
<ClInclude Include="BuiltinBatch.h" />
|
||||||
|
<ClInclude Include="BuiltinCamera3D.h" />
|
||||||
<ClInclude Include="BuiltinCamera2D.h" />
|
<ClInclude Include="BuiltinCamera2D.h" />
|
||||||
<ClInclude Include="Camera.h" />
|
<ClInclude Include="Camera.h" />
|
||||||
<ClInclude Include="Camera2D.h" />
|
<ClInclude Include="Camera2D.h" />
|
||||||
@ -196,7 +197,11 @@
|
|||||||
<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="LitScene.h" />
|
||||||
|
<ClInclude Include="LitShaderProgram.h" />
|
||||||
<ClInclude Include="MyBuiltinCubeScene.h" />
|
<ClInclude Include="MyBuiltinCubeScene.h" />
|
||||||
|
<ClInclude Include="MyBuiltinLitScene.h" />
|
||||||
|
<ClInclude Include="PoseableBatch.h" />
|
||||||
<ClInclude Include="Prerenderable.h" />
|
<ClInclude Include="Prerenderable.h" />
|
||||||
<ClInclude Include="VertexFragmentShaderProgram.h" />
|
<ClInclude Include="VertexFragmentShaderProgram.h" />
|
||||||
<ClInclude Include="GLFWInputManager.h" />
|
<ClInclude Include="GLFWInputManager.h" />
|
||||||
@ -220,7 +225,7 @@
|
|||||||
<ClInclude Include="ShaderProgram.h" />
|
<ClInclude Include="ShaderProgram.h" />
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
<ClInclude Include="Util.h" />
|
<ClInclude Include="Util.h" />
|
||||||
<ClInclude Include="MeshTypes.h" />
|
<ClInclude Include="BuiltinTypes.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="BasicFS.glsl" />
|
<None Include="BasicFS.glsl" />
|
||||||
@ -229,8 +234,8 @@
|
|||||||
<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="LitVS.glsl" />
|
||||||
<None Include="PassthroughVS.glsl" />
|
<None Include="LitFS.glsl" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -120,12 +120,6 @@
|
|||||||
<ClCompile Include="GLUtil.cpp">
|
<ClCompile Include="GLUtil.cpp">
|
||||||
<Filter>Source Files\Engine\builtin</Filter>
|
<Filter>Source Files\Engine\builtin</Filter>
|
||||||
</ClCompile>
|
</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">
|
<ClCompile Include="BasicScene.cpp">
|
||||||
<Filter>Source Files\Engine\builtin</Filter>
|
<Filter>Source Files\Engine\builtin</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -135,6 +129,15 @@
|
|||||||
<ClCompile Include="AutoPrerenderingScene.cpp">
|
<ClCompile Include="AutoPrerenderingScene.cpp">
|
||||||
<Filter>Source Files\Engine\builtin</Filter>
|
<Filter>Source Files\Engine\builtin</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="LitScene.cpp">
|
||||||
|
<Filter>Source Files\Engine\builtin</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="MyBuiltinLitScene.cpp">
|
||||||
|
<Filter>Source Files\Example\Application</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="VertexFragmentShaderProgram.cpp">
|
||||||
|
<Filter>Source Files\Engine\Rendering</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Exception.h">
|
<ClInclude Include="Exception.h">
|
||||||
@ -224,9 +227,6 @@
|
|||||||
<ClInclude Include="MeshGenerator.h">
|
<ClInclude Include="MeshGenerator.h">
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="MeshTypes.h">
|
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GLUtil.h">
|
<ClInclude Include="GLUtil.h">
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -236,9 +236,6 @@
|
|||||||
<ClInclude Include="VertexFragmentShaderProgram.h">
|
<ClInclude Include="VertexFragmentShaderProgram.h">
|
||||||
<Filter>Header Files\Engine\Rendering</Filter>
|
<Filter>Header Files\Engine\Rendering</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="BasicBatch.h">
|
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="BasicScene.h">
|
<ClInclude Include="BasicScene.h">
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -254,12 +251,30 @@
|
|||||||
<ClInclude Include="AutoPrerenderingScene.h">
|
<ClInclude Include="AutoPrerenderingScene.h">
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="BuiltinCamera3D.h">
|
||||||
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="LitScene.h">
|
||||||
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="PoseableBatch.h">
|
||||||
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="BuiltinTypes.h">
|
||||||
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="BuiltinBatch.h">
|
<ClInclude Include="BuiltinBatch.h">
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="BuiltinCamera3D.h">
|
<ClInclude Include="Batched.h">
|
||||||
<Filter>Header Files\Engine\builtin</Filter>
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="LitShaderProgram.h">
|
||||||
|
<Filter>Header Files\Engine\builtin</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="MyBuiltinLitScene.h">
|
||||||
|
<Filter>Header Files\Example\Application</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="MySimpleVS.glsl">
|
<None Include="MySimpleVS.glsl">
|
||||||
@ -280,10 +295,10 @@
|
|||||||
<None Include="BasicVS.glsl">
|
<None Include="BasicVS.glsl">
|
||||||
<Filter>Source Files\Engine\builtin\Shaders</Filter>
|
<Filter>Source Files\Engine\builtin\Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="PassthroughVS.glsl">
|
<None Include="LitVS.glsl">
|
||||||
<Filter>Source Files\Engine\builtin\Shaders</Filter>
|
<Filter>Source Files\Engine\builtin\Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="PassthroughFS.glsl">
|
<None Include="LitFS.glsl">
|
||||||
<Filter>Source Files\Engine\builtin\Shaders</Filter>
|
<Filter>Source Files\Engine\builtin\Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
// TODO
|
|
||||||
// Could be same as BasicFS.glsl ...
|
|
@ -1 +0,0 @@
|
|||||||
// TODO
|
|
76
OpenGLEngine/PoseableBatch.h
Normal file
76
OpenGLEngine/PoseableBatch.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Batch.h"
|
||||||
|
#include "BuiltinBatch.h"
|
||||||
|
#include "Renderable.h"
|
||||||
|
#include "Poseable.h"
|
||||||
|
|
||||||
|
namespace charcoal
|
||||||
|
{
|
||||||
|
namespace builtin
|
||||||
|
{
|
||||||
|
template <typename VertexType, typename IndexType, typename Renderable = Renderable<VertexType, IndexType> >
|
||||||
|
class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, Renderable>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// TODO: Figure out how to get rid of this typename garbage. If that it figured out, m_element_buffers should get fixed.
|
||||||
|
PoseableBatch(
|
||||||
|
Renderable* renderable,
|
||||||
|
int element_count
|
||||||
|
) : PoseableBatch(renderable, element_count, element_count)
|
||||||
|
{}
|
||||||
|
|
||||||
|
PoseableBatch(
|
||||||
|
Renderable* renderable,
|
||||||
|
int element_count,
|
||||||
|
int element_render_count
|
||||||
|
) : builtin::Batch<VertexType, IndexType, 1, Renderable>(renderable, element_render_count), m_pose_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]; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setup_element_buffers() override
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, Renderable>::m_element_buffers[0]);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_vao() override
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, Renderable>::m_vertex_vbo);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), NULL);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, Renderable>::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 update_element_buffers() override
|
||||||
|
{
|
||||||
|
// 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<VertexType, IndexType, 1, Renderable>::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());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Poseable> m_pose_elements;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user