mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
GL: Added texture mip autogen.
This commit is contained in:
@@ -403,6 +403,7 @@
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT16_C(0x0800) //!< Texture format can be used as frame buffer.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT16_C(0x1000) //!< Texture format can be used as MSAA frame buffer.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT16_C(0x2000) //!< Texture can be sampled as MSAA.
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN UINT16_C(0x4000) //!< Texture format supports auto-generated mips.
|
||||
|
||||
///
|
||||
#define BGFX_VIEW_NONE UINT8_C(0x00) //!<
|
||||
|
||||
28
src/bgfx.cpp
28
src/bgfx.cpp
@@ -1129,25 +1129,26 @@ namespace bgfx
|
||||
}
|
||||
|
||||
BX_TRACE("Supported texture formats:");
|
||||
BX_TRACE("\t +--------------- 2D: x = supported / * = emulated");
|
||||
BX_TRACE("\t |+-------------- 2D: sRGB format");
|
||||
BX_TRACE("\t ||+------------- 3D: x = supported / * = emulated");
|
||||
BX_TRACE("\t |||+------------ 3D: sRGB format");
|
||||
BX_TRACE("\t ||||+----------- Cube: x = supported / * = emulated");
|
||||
BX_TRACE("\t |||||+---------- Cube: sRGB format");
|
||||
BX_TRACE("\t ||||||+--------- vertex format");
|
||||
BX_TRACE("\t |||||||+-------- image");
|
||||
BX_TRACE("\t ||||||||+------- framebuffer");
|
||||
BX_TRACE("\t |||||||||+------ MSAA framebuffer");
|
||||
BX_TRACE("\t ||||||||||+----- MSAA texture");
|
||||
BX_TRACE("\t ||||||||||| +-- name");
|
||||
BX_TRACE("\t +---------------- 2D: x = supported / * = emulated");
|
||||
BX_TRACE("\t |+--------------- 2D: sRGB format");
|
||||
BX_TRACE("\t ||+-------------- 3D: x = supported / * = emulated");
|
||||
BX_TRACE("\t |||+------------- 3D: sRGB format");
|
||||
BX_TRACE("\t ||||+------------ Cube: x = supported / * = emulated");
|
||||
BX_TRACE("\t |||||+----------- Cube: sRGB format");
|
||||
BX_TRACE("\t ||||||+---------- vertex format");
|
||||
BX_TRACE("\t |||||||+--------- image");
|
||||
BX_TRACE("\t ||||||||+-------- framebuffer");
|
||||
BX_TRACE("\t |||||||||+------- MSAA framebuffer");
|
||||
BX_TRACE("\t ||||||||||+------ MSAA texture");
|
||||
BX_TRACE("\t |||||||||||+----- Auto-generated mips");
|
||||
BX_TRACE("\t |||||||||||| +-- name");
|
||||
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
|
||||
{
|
||||
if (TextureFormat::Unknown != ii
|
||||
&& TextureFormat::UnknownDepth != ii)
|
||||
{
|
||||
uint16_t flags = g_caps.formats[ii];
|
||||
BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c] %s"
|
||||
BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c%c] %s"
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_3D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED ? '*' : ' '
|
||||
@@ -1159,6 +1160,7 @@ namespace bgfx
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA ? '+' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_MSAA ? 'm' : ' '
|
||||
, flags&BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN ? 'M' : ' '
|
||||
, getName(TextureFormat::Enum(ii) )
|
||||
);
|
||||
BX_UNUSED(flags);
|
||||
|
||||
@@ -113,6 +113,7 @@ typedef void (GL_APIENTRYP PFNGLFLUSHPROC) ();
|
||||
typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
|
||||
typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
typedef void (GL_APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
|
||||
typedef void (GL_APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target);
|
||||
typedef void (GL_APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers);
|
||||
typedef void (GL_APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids);
|
||||
typedef void (GL_APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers);
|
||||
@@ -301,6 +302,7 @@ GL_IMPORT______(false, PFNGLFLUSHPROC, glFlush);
|
||||
GL_IMPORT______(true, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer);
|
||||
GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D);
|
||||
GL_IMPORT______(false, PFNGLGENBUFFERSPROC, glGenBuffers);
|
||||
GL_IMPORT______(true, PFNGLGENERATEMIPMAPPROC, glGenerateMipmap);
|
||||
GL_IMPORT______(true, PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers);
|
||||
GL_IMPORT______(true, PFNGLGENRENDERBUFFERSPROC, glGenRenderbuffers);
|
||||
GL_IMPORT______(true, PFNGLGENQUERIESPROC, glGenQueries);
|
||||
|
||||
@@ -1429,6 +1429,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_MSAA
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
support |= 0 != (data.OutFormatSupport & (0
|
||||
| D3D11_FORMAT_SUPPORT_MIP_AUTOGEN
|
||||
) )
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -702,6 +702,14 @@ namespace bgfx { namespace d3d9
|
||||
, NULL
|
||||
) ) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
||||
|
||||
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
||||
, m_deviceType
|
||||
, adapterFormat
|
||||
, isDepth(TextureFormat::Enum(ii) ) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET
|
||||
, D3DRTYPE_TEXTURE
|
||||
, s_textureFormat[ii].m_fmt
|
||||
) ) ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
||||
|
||||
g_caps.formats[ii] = support;
|
||||
}
|
||||
|
||||
@@ -1340,8 +1348,7 @@ namespace bgfx { namespace d3d9
|
||||
void setFrameBuffer(FrameBufferHandle _fbh, bool _msaa = true)
|
||||
{
|
||||
if (isValid(m_fbh)
|
||||
&& m_fbh.idx != _fbh.idx
|
||||
&& m_rtMsaa)
|
||||
&& m_fbh.idx != _fbh.idx)
|
||||
{
|
||||
FrameBufferD3D9& frameBuffer = m_frameBuffers[m_fbh.idx];
|
||||
frameBuffer.resolve();
|
||||
|
||||
@@ -2573,21 +2573,16 @@ namespace bgfx { namespace gl
|
||||
uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint16_t _discard = BGFX_CLEAR_NONE, bool _msaa = true)
|
||||
{
|
||||
if (isValid(m_fbh)
|
||||
&& m_fbh.idx != _fbh.idx
|
||||
&& (BGFX_CLEAR_NONE != m_fbDiscard || m_rtMsaa) )
|
||||
&& m_fbh.idx != _fbh.idx)
|
||||
{
|
||||
FrameBufferGL& frameBuffer = m_frameBuffers[m_fbh.idx];
|
||||
if (m_rtMsaa)
|
||||
{
|
||||
frameBuffer.resolve();
|
||||
}
|
||||
frameBuffer.resolve();
|
||||
|
||||
if (BGFX_CLEAR_NONE != m_fbDiscard)
|
||||
{
|
||||
frameBuffer.discard(m_fbDiscard);
|
||||
m_fbDiscard = BGFX_CLEAR_NONE;
|
||||
}
|
||||
|
||||
m_fbDiscard = BGFX_CLEAR_NONE;
|
||||
}
|
||||
|
||||
m_glctx.makeCurrent(NULL);
|
||||
@@ -4823,6 +4818,18 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::resolve() const
|
||||
{
|
||||
const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK);
|
||||
if (renderTarget
|
||||
&& 1 < m_numMips)
|
||||
{
|
||||
GL_CHECK(glBindTexture(m_target, m_id) );
|
||||
GL_CHECK(glGenerateMipmap(m_target) );
|
||||
GL_CHECK(glBindTexture(m_target, 0) );
|
||||
}
|
||||
}
|
||||
|
||||
void writeString(bx::WriterI* _writer, const char* _str)
|
||||
{
|
||||
bx::write(_writer, _str, (int32_t)strlen(_str) );
|
||||
@@ -5548,6 +5555,19 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glReadBuffer(GL_NONE) );
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) );
|
||||
}
|
||||
|
||||
if (0 < m_numTh)
|
||||
{
|
||||
for (uint32_t ii = 0; ii < m_numTh; ++ii)
|
||||
{
|
||||
TextureHandle handle = m_attachment[ii].handle;
|
||||
if (isValid(handle) )
|
||||
{
|
||||
const TextureGL& texture = s_renderGL->m_textures[handle.idx];
|
||||
texture.resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBufferGL::discard(uint16_t _flags)
|
||||
|
||||
@@ -1234,6 +1234,7 @@ namespace bgfx { namespace gl
|
||||
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
|
||||
void setSamplerState(uint32_t _flags, const float _rgba[4]);
|
||||
void commit(uint32_t _stage, uint32_t _flags, const float _palette[][4]);
|
||||
void resolve() const;
|
||||
|
||||
GLuint m_id;
|
||||
GLuint m_rbo;
|
||||
|
||||
Reference in New Issue
Block a user