Starting Textured Scene

Want to use seperate textures and samplers for the scene to allow
for more modularization. Currently have created a texture class
and started creating a scene class.
This commit is contained in:
elipzer 2018-09-15 17:40:49 -04:00
parent 1eea92a3af
commit ae7fcc9011
20 changed files with 621 additions and 35 deletions

View File

@ -6,7 +6,7 @@
#include "BasicShaderProgram.h" #include "BasicShaderProgram.h"
#include "BuiltinTypes.h" #include "BuiltinTypes.h"
#include "Camera2D.h" #include "Camera.h"
#include "Batched.h" #include "Batched.h"
#include "BasicBatch.h" #include "BasicBatch.h"

View File

@ -79,15 +79,6 @@ namespace charcoal
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;
};
struct PNMVertex struct PNMVertex
{ {
void set_position(const Position& position) { this->position = position; } void set_position(const Position& position) { this->position = position; }
@ -99,6 +90,15 @@ namespace charcoal
Material material; Material material;
}; };
struct PTVertex
{
void set_position(const Position& position) { this->position = position; }
void set_uv(const UV& uv) { this->uv = uv; }
Position position;
UV uv;
};
// typedefs for builtin types // typedefs for builtin types
typedef PVertex BasicVertex; typedef PVertex BasicVertex;
@ -108,5 +108,9 @@ namespace charcoal
typedef PNMVertex LitVertex; typedef PNMVertex LitVertex;
typedef Index LitIndex; typedef Index LitIndex;
typedef Renderable<LitVertex, LitIndex> LitRenderable; typedef Renderable<LitVertex, LitIndex> LitRenderable;
typedef PTVertex TexturedVertex;
typedef Index TexturedIndex;
typedef Renderable<TexturedVertex, TexturedIndex> TexturedRenderable;
} }
} }

View File

@ -7,7 +7,8 @@ MyApplication::MyApplication(int width, int height)
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) m_builtin_lit_scene(*this),
m_builtin_textured_scene(*this)
{} {}
void MyApplication::init() void MyApplication::init()
@ -18,6 +19,7 @@ void MyApplication::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_builtin_lit_scene.init();
m_builtin_textured_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();
@ -49,6 +51,10 @@ void MyApplication::update(float delta_time, clock_t clock)
{ {
swap_scene(&m_builtin_lit_scene); swap_scene(&m_builtin_lit_scene);
} }
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_7))
{
swap_scene(&m_builtin_textured_scene);
}
m_p_current_scene->update(delta_time, clock); m_p_current_scene->update(delta_time, clock);
} }

View File

@ -7,6 +7,7 @@
#include "MySimpleCubeScene.h" #include "MySimpleCubeScene.h"
#include "MyBuiltinCubeScene.h" #include "MyBuiltinCubeScene.h"
#include "MyBuiltinLitScene.h" #include "MyBuiltinLitScene.h"
#include "MyBuiltinTexturedScene.h"
using namespace charcoal; using namespace charcoal;
@ -37,5 +38,6 @@ private:
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; MyBuiltinLitScene m_builtin_lit_scene;
MyBuiltinTexturedScene m_builtin_textured_scene;
}; };

View File

@ -0,0 +1,55 @@
#include "MyBuiltinTexturedScene.h"
#include "MeshGenerator.h"
#include "constants.h"
MyBuiltinTexturedScene::MyBuiltinTexturedScene(Application& application)
: TexturedScene(application),
m_shape(meshgenerator::gen_cube_p<TexturedVertex, TexturedIndex>(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);
}
void MyBuiltinTexturedScene::update(float delta_time, clock_t clock)
{
float brightness;
float radians;
clock_t c;
const clock_t intervals = 512 * CLOCKS_PER_SEC / 100;
const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100;
c = clock % intervals;
if (c < half_interval)
brightness = (float)c / half_interval;
else
brightness = (float)(intervals - c) / half_interval;
radians = (float)TAU * c / intervals;
{
Poseable& pose = m_batch.get_pose(0);
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_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);
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "TexturedScene.h"
#include "BuiltinCamera3D.h"
using namespace charcoal;
using namespace charcoal::builtin;
class MyBuiltinTexturedScene : public TexturedScene
{
public:
MyBuiltinTexturedScene(Application& application);
void update(float delta_time, clock_t clock) override;
private:
TexturedRenderable m_shape;
builtin::Camera3D m_camera;
TexturedBatch& m_batch;
};

View File

@ -31,6 +31,6 @@ private:
MySimpleShaderProgram m_shader_program; MySimpleShaderProgram m_shader_program;
MySimpleShaderProgram::Renderable m_shape; MySimpleShaderProgram::Renderable m_shape;
MyBatch m_batch; MyBatch m_batch;
Camera3D m_camera; charcoal::Camera3D m_camera;
}; };

View File

@ -31,6 +31,6 @@ private:
MySimpleShaderProgram m_shader_program; MySimpleShaderProgram m_shader_program;
MySimpleShaderProgram::Renderable m_shape; MySimpleShaderProgram::Renderable m_shape;
MyBatch m_batch; MyBatch m_batch;
Camera3D m_camera; charcoal::Camera3D m_camera;
}; };

View File

@ -166,6 +166,7 @@
<ClCompile Include="InputManager.cpp" /> <ClCompile Include="InputManager.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="MyBuiltinLitScene.cpp" /> <ClCompile Include="MyBuiltinLitScene.cpp" />
<ClCompile Include="MyBuiltinTexturedScene.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" />
@ -179,6 +180,8 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="TexturedBatch.cpp" />
<ClCompile Include="TexturedScene.cpp" />
<ClCompile Include="Util.cpp" /> <ClCompile Include="Util.cpp" />
<ClCompile Include="VertexFragmentShaderProgram.cpp" /> <ClCompile Include="VertexFragmentShaderProgram.cpp" />
</ItemGroup> </ItemGroup>
@ -205,8 +208,12 @@
<ClInclude Include="LitShaderProgram.h" /> <ClInclude Include="LitShaderProgram.h" />
<ClInclude Include="MyBuiltinCubeScene.h" /> <ClInclude Include="MyBuiltinCubeScene.h" />
<ClInclude Include="MyBuiltinLitScene.h" /> <ClInclude Include="MyBuiltinLitScene.h" />
<ClInclude Include="MyBuiltinTexturedScene.h" />
<ClInclude Include="PoseableBatch.h" /> <ClInclude Include="PoseableBatch.h" />
<ClInclude Include="Prerenderable.h" /> <ClInclude Include="Prerenderable.h" />
<ClInclude Include="TexturedBatch.h" />
<ClInclude Include="TexturedScene.h" />
<ClInclude Include="TexturedShaderProgram.h" />
<ClInclude Include="VertexFragmentShaderProgram.h" /> <ClInclude Include="VertexFragmentShaderProgram.h" />
<ClInclude Include="GLFWInputManager.h" /> <ClInclude Include="GLFWInputManager.h" />
<ClInclude Include="GLUtil.h" /> <ClInclude Include="GLUtil.h" />
@ -240,6 +247,8 @@
<None Include="MyBasicVS.glsl" /> <None Include="MyBasicVS.glsl" />
<None Include="LitVS.glsl" /> <None Include="LitVS.glsl" />
<None Include="LitFS.glsl" /> <None Include="LitFS.glsl" />
<None Include="TexturedFS.glsl" />
<None Include="TexturedVS.glsl" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -61,6 +61,24 @@
<Filter Include="Source Files\Engine\builtin\Shaders"> <Filter Include="Source Files\Engine\builtin\Shaders">
<UniqueIdentifier>{ca004137-6425-4863-b91a-cf32988855be}</UniqueIdentifier> <UniqueIdentifier>{ca004137-6425-4863-b91a-cf32988855be}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Header Files\Engine\builtin\Basic">
<UniqueIdentifier>{f3f94b58-31cf-4a57-bc2a-0c3a33a6b9ee}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Engine\builtin\Lit">
<UniqueIdentifier>{fa76cc6e-e866-4987-8263-85abac1ac2c6}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Engine\builtin\Textured">
<UniqueIdentifier>{2e0e6381-fca9-42aa-87a9-04495a753104}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Engine\builtin\Basic">
<UniqueIdentifier>{283b2135-b031-48f0-b3cc-564a864e13bd}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Engine\builtin\Lit">
<UniqueIdentifier>{a67acfda-71a8-46cf-8207-bfdece4228ac}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Engine\builtin\Textured">
<UniqueIdentifier>{4c6497d4-160a-45a1-a23b-7bf905de0824}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
@ -120,18 +138,12 @@
<ClCompile Include="GLUtil.cpp"> <ClCompile Include="GLUtil.cpp">
<Filter>Source Files\Engine\builtin</Filter> <Filter>Source Files\Engine\builtin</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="BasicScene.cpp">
<Filter>Source Files\Engine\builtin</Filter>
</ClCompile>
<ClCompile Include="MyBuiltinCubeScene.cpp"> <ClCompile Include="MyBuiltinCubeScene.cpp">
<Filter>Source Files\Example\Application</Filter> <Filter>Source Files\Example\Application</Filter>
</ClCompile> </ClCompile>
<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"> <ClCompile Include="MyBuiltinLitScene.cpp">
<Filter>Source Files\Example\Application</Filter> <Filter>Source Files\Example\Application</Filter>
</ClCompile> </ClCompile>
@ -139,10 +151,25 @@
<Filter>Source Files\Engine\Rendering</Filter> <Filter>Source Files\Engine\Rendering</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="BasicBatch.cpp"> <ClCompile Include="BasicBatch.cpp">
<Filter>Source Files\Engine\builtin</Filter> <Filter>Source Files\Engine\builtin\Basic</Filter>
</ClCompile>
<ClCompile Include="BasicScene.cpp">
<Filter>Source Files\Engine\builtin\Basic</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="LitBatch.cpp"> <ClCompile Include="LitBatch.cpp">
<Filter>Source Files\Engine\builtin</Filter> <Filter>Source Files\Engine\builtin\Lit</Filter>
</ClCompile>
<ClCompile Include="LitScene.cpp">
<Filter>Source Files\Engine\builtin\Lit</Filter>
</ClCompile>
<ClCompile Include="TexturedBatch.cpp">
<Filter>Source Files\Engine\builtin\Textured</Filter>
</ClCompile>
<ClCompile Include="TexturedScene.cpp">
<Filter>Source Files\Engine\builtin\Textured</Filter>
</ClCompile>
<ClCompile Include="MyBuiltinTexturedScene.cpp">
<Filter>Source Files\Example\Application</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -236,15 +263,9 @@
<ClInclude Include="GLUtil.h"> <ClInclude Include="GLUtil.h">
<Filter>Header Files\Engine\builtin</Filter> <Filter>Header Files\Engine\builtin</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="BasicShaderProgram.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="VertexFragmentShaderProgram.h"> <ClInclude Include="VertexFragmentShaderProgram.h">
<Filter>Header Files\Engine\Rendering</Filter> <Filter>Header Files\Engine\Rendering</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="BasicScene.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="MyBuiltinCubeScene.h"> <ClInclude Include="MyBuiltinCubeScene.h">
<Filter>Header Files\Example\Application</Filter> <Filter>Header Files\Example\Application</Filter>
</ClInclude> </ClInclude>
@ -260,9 +281,6 @@
<ClInclude Include="BuiltinCamera3D.h"> <ClInclude Include="BuiltinCamera3D.h">
<Filter>Header Files\Engine\builtin</Filter> <Filter>Header Files\Engine\builtin</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="LitScene.h">
<Filter>Header Files\Engine\builtin</Filter>
</ClInclude>
<ClInclude Include="PoseableBatch.h"> <ClInclude Include="PoseableBatch.h">
<Filter>Header Files\Engine\builtin</Filter> <Filter>Header Files\Engine\builtin</Filter>
</ClInclude> </ClInclude>
@ -275,17 +293,38 @@
<ClInclude Include="Batched.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"> <ClInclude Include="MyBuiltinLitScene.h">
<Filter>Header Files\Example\Application</Filter> <Filter>Header Files\Example\Application</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="BasicBatch.h"> <ClInclude Include="BasicBatch.h">
<Filter>Header Files\Engine\builtin</Filter> <Filter>Header Files\Engine\builtin\Basic</Filter>
</ClInclude>
<ClInclude Include="BasicScene.h">
<Filter>Header Files\Engine\builtin\Basic</Filter>
</ClInclude>
<ClInclude Include="BasicShaderProgram.h">
<Filter>Header Files\Engine\builtin\Basic</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="LitBatch.h"> <ClInclude Include="LitBatch.h">
<Filter>Header Files\Engine\builtin</Filter> <Filter>Header Files\Engine\builtin\Lit</Filter>
</ClInclude>
<ClInclude Include="LitScene.h">
<Filter>Header Files\Engine\builtin\Lit</Filter>
</ClInclude>
<ClInclude Include="LitShaderProgram.h">
<Filter>Header Files\Engine\builtin\Lit</Filter>
</ClInclude>
<ClInclude Include="TexturedBatch.h">
<Filter>Header Files\Engine\builtin\Textured</Filter>
</ClInclude>
<ClInclude Include="TexturedScene.h">
<Filter>Header Files\Engine\builtin\Textured</Filter>
</ClInclude>
<ClInclude Include="TexturedShaderProgram.h">
<Filter>Header Files\Engine\builtin\Textured</Filter>
</ClInclude>
<ClInclude Include="MyBuiltinTexturedScene.h">
<Filter>Header Files\Example\Application</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -313,5 +352,11 @@
<None Include="LitFS.glsl"> <None Include="LitFS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter> <Filter>Source Files\Engine\builtin\Shaders</Filter>
</None> </None>
<None Include="TexturedVS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter>
</None>
<None Include="TexturedFS.glsl">
<Filter>Source Files\Engine\builtin\Shaders</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

21
OpenGLEngine/Sampler.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "Sampler.h"
namespace charcoal
{
Sampler::Sampler(Wrap wrap_s, Wrap wrap_t, MagFilter magnification_filter, MinFilter minification_filter)
{
glGenSamplers(1, &m_sampler);
glSamplerParameteri(m_sampler, GL_WRAP_S, wrap_s);
}
Sampler::~Sampler()
{
glDeleteSamplers(1, &m_sampler);
}
void Sampler::bind(GLuint texture_unit)
{
glBindSampler(texture_unit, m_sampler);
}
}

48
OpenGLEngine/Sampler.h Normal file
View File

@ -0,0 +1,48 @@
#pragma once
#include "stdafx.h"
namespace charcoal
{
class Sampler
{
public:
enum MinFilter : GLenum
{
NEAREST = GL_NEAREST,
LINEAR = GL_LINEAR,
NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
};
enum MagFilter : GLenum
{
NEAREST = GL_NEAREST,
LINEAR = GL_LINEAR,
};
enum Wrap : GLenum
{
CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
MIRRORED_REPEAT = GL_MIRRORED_REPEAT,
REPEAT = GL_REPEAT,
};
/*
TODO:
GL_TEXTURE_BORDER_COLOR, GL_TEXTURE_MIN_LOD, GL_TEXTURE_MAX_LOD,
GL_TEXTURE_LOD_BIAS GL_TEXTURE_COMPARE_MODE, GL_TEXTURE_COMPARE_FUNC,
GL_TEXTURE_WRAP_R
*/
Sampler(Wrap wrap_s, Wrap wrap_t, MagFilter magnification_filter, MinFilter minification_filter);
~Sampler();
void bind(GLuint texture_unit);
private:
GLuint m_sampler = 0;
};
}

199
OpenGLEngine/Texture.h Normal file
View File

@ -0,0 +1,199 @@
#pragma once
#include "stdafx.h"
#include "Exception.h"
#include <vector>
namespace charcoal
{
class Texture
{
public:
enum Target : GLenum
{
TEXTURE_2D = GL_TEXTURE_2D,
PROXY_TEXTURE_2D = GL_PROXY_TEXTURE_2D,
TEXTURE_1D_ARRAY = GL_TEXTURE_1D_ARRAY,
PROXY_TEXTURE_1D_ARRAY = GL_PROXY_TEXTURE_1D_ARRAY,
TEXTURE_RECTANGLE = GL_TEXTURE_RECTANGLE,
PROXY_TEXTURE_RECTANGLE = GL_PROXY_TEXTURE_RECTANGLE,
TEXTURE_CUBE_MAP_POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X,
TEXTURE_CUBE_MAP_NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
TEXTURE_CUBE_MAP_POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
TEXTURE_CUBE_MAP_NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
TEXTURE_CUBE_MAP_POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
TEXTURE_CUBE_MAP_NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
PROXY_TEXTURE_CUBE_MAP = GL_PROXY_TEXTURE_CUBE_MAP,
};
enum InternalFormat : GLint
{
// Base Internal Formats
DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
DEPTH_STENCIL = GL_DEPTH_STENCIL,
RED = GL_RED,
RG = GL_RG,
RGB = GL_RGB,
RGBA = GL_RGBA,
// Sized Internal Formats
R8 = GL_R8,
R8_SNORM = GL_R8_SNORM,
R16 = GL_R16,
R16_SNORM = GL_R16_SNORM,
RG8 = GL_RG8,
RG8_SNORM = GL_RG8_SNORM,
RG16 = GL_RG16,
RG16_SNORM = GL_RG16_SNORM,
R3_G3_B2 = GL_R3_G3_B2,
RGB4 = GL_RGB4,
RGB5 = GL_RGB5,
RGB8 = GL_RGB8,
RGB8_SNORM = GL_RGB8_SNORM,
RGB10 = GL_RGB10,
RGB12 = GL_RGB12,
RGB16_SNORM = GL_RGB16_SNORM,
RGBA2 = GL_RGBA2,
RGBA4 = GL_RGBA4,
RGB5_A1 = GL_RGB5_A1,
RGBA8 = GL_RGBA8,
RGBA8_SNORM = GL_RGBA8_SNORM,
RGB10_A2 = GL_RGB10_A2,
RGB10_A2UI = GL_RGB10_A2UI,
RGBA12 = GL_RGBA12,
RGBA16 = GL_RGBA16,
SRGB8 = GL_SRGB8,
SRGB8_ALPHA8 = GL_SRGB8_ALPHA8,
R16F = GL_R16F,
RG16F = GL_RG16F,
RGB16F = GL_RGB16F,
RGBA16F = GL_RGBA16F,
R32F = GL_R32F,
RG32F = GL_RG32F,
RGB32F = GL_RGB32F,
RGBA32F = GL_RGBA32F,
R11F_G11F_B10F = GL_R11F_G11F_B10F,
RGB9_E5 = GL_RGB9_E5,
R8I = GL_R8I,
R8UI = GL_R8UI,
R16I = GL_R16I,
R16UI = GL_R16UI,
R32I = GL_R32I,
R32UI = GL_R32UI,
RG8I = GL_RG8I,
RG8UI = GL_RG8UI,
RG16I = GL_RG16I,
RG16UI = GL_RG16UI,
RG32I = GL_RG32I,
RG32UI = GL_RG32UI,
RGB8I = GL_RGB8I,
RGB8UI = GL_RGB8UI,
RGB16I = GL_RGB16I,
RGB16UI = GL_RGB16UI,
RGB32I = GL_RGB32I,
RGB32UI = GL_RGB32UI,
RGBA8I = GL_RGBA8I,
RGBA8UI = GL_RGBA8UI,
RGBA16I = GL_RGBA16I,
RGBA16UI = GL_RGBA16UI,
RGBA32I = GL_RGBA32I,
RGBA32UI = GL_RGBA32UI,
// Compressed Internal Formats
COMPRESSED_RED = GL_COMPRESSED_RED,
COMPRESSED_RG = GL_COMPRESSED_RG,
COMPRESSED_RGB = GL_COMPRESSED_RGB,
COMPRESSED_RGBA = GL_COMPRESSED_RGBA,
COMPRESSED_SRGB = GL_COMPRESSED_SRGB,
COMPRESSED_SRGB_ALPHA = GL_COMPRESSED_SRGB_ALPHA,
COMPRESSED_RED_RGTC1 = GL_COMPRESSED_RED_RGTC1,
COMPRESSED_SIGNED_RED_RGTC1 = GL_COMPRESSED_SIGNED_RED_RGTC1,
COMPRESSED_RG_RGTC2 = GL_COMPRESSED_RG_RGTC2,
COMPRESSED_SIGNED_RG_RGTC2 = GL_COMPRESSED_SIGNED_RG_RGTC2,
COMPRESSED_RGBA_BPTC_UNORM = GL_COMPRESSED_RGBA_BPTC_UNORM,
COMPRESSED_SRGB_ALPHA_BPTC_UNORM = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
COMPRESSED_RGB_BPTC_SIGNED_FLOAT = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
};
enum Format : GLenum
{
RED = GL_RED,
RG = GL_RG,
RGB = GL_RGB,
BGR = GL_BGR,
RGBA = GL_RGBA,
BGRA = GL_BGRA,
RED_INTEGER = GL_RED_INTEGER,
RG_INTEGER = GL_RG_INTEGER,
RGB_INTEGER = GL_RGB_INTEGER,
BGR_INTEGER = GL_BGR_INTEGER,
RGBA_INTEGER = GL_RGBA_INTEGER,
BGRA_INTEGER = GL_BGRA_INTEGER,
STENCIL_INDEX = GL_STENCIL_INDEX,
DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
DEPTH_STENCIL = GL_DEPTH_STENCIL,
};
enum Type : GLenum
{
UNSIGNED_BYTE = GL_UNSIGNED_BYTE,
BYTE = GL_BYTE,
UNSIGNED_SHORT = GL_UNSIGNED_SHORT,
SHORT = GL_SHORT,
UNSIGNED_INT = GL_UNSIGNED_INT,
INT = GL_INT,
FLOAT = GL_FLOAT,
UNSIGNED_BYTE_3_3_2 = GL_UNSIGNED_BYTE_3_3_2,
UNSIGNED_BYTE_2_3_3_REV = GL_UNSIGNED_BYTE_2_3_3_REV,
UNSIGNED_SHORT_5_6_5 = GL_UNSIGNED_SHORT_5_6_5,
UNSIGNED_SHORT_5_6_5_REV = GL_UNSIGNED_SHORT_5_6_5_REV,
UNSIGNED_SHORT_4_4_4_4 = GL_UNSIGNED_SHORT_4_4_4_4,
UNSIGNED_SHORT_4_4_4_4_REV = GL_UNSIGNED_SHORT_4_4_4_4_REV,
UNSIGNED_SHORT_5_5_5_1 = GL_UNSIGNED_SHORT_5_5_5_1,
UNSIGNED_SHORT_1_5_5_5_REV = GL_UNSIGNED_SHORT_1_5_5_5_REV,
UNSIGNED_INT_8_8_8_8 = GL_UNSIGNED_INT_8_8_8_8,
UNSIGNED_INT_8_8_8_8_REV = GL_UNSIGNED_INT_8_8_8_8_REV,
UNSIGNED_INT_10_10_10_2 = GL_UNSIGNED_INT_10_10_10_2,
UNSIGNED_INT_2_10_10_10_REV = GL_UNSIGNED_INT_2_10_10_10_REV,
};
template <typename T>
Texture(
Format data_format,
Type data_type,
unsigned long width,
unsigned long height,
const std::vector<T>& data,
InternalFormat internal_format,
unsigned short mipmap_level = 0,
Target texture_target = TEXTURE_2D
)
: width(width), height(height)
{
if (texture_target != TEXTURE_2D)
throw EXCEPTION("Non 2D textures are not supported yet.");
glGenTextures(1, &m_texture);
glBindTexture(texture_target, m_texture);
glTexImage2D(texture_target, mipmap_level, internal_format, width, height, 0, data_format, data_type, data);
glGenerateMipmap(texture_target);
glBindTexture(texture_target, NULL);
}
~Texture()
{
glDeleteTextures(1, &m_texture);
}
private:
GLuint m_texture = 0;
unsigned long width;
unsigned long height;
};
}

View File

@ -0,0 +1,32 @@
#include "TexturedBatch.h"
namespace charcoal
{
namespace builtin
{
void TexturedBatch::setup_vao()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void*)offsetof(TexturedVertex, position));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void*)offsetof(TexturedVertex, uv));
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[0]);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
glVertexAttribDivisor(0, 0); // Send the mesh data once
glVertexAttribDivisor(1, 0); // Send the mesh data once
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
}
}
}

View File

@ -0,0 +1,30 @@
#pragma once
#include "PoseableBatch.h"
#include "BuiltinTypes.h"
namespace charcoal
{
namespace builtin
{
class TexturedBatch : public PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>
{
public:
TexturedBatch(
TexturedRenderable* renderable,
int element_count
) : PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>(renderable, element_count)
{}
TexturedBatch(
TexturedRenderable* renderable,
int element_count,
int element_render_count
) : PoseableBatch<TexturedVertex, TexturedIndex, TexturedRenderable>(renderable, element_count, element_render_count)
{}
protected:
void setup_vao() override;
};
}
}

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,45 @@
#include "TexturedScene.h"
#include "stdafx.h"
#include "GLUtil.h"
#include "MeshFactory.h"
namespace charcoal
{
namespace builtin
{
void TexturedScene::init()
{
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
TexturedBatch& batch = *iter;
batch.init();
add_prerenderable(&batch);
}
}
void TexturedScene::use()
{
// TODO: move to glutil
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void TexturedScene::unuse()
{
}
void TexturedScene::render()
{
glutil::clear_screen();
m_shader_program.use();
glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix());
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{
iter->render();
}
}
}
}

View File

@ -0,0 +1,39 @@
#pragma once
#include <vector>
#include "AutoPrerenderingScene.h"
#include "BuiltinTypes.h"
#include "Camera.h"
#include "Batched.h"
#include "TexturedBatch.h"
#include "TexturedShaderProgram.h"
namespace charcoal
{
namespace builtin
{
class TexturedScene : public AutoPrerenderingScene, public Batched<TexturedRenderable, TexturedBatch>
{
public:
TexturedScene(Application& application) : AutoPrerenderingScene(application) {}
virtual ~TexturedScene() {}
void init() override;
void use() override;
void unuse() override;
void render() override;
protected:
void set_camera(const Camera* p_camera) { m_p_camera = p_camera; }
private:
TexturedShaderProgram m_shader_program;
const Camera* m_p_camera = nullptr;
};
}
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "VertexFragmentShaderProgram.h"
namespace charcoal
{
namespace builtin
{
class TexturedShaderProgram : public VertexFragmentShaderProgram
{
public:
TexturedShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "TexturedVS.glsl", SHADER_PATH "TexturedFS.glsl") {}
};
}
}

View File

@ -0,0 +1,11 @@
#version 430
layout(location = 0) in vec3 vertex_position;
layout(location = 1) in vec2 vertex_uv;
layout(location = 2) 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);
}