added image widget with atlas support and global texture manager

This commit is contained in:
2017-02-07 23:42:39 +00:00
parent 83e59573e0
commit 5e5ddf310c
10 changed files with 167 additions and 9 deletions

View File

@@ -1,6 +1,24 @@
#include "pch.h"
#include "texture.h"
#include "image.h"
#include "util.h"
std::map<uint16_t, Texture2D> TextureManager::m_textures;
bool TextureManager::load(const char* path)
{
uint16_t id = const_hash(path);
if (m_textures.count(id) == 0 || !m_textures[id].ready())
{
return m_textures[id].load(path);
}
return true;
}
Texture2D& TextureManager::get(uint16_t id)
{
return m_textures[id];
}
bool Texture2D::create(int width, int height, GLint format, const uint8_t* data)
{
@@ -31,6 +49,11 @@ void Texture2D::update(const uint8_t* data)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, m_format, GL_UNSIGNED_BYTE, data);
}
glm::vec2 Texture2D::size() const
{
return { m_width, m_height };
}
bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
{
glGenSamplers(1, &id);
@@ -55,3 +78,4 @@ void Sampler::unbind()
{
glBindSampler(current_unit, 0);
}