gsdx mipmap:ogl: add capabilities to automatically generate mipmap layer

This commit is contained in:
Gregory Hainaut 2016-10-02 10:41:18 +02:00
parent 510eccd471
commit 1b9b47dd6a
6 changed files with 19 additions and 1 deletions

View File

@ -139,6 +139,7 @@ PFNGLCOPYTEXTURESUBIMAGE2DPROC glCopyTextureSubImage2D = NUL
PFNGLBINDTEXTUREUNITPROC glBindTextureUnit = NULL; PFNGLBINDTEXTUREUNITPROC glBindTextureUnit = NULL;
PFNGLGETTEXTUREIMAGEPROC glGetTextureImage = NULL; PFNGLGETTEXTUREIMAGEPROC glGetTextureImage = NULL;
PFNGLTEXTUREPARAMETERIPROC glTextureParameteri = NULL; PFNGLTEXTUREPARAMETERIPROC glTextureParameteri = NULL;
PFNGLGENERATETEXTUREMIPMAPPROC glGenerateTextureMipmap = NULL;
PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers = NULL; PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers = NULL;
PFNGLCLEARNAMEDFRAMEBUFFERFVPROC glClearNamedFramebufferfv = NULL; PFNGLCLEARNAMEDFRAMEBUFFERFVPROC glClearNamedFramebufferfv = NULL;

View File

@ -318,6 +318,7 @@ extern PFNGLCOPYTEXTURESUBIMAGE2DPROC glCopyTextureSubImage2D;
extern PFNGLBINDTEXTUREUNITPROC glBindTextureUnit; extern PFNGLBINDTEXTUREUNITPROC glBindTextureUnit;
extern PFNGLGETTEXTUREIMAGEPROC glGetTextureImage; extern PFNGLGETTEXTUREIMAGEPROC glGetTextureImage;
extern PFNGLTEXTUREPARAMETERIPROC glTextureParameteri; extern PFNGLTEXTUREPARAMETERIPROC glTextureParameteri;
extern PFNGLGENERATETEXTUREMIPMAPPROC glGenerateTextureMipmap;
extern PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers; extern PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers;
extern PFNGLCLEARNAMEDFRAMEBUFFERFVPROC glClearNamedFramebufferfv; extern PFNGLCLEARNAMEDFRAMEBUFFERFVPROC glClearNamedFramebufferfv;

View File

@ -46,6 +46,7 @@ public:
virtual bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) = 0; virtual bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) = 0;
virtual bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) = 0; virtual bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) = 0;
virtual void Unmap() = 0; virtual void Unmap() = 0;
virtual void GenerateMipmap() {}
virtual bool Save(const string& fn, bool dds = false) = 0; virtual bool Save(const string& fn, bool dds = false) = 0;
virtual uint32 GetID() { return 0; } virtual uint32 GetID() { return 0; }

View File

@ -153,7 +153,7 @@ namespace PboPool {
} }
GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read, bool mipmap) GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read, bool mipmap)
: m_pbo_size(0), m_clean(false), m_local_buffer(NULL), m_r_x(0), m_r_y(0), m_r_w(0), m_r_h(0), m_layer(0) : m_pbo_size(0), m_clean(false), m_generate_mipmap(true), m_local_buffer(NULL), m_r_x(0), m_r_y(0), m_r_w(0), m_r_h(0), m_layer(0)
{ {
// OpenGL didn't like dimensions of size 0 // OpenGL didn't like dimensions of size 0
m_size.x = max(1,w); m_size.x = max(1,w);
@ -370,6 +370,8 @@ bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch, int
PboPool::EndTransfer(); PboPool::EndTransfer();
#endif #endif
m_generate_mipmap = true;
return true; return true;
} }
@ -452,10 +454,20 @@ void GSTextureOGL::Unmap()
PboPool::EndTransfer(); PboPool::EndTransfer();
m_generate_mipmap = true;
GL_POP(); // PUSH is in Map GL_POP(); // PUSH is in Map
} }
} }
void GSTextureOGL::GenerateMipmap()
{
if (m_generate_mipmap && m_max_layer > 1) {
glGenerateTextureMipmap(m_texture_id);
m_generate_mipmap = false;
}
}
bool GSTextureOGL::Save(const string& fn, bool dds) bool GSTextureOGL::Save(const string& fn, bool dds)
{ {
// Collect the texture data // Collect the texture data

View File

@ -44,6 +44,7 @@ class GSTextureOGL final : public GSTexture
int m_pbo_size; int m_pbo_size;
GLuint m_fbo_read; GLuint m_fbo_read;
bool m_clean; bool m_clean;
bool m_generate_mipmap;
uint8* m_local_buffer; uint8* m_local_buffer;
// Avoid alignment constrain // Avoid alignment constrain
@ -70,6 +71,7 @@ class GSTextureOGL final : public GSTexture
bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) final; bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) final;
bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) final; bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) final;
void Unmap() final; void Unmap() final;
void GenerateMipmap() final;
bool Save(const string& fn, bool dds = false) final; bool Save(const string& fn, bool dds = false) final;
bool IsBackbuffer() { return (m_type == GSTexture::Backbuffer); } bool IsBackbuffer() { return (m_type == GSTexture::Backbuffer); }

View File

@ -146,6 +146,7 @@ void GSWndGL::PopulateGlFunction()
GL_EXT_LOAD(glBindTextureUnit); GL_EXT_LOAD(glBindTextureUnit);
GL_EXT_LOAD(glGetTextureImage); GL_EXT_LOAD(glGetTextureImage);
GL_EXT_LOAD(glTextureParameteri); GL_EXT_LOAD(glTextureParameteri);
GL_EXT_LOAD(glGenerateTextureMipmap);
GL_EXT_LOAD(glCreateFramebuffers); GL_EXT_LOAD(glCreateFramebuffers);
GL_EXT_LOAD(glClearNamedFramebufferfv); GL_EXT_LOAD(glClearNamedFramebufferfv);