allow use of mipmaps in framebuffers
This commit is contained in:
parent
e8767d3971
commit
4276bd680d
|
@ -1 +1 @@
|
||||||
Subproject commit dd648e1431171bffe091b748744395780df7eba1
|
Subproject commit 9beb17daaeb170c127c39c5a5e4feb9d95ebed92
|
|
@ -83,6 +83,11 @@ void FrameBuffer::release()
|
||||||
g_graphics.setViewportSize(m_oldViewportSize);
|
g_graphics.setViewportSize(m_oldViewportSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrameBuffer::generateMipmaps()
|
||||||
|
{
|
||||||
|
m_texture->generateMipmaps();
|
||||||
|
}
|
||||||
|
|
||||||
void FrameBuffer::draw(const Rect& dest)
|
void FrameBuffer::draw(const Rect& dest)
|
||||||
{
|
{
|
||||||
g_painter.drawTexturedRect(dest, m_texture);
|
g_painter.drawTexturedRect(dest, m_texture);
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
void resize(const Size& size);
|
void resize(const Size& size);
|
||||||
void bind(bool clear = true);
|
void bind(bool clear = true);
|
||||||
void release();
|
void release();
|
||||||
|
void generateMipmaps();
|
||||||
void draw(const Rect& dest);
|
void draw(const Rect& dest);
|
||||||
|
|
||||||
void setClearColor(const Color& color) { m_clearColor = color; }
|
void setClearColor(const Color& color) { m_clearColor = color; }
|
||||||
|
|
|
@ -89,29 +89,31 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
// nearest filtering (non smooth)
|
setupFilters();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::generateMipmaps()
|
||||||
|
{
|
||||||
|
bind();
|
||||||
|
|
||||||
|
if(!m_useMipmaps) {
|
||||||
|
m_useMipmaps = true;
|
||||||
|
setupFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::setSmooth(bool smooth)
|
void Texture::setSmooth(bool smooth)
|
||||||
{
|
{
|
||||||
if(smooth == m_smooth)
|
if(smooth == m_smooth)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(smooth) {
|
m_smooth = smooth;
|
||||||
// enable smooth texture
|
bind();
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
setupFilters();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
} else {
|
|
||||||
// nearest filtering (non smooth)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_smooth = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8> Texture::getPixels()
|
std::vector<uint8> Texture::getPixels()
|
||||||
|
@ -125,3 +127,18 @@ std::vector<uint8> Texture::getPixels()
|
||||||
fb->release();
|
fb->release();
|
||||||
return pixels;
|
return pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::setupFilters()
|
||||||
|
{
|
||||||
|
GLint minFilter;
|
||||||
|
GLint magFilter;
|
||||||
|
if(m_smooth) {
|
||||||
|
minFilter = m_useMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
|
||||||
|
magFilter = GL_LINEAR;
|
||||||
|
} else {
|
||||||
|
minFilter = m_useMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST;
|
||||||
|
magFilter = GL_NEAREST;
|
||||||
|
}
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
|
||||||
|
}
|
||||||
|
|
|
@ -32,7 +32,10 @@ public:
|
||||||
Texture(int width, int height, int channels, uchar* pixels = NULL);
|
Texture(int width, int height, int channels, uchar* pixels = NULL);
|
||||||
virtual ~Texture();
|
virtual ~Texture();
|
||||||
|
|
||||||
virtual void setSmooth(bool smooth);
|
void bind() { glBindTexture(GL_TEXTURE_2D, m_textureId); }
|
||||||
|
|
||||||
|
void generateMipmaps();
|
||||||
|
void setSmooth(bool smooth);
|
||||||
GLuint getId() { return m_textureId; }
|
GLuint getId() { return m_textureId; }
|
||||||
|
|
||||||
std::vector<uint8> getPixels();
|
std::vector<uint8> getPixels();
|
||||||
|
@ -44,10 +47,12 @@ public:
|
||||||
bool isEmpty() const { return m_textureId == 0; }
|
bool isEmpty() const { return m_textureId == 0; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void setupFilters();
|
||||||
GLuint internalLoadGLTexture(uchar* pixels, int channels, int w, int h);
|
GLuint internalLoadGLTexture(uchar* pixels, int channels, int w, int h);
|
||||||
|
|
||||||
GLuint m_textureId;
|
GLuint m_textureId;
|
||||||
Size m_size;
|
Size m_size;
|
||||||
|
Boolean<false> m_useMipmaps;
|
||||||
Boolean<false> m_smooth;
|
Boolean<false> m_smooth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue