Image Rendering almost works!

There is an OpenGL error (1282) invalid operation that is getting
caught when switching to the imagescene. This needs to get fixed
and then hopefully the whole thing will work.
This commit is contained in:
Elipzer 2018-10-09 19:58:26 -04:00
parent b7456401e0
commit 5a9765b111
10 changed files with 91 additions and 60 deletions

View File

@ -1,4 +1,4 @@
#include "TexturedScene.h" #include "ImageScene.h"
#include "stdafx.h" #include "stdafx.h"
@ -9,7 +9,7 @@ namespace charcoal
{ {
namespace builtin namespace builtin
{ {
namespace textured namespace image
{ {
void Scene::init() void Scene::init()
{ {
@ -37,7 +37,7 @@ namespace charcoal
{ {
glutil::clear_screen(); glutil::clear_screen();
m_shader_program.use(); m_shader_program.use();
glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix());
glutil::uniform_int(4, 0); // The textured batch uses GL_TEXTURE0 glutil::uniform_int(4, 0); // The textured batch uses GL_TEXTURE0
for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter)
{ {

View File

@ -13,7 +13,7 @@ namespace charcoal
typedef PTVertex Vertex; typedef PTVertex Vertex;
typedef Index Index; typedef Index Index;
typedef TextureRenderable<Vertex, Index> Renderable; typedef TextureRenderable<Vertex, Index> Renderable;
typedef SpriteBatch<Vertex, Index> Batch; typedef SpriteBatch<Vertex, Index, offsetof(Vertex, position), offsetof(Vertex, uv)> Batch;
} }
} }
} }

View File

@ -688,7 +688,8 @@ namespace charcoal
mesh->indices[3] = 0; mesh->indices[3] = 0;
mesh->indices[4] = 3; mesh->indices[4] = 3;
mesh->indices[5] = 2; mesh->indices[5] = 2;
break;
return mesh;
case DrawMode::DRAW_TRIANGLE_STRIP: case DrawMode::DRAW_TRIANGLE_STRIP:
mesh = MeshFactory<VertexType, IndexType>::create_mesh(4, 4); mesh = MeshFactory<VertexType, IndexType>::create_mesh(4, 4);
@ -706,7 +707,8 @@ namespace charcoal
mesh->indices[1] = 3; mesh->indices[1] = 3;
mesh->indices[2] = 0; mesh->indices[2] = 0;
mesh->indices[3] = 2; mesh->indices[3] = 2;
break;
return mesh;
case DrawMode::DRAW_TRIANGLE_FAN: case DrawMode::DRAW_TRIANGLE_FAN:
mesh = MeshFactory<VertexType, IndexType>::create_mesh(4, 4); mesh = MeshFactory<VertexType, IndexType>::create_mesh(4, 4);
@ -724,7 +726,8 @@ namespace charcoal
mesh->indices[1] = 3; mesh->indices[1] = 3;
mesh->indices[2] = 2; mesh->indices[2] = 2;
mesh->indices[3] = 0; mesh->indices[3] = 0;
break;
return mesh;
case DrawMode::DRAW_POINTS: case DrawMode::DRAW_POINTS:
case DrawMode::DRAW_LINES: case DrawMode::DRAW_LINES:
case DrawMode::DRAW_LINE_STRIP: case DrawMode::DRAW_LINE_STRIP:

View File

@ -191,6 +191,8 @@
</ClCompile> </ClCompile>
<ClCompile Include="TexturedBatch.cpp" /> <ClCompile Include="TexturedBatch.cpp" />
<ClCompile Include="TexturedScene.cpp" /> <ClCompile Include="TexturedScene.cpp" />
<ClCompile Include="TextureFactory.cpp" />
<ClCompile Include="TextureGenerator.cpp" />
<ClCompile Include="Util.cpp" /> <ClCompile Include="Util.cpp" />
<ClCompile Include="VertexFragmentShaderProgram.cpp" /> <ClCompile Include="VertexFragmentShaderProgram.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -258,6 +258,12 @@
<ClCompile Include="MyBuiltinImageScene.cpp"> <ClCompile Include="MyBuiltinImageScene.cpp">
<Filter>Source Files\Example\Application</Filter> <Filter>Source Files\Example\Application</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="TextureGenerator.cpp">
<Filter>Source Files\Engine\builtin\General</Filter>
</ClCompile>
<ClCompile Include="TextureFactory.cpp">
<Filter>Source Files\Engine\Baseline</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Application.h"> <ClInclude Include="Application.h">

View File

@ -8,9 +8,10 @@ namespace charcoal
{ {
namespace builtin namespace builtin
{ {
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType, int position_offset, int uv_offset>
class SpriteBatch : public Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> > class SpriteBatch : public Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >
{ {
public:
// Note: This is VERY similar to builtin::textured::Batch // Note: This is VERY similar to builtin::textured::Batch
// TODO: Use Poseable2D for each sprite's position // TODO: Use Poseable2D for each sprite's position
// TODO: Have a texture // TODO: Have a texture
@ -43,8 +44,8 @@ namespace charcoal
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
// TODO: Figure out how to do this without offsetof :( // TODO: Figure out how to do this without offsetof :(
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)offsetof(VertexType, position)); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)position_offset);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)offsetof(VertexType, uv)); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)uv_offset);
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_element_buffers[0]); glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_element_buffers[0]);
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3); glEnableVertexAttribArray(3);

View File

@ -0,0 +1,7 @@
#include "TextureFactory.h"
namespace charcoal
{
std::vector<Texture> TextureFactory::m_textures;
std::vector<Sampler> TextureFactory::m_samplers;
}

View File

@ -52,7 +52,4 @@ namespace charcoal
static std::vector<Texture> m_textures; static std::vector<Texture> m_textures;
static std::vector<Sampler> m_samplers; static std::vector<Sampler> m_samplers;
}; };
std::vector<Texture> TextureFactory::m_textures;
std::vector<Sampler> TextureFactory::m_samplers;
} }

View File

@ -0,0 +1,60 @@
#include "TextureGenerator.h"
#include "TextureFactory.h"
namespace charcoal
{
namespace builtin
{
namespace texturegenerator
{
Texture* gen_quick_cube_texture()
{
std::vector<unsigned char> values;
// Front
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(255);
// Right
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(255);
// Back
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(255);
values.emplace_back(255);
// Left
values.emplace_back(0);
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(255);
// Top
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(0);
values.emplace_back(255);
// Bottom
values.emplace_back(0);
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(255);
return TextureFactory::gen_texture(Texture::Format::RGBA, Texture::Type::UNSIGNED_BYTE, 6, 1, values, Texture::InternalFormat::RGBA);
}
Sampler* gen_quick_sampler()
{
return TextureFactory::gen_sampler(Sampler::Wrap::REPEAT, Sampler::Wrap::REPEAT, Sampler::MagFilter::NEAREST, Sampler::MinFilter::NEAREST);
}
}
}
}

View File

@ -4,7 +4,6 @@
#include "Texture.h" #include "Texture.h"
#include "Sampler.h" #include "Sampler.h"
#include "TextureFactory.h"
namespace charcoal namespace charcoal
{ {
@ -12,53 +11,9 @@ namespace charcoal
{ {
namespace texturegenerator namespace texturegenerator
{ {
Texture* gen_quick_cube_texture() Texture* gen_quick_cube_texture();
{
std::vector<unsigned char> values;
// Front
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(255);
// Right
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(255);
// Back
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(255);
values.emplace_back(255);
// Left
values.emplace_back(0);
values.emplace_back(255);
values.emplace_back(255);
values.emplace_back(255);
// Top
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(0);
values.emplace_back(255);
// Bottom
values.emplace_back(0);
values.emplace_back(255);
values.emplace_back(0);
values.emplace_back(255);
return TextureFactory::gen_texture(Texture::Format::RGBA, Texture::Type::UNSIGNED_BYTE, 6, 1, values, Texture::InternalFormat::RGBA);
}
Sampler* gen_quick_sampler() Sampler* gen_quick_sampler();
{
return TextureFactory::gen_sampler(Sampler::Wrap::REPEAT, Sampler::Wrap::REPEAT, Sampler::MagFilter::NEAREST, Sampler::MinFilter::NEAREST);
}
} }
} }
} }