added asset loading class, zoom factor, vbo switch, shader version

This commit is contained in:
2017-03-13 01:16:20 +00:00
parent a2a221b17a
commit ee6d352fc6
25 changed files with 345 additions and 108 deletions

View File

@@ -33,7 +33,7 @@ bool Texture2D::create(int width, int height, GLint format, const uint8_t* data)
}
bool Texture2D::create(const Image& img)
{
static GLint formats[] = { GL_RED, GL_RG, GL_RGB, GL_RGBA };
static GLint formats[] = { 0, 0, GL_RGB, GL_RGBA };
return create(img.width, img.height, formats[img.comp - 1], img.data());
}
bool Texture2D::load(std::string filename)
@@ -56,7 +56,9 @@ glm::vec2 Texture2D::size() const
bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
{
#if USE_SAMPLER
glGenSamplers(1, &id);
#endif // USE_SAMPLER
if (id == 0)
return false;
set(filter, wrap);
@@ -64,18 +66,24 @@ bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_ED
}
void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
{
#if USE_SAMPLER
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, wrap);
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, wrap);
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, filter);
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, filter);
#endif // USE_SAMPLER
}
void Sampler::bind(int unit)
{
current_unit = unit;
#if USE_SAMPLER
glBindSampler(unit, id);
#endif // USE_SAMPLER
}
void Sampler::unbind()
{
#if USE_SAMPLER
glBindSampler(current_unit, 0);
#endif // USE_SAMPLER
}