mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Added support for different RT depth stencil formats.
This commit is contained in:
parent
6005ebda2b
commit
d1117f34b5
7 changed files with 117 additions and 37 deletions
|
@ -476,7 +476,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
Mesh mesh;
|
||||
mesh.load("meshes/bunny.bin");
|
||||
|
||||
bgfx::RenderTargetHandle rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA8|BGFX_RENDER_TARGET_DEPTH);
|
||||
bgfx::RenderTargetHandle rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA8|BGFX_RENDER_TARGET_DEPTH_D16);
|
||||
|
||||
bgfx::RenderTargetHandle lum[5];
|
||||
lum[0] = bgfx::createRenderTarget(128, 128, BGFX_RENDER_TARGET_COLOR_RGBA8);
|
||||
|
@ -528,7 +528,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::destroyRenderTarget(bright);
|
||||
bgfx::destroyRenderTarget(blur);
|
||||
|
||||
rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA8|BGFX_RENDER_TARGET_DEPTH);
|
||||
rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA8|BGFX_RENDER_TARGET_DEPTH_D16);
|
||||
bright = bgfx::createRenderTarget(width/2, height/2, BGFX_RENDER_TARGET_COLOR_RGBA8);
|
||||
blur = bgfx::createRenderTarget(width/8, height/8, BGFX_RENDER_TARGET_COLOR_RGBA8);
|
||||
}
|
||||
|
|
|
@ -1993,7 +1993,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
mem = loadTexture("fieldstone-rgba.dds");
|
||||
bgfx::TextureHandle fieldstoneTex = bgfx::createTexture(mem);
|
||||
|
||||
s_stencilRt = bgfx::createRenderTarget(viewState.m_width, viewState.m_height, BGFX_RENDER_TARGET_COLOR_RGBA8 | BGFX_RENDER_TARGET_DEPTH);
|
||||
s_stencilRt = bgfx::createRenderTarget(viewState.m_width, viewState.m_height, BGFX_RENDER_TARGET_COLOR_RGBA8 | BGFX_RENDER_TARGET_DEPTH_D16);
|
||||
|
||||
u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
|
||||
u_texStencil = bgfx::createUniform("u_texStencil", bgfx::UniformType::Uniform1iv);
|
||||
|
@ -2172,7 +2172,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
|
||||
bgfx::destroyRenderTarget(s_stencilRt);
|
||||
|
||||
s_stencilRt = bgfx::createRenderTarget(viewState.m_width, viewState.m_height, BGFX_RENDER_TARGET_COLOR_RGBA8 | BGFX_RENDER_TARGET_DEPTH);
|
||||
s_stencilRt = bgfx::createRenderTarget(viewState.m_width, viewState.m_height, BGFX_RENDER_TARGET_COLOR_RGBA8 | BGFX_RENDER_TARGET_DEPTH_D16);
|
||||
}
|
||||
|
||||
//set view and projection matrices
|
||||
|
|
|
@ -203,9 +203,18 @@
|
|||
#define BGFX_RENDER_TARGET_COLOR_R32F UINT32_C(0x00000006)
|
||||
#define BGFX_RENDER_TARGET_COLOR_SHIFT 0
|
||||
#define BGFX_RENDER_TARGET_COLOR_MASK UINT32_C(0x000000ff)
|
||||
#define BGFX_RENDER_TARGET_DEPTH UINT32_C(0x00000100)
|
||||
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D16 UINT32_C(0x00000100)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D24 UINT32_C(0x00000200)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D24S8 UINT32_C(0x00000300)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D32 UINT32_C(0x00000400)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D16F UINT32_C(0x00000500)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D24F UINT32_C(0x00000600)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D32F UINT32_C(0x00000700)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_D0S8 UINT32_C(0x00000800)
|
||||
#define BGFX_RENDER_TARGET_DEPTH_SHIFT 8
|
||||
#define BGFX_RENDER_TARGET_DEPTH_MASK UINT32_C(0x0000ff00)
|
||||
|
||||
#define BGFX_RENDER_TARGET_MSAA_X2 UINT32_C(0x00010000)
|
||||
#define BGFX_RENDER_TARGET_MSAA_X4 UINT32_C(0x00020000)
|
||||
#define BGFX_RENDER_TARGET_MSAA_X8 UINT32_C(0x00030000)
|
||||
|
|
|
@ -122,8 +122,15 @@ namespace bgfx
|
|||
|
||||
static const DXGI_FORMAT s_depthFormat[] =
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN, // ignored
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT,
|
||||
DXGI_FORMAT_UNKNOWN, // ignored
|
||||
DXGI_FORMAT_D16_UNORM, // D16
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT, // D24
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT, // D24S8
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT, // D32
|
||||
DXGI_FORMAT_D32_FLOAT, // D16F
|
||||
DXGI_FORMAT_D32_FLOAT, // D24F
|
||||
DXGI_FORMAT_D32_FLOAT, // D32F
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT, // D0S8
|
||||
};
|
||||
|
||||
static const D3D11_TEXTURE_ADDRESS_MODE s_textureAddress[] =
|
||||
|
@ -2740,7 +2747,7 @@ namespace bgfx
|
|||
|
||||
tvm.clear();
|
||||
uint16_t pos = 0;
|
||||
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
|
||||
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " ");
|
||||
|
||||
const DXGI_ADAPTER_DESC& desc = s_renderCtx->m_adapterDesc;
|
||||
char description[BX_COUNTOF(desc.Description)];
|
||||
|
|
|
@ -162,8 +162,19 @@ namespace bgfx
|
|||
|
||||
static const D3DFORMAT s_depthFormat[] =
|
||||
{
|
||||
D3DFMT_UNKNOWN, // ignored
|
||||
D3DFMT_D24S8,
|
||||
D3DFMT_UNKNOWN, // ignored
|
||||
D3DFMT_D16, // D16
|
||||
D3DFMT_D24X8, // D24
|
||||
D3DFMT_D24S8, // D24S8
|
||||
D3DFMT_D32, // D32
|
||||
D3DFMT_DF16, // D16F
|
||||
D3DFMT_DF24, // D24F
|
||||
D3DFMT_D32F_LOCKABLE, // D32F
|
||||
#if defined(D3D_DISABLE_9EX)
|
||||
D3DFMT_UNKNOWN, // D0S8
|
||||
#else
|
||||
D3DFMT_S8_LOCKABLE, // D0S8
|
||||
#endif // defined(D3D_DISABLE_9EX)
|
||||
};
|
||||
|
||||
static const D3DTEXTUREADDRESS s_textureAddress[] =
|
||||
|
@ -1727,8 +1738,8 @@ namespace bgfx
|
|||
if (0 != m_flags)
|
||||
{
|
||||
m_msaa = s_msaa[(m_flags&BGFX_RENDER_TARGET_MSAA_MASK)>>BGFX_RENDER_TARGET_MSAA_SHIFT];
|
||||
uint32_t colorFormat = (m_flags&BGFX_RENDER_TARGET_COLOR_MASK)>>BGFX_RENDER_TARGET_COLOR_SHIFT;
|
||||
uint32_t depthFormat = (m_flags&BGFX_RENDER_TARGET_DEPTH_MASK)>>BGFX_RENDER_TARGET_DEPTH_SHIFT;
|
||||
const uint32_t colorFormat = (m_flags&BGFX_RENDER_TARGET_COLOR_MASK)>>BGFX_RENDER_TARGET_COLOR_SHIFT;
|
||||
const uint32_t depthFormat = (m_flags&BGFX_RENDER_TARGET_DEPTH_MASK)>>BGFX_RENDER_TARGET_DEPTH_SHIFT;
|
||||
m_depthOnly = (0 == colorFormat && 0 < depthFormat);
|
||||
|
||||
// CheckDeviceFormat D3DUSAGE_SRGBWRITE
|
||||
|
@ -1751,7 +1762,7 @@ namespace bgfx
|
|||
, m_height
|
||||
, 1
|
||||
, D3DUSAGE_DEPTHSTENCIL
|
||||
, D3DFMT_DF24 //s_depthFormat[depthFormat]
|
||||
, s_depthFormat[depthFormat]
|
||||
, D3DPOOL_DEFAULT
|
||||
, &m_depthTexture
|
||||
, NULL
|
||||
|
@ -1799,7 +1810,7 @@ namespace bgfx
|
|||
{
|
||||
DX_CHECK(s_renderCtx->m_device->CreateDepthStencilSurface(m_width
|
||||
, m_height
|
||||
, s_depthFormat[depthFormat] // s_renderCtx->m_fmtDepth
|
||||
, s_depthFormat[depthFormat]
|
||||
, m_msaa.m_type
|
||||
, m_msaa.m_quality
|
||||
, FALSE
|
||||
|
@ -2883,7 +2894,7 @@ namespace bgfx
|
|||
|
||||
tvm.clear();
|
||||
uint16_t pos = 0;
|
||||
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
|
||||
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " ");
|
||||
|
||||
const D3DADAPTER_IDENTIFIER9& identifier = s_renderCtx->m_identifier;
|
||||
tvm.printf(0, pos++, 0x0f, " Device: %s (%s)", identifier.Description, identifier.Driver);
|
||||
|
|
|
@ -157,10 +157,23 @@ namespace bgfx
|
|||
{ GL_R32F, GL_FLOAT, 32 },
|
||||
};
|
||||
|
||||
static const GLenum s_depthFormat[] =
|
||||
struct RenderTargetDepthFormat
|
||||
{
|
||||
0, // ignored
|
||||
0,
|
||||
GLenum m_internalFmt;
|
||||
GLenum m_attachment;
|
||||
};
|
||||
|
||||
static const RenderTargetDepthFormat s_depthFormat[] =
|
||||
{
|
||||
{ 0, 0 }, // ignored
|
||||
{ GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT }, // D16
|
||||
{ GL_DEPTH_COMPONENT24, GL_DEPTH_ATTACHMENT }, // D24
|
||||
{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL_ATTACHMENT }, // D24S8
|
||||
{ GL_DEPTH_COMPONENT32, GL_DEPTH_ATTACHMENT }, // D32
|
||||
{ GL_DEPTH_COMPONENT32F, GL_DEPTH_ATTACHMENT }, // D16F
|
||||
{ GL_DEPTH_COMPONENT32F, GL_DEPTH_ATTACHMENT }, // D24F
|
||||
{ GL_DEPTH_COMPONENT32F, GL_DEPTH_ATTACHMENT }, // D32F
|
||||
{ GL_STENCIL_INDEX8, GL_STENCIL_ATTACHMENT }, // D0S8
|
||||
};
|
||||
|
||||
static const GLenum s_textureAddress[] =
|
||||
|
@ -278,9 +291,12 @@ namespace bgfx
|
|||
NVX_gpu_memory_info,
|
||||
OES_compressed_ETC1_RGB8_texture,
|
||||
OES_depth24,
|
||||
OES_depth32,
|
||||
OES_depth_texture,
|
||||
OES_fragment_precision_high,
|
||||
OES_get_program_binary,
|
||||
OES_required_internalformat,
|
||||
OES_packed_depth_stencil,
|
||||
OES_read_format,
|
||||
OES_rgb8_rgba8,
|
||||
OES_standard_derivatives,
|
||||
|
@ -358,9 +374,12 @@ namespace bgfx
|
|||
{ "GL_NVX_gpu_memory_info", false, true },
|
||||
{ "GL_OES_compressed_ETC1_RGB8_texture", false, true },
|
||||
{ "GL_OES_depth24", false, true },
|
||||
{ "GL_OES_depth32", false, true },
|
||||
{ "GL_OES_depth_texture", false, true },
|
||||
{ "GL_OES_fragment_precision_high", false, true },
|
||||
{ "GL_OES_get_program_binary", false, true },
|
||||
{ "GL_OES_required_internalformat", false, true },
|
||||
{ "GL_OES_packed_depth_stencil", false, true },
|
||||
{ "GL_OES_read_format", false, true },
|
||||
{ "GL_OES_rgb8_rgba8", false, true },
|
||||
{ "GL_OES_standard_derivatives", false, true },
|
||||
|
@ -1846,7 +1865,7 @@ namespace bgfx
|
|||
|| findMatch(code, "fwidth")
|
||||
);
|
||||
|
||||
bool usesFragDepth = findMatch(code, "gl_FragDepth");
|
||||
bool usesFragDepth = !!findMatch(code, "gl_FragDepth");
|
||||
|
||||
bool usesTexture3D = s_extension[Extension::OES_texture_3D].m_supported &&
|
||||
( findMatch(code, "texture3D")
|
||||
|
@ -1983,10 +2002,10 @@ namespace bgfx
|
|||
uint32_t msaa = (_flags&BGFX_RENDER_TARGET_MSAA_MASK)>>BGFX_RENDER_TARGET_MSAA_SHIFT;
|
||||
m_msaa = bx::uint32_min(s_renderCtx->m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
|
||||
|
||||
uint32_t colorFormat = (_flags&BGFX_RENDER_TARGET_COLOR_MASK)>>BGFX_RENDER_TARGET_COLOR_SHIFT;
|
||||
uint32_t depthFormat = (_flags&BGFX_RENDER_TARGET_DEPTH_MASK)>>BGFX_RENDER_TARGET_DEPTH_SHIFT;
|
||||
GLenum minFilter = s_textureFilterMin[(_textureFlags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT][0];
|
||||
GLenum magFilter = s_textureFilterMag[(_textureFlags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT];
|
||||
const uint32_t colorFormat = (_flags&BGFX_RENDER_TARGET_COLOR_MASK)>>BGFX_RENDER_TARGET_COLOR_SHIFT;
|
||||
const uint32_t depthFormat = (_flags&BGFX_RENDER_TARGET_DEPTH_MASK)>>BGFX_RENDER_TARGET_DEPTH_SHIFT;
|
||||
const GLenum minFilter = s_textureFilterMin[(_textureFlags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT][0];
|
||||
const GLenum magFilter = s_textureFilterMag[(_textureFlags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT];
|
||||
|
||||
if (0 < colorFormat)
|
||||
{
|
||||
|
@ -2049,16 +2068,13 @@ namespace bgfx
|
|||
|
||||
if (0 < colorFormat)
|
||||
{
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
GLenum depthComponent = GL_DEPTH_COMPONENT32;
|
||||
#else
|
||||
GLenum depthComponent = GL_DEPTH_COMPONENT16;
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
||||
GL_CHECK(glGenRenderbuffers(1, &m_depthRbo) );
|
||||
BX_CHECK(0 != m_depthRbo, "Failed to generate renderbuffer id.");
|
||||
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthRbo) );
|
||||
|
||||
const GLenum depthComponent = s_depthFormat[depthFormat].m_internalFmt;
|
||||
const GLenum attachment = s_depthFormat[depthFormat].m_attachment;
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
if (0 != m_msaa)
|
||||
{
|
||||
|
@ -2071,11 +2087,32 @@ namespace bgfx
|
|||
}
|
||||
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0) );
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
if (GL_STENCIL_ATTACHMENT != attachment)
|
||||
{
|
||||
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
|
||||
, GL_DEPTH_ATTACHMENT
|
||||
, GL_RENDERBUFFER
|
||||
, m_depthRbo
|
||||
) );
|
||||
}
|
||||
|
||||
if (GL_DEPTH_STENCIL_ATTACHMENT == attachment
|
||||
|| GL_STENCIL_ATTACHMENT == attachment)
|
||||
{
|
||||
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
|
||||
, GL_STENCIL_ATTACHMENT
|
||||
, GL_RENDERBUFFER
|
||||
, m_depthRbo
|
||||
) );
|
||||
}
|
||||
#else
|
||||
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
|
||||
, GL_DEPTH_ATTACHMENT
|
||||
, attachment
|
||||
, GL_RENDERBUFFER
|
||||
, m_depthRbo
|
||||
) );
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -3743,7 +3780,7 @@ namespace bgfx
|
|||
|
||||
tvm.clear();
|
||||
uint16_t pos = 0;
|
||||
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
|
||||
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " ");
|
||||
tvm.printf(0, pos++, 0x0f, " Vendor: %s", s_renderCtx->m_vendor);
|
||||
tvm.printf(0, pos++, 0x0f, " Renderer: %s", s_renderCtx->m_renderer);
|
||||
tvm.printf(0, pos++, 0x0f, " Version: %s", s_renderCtx->m_version);
|
||||
|
|
|
@ -96,6 +96,10 @@ typedef void (GL_APIENTRYP PFLGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLu
|
|||
# define GL_TEXTURE_WRAP_R GL_TEXTURE_WRAP_R_OES
|
||||
# define GL_MIN GL_MIN_EXT
|
||||
# define GL_MAX GL_MAX_EXT
|
||||
# define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
|
||||
# define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
|
||||
# define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES
|
||||
# define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES
|
||||
# elif BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
# include <GLES3/gl3platform.h>
|
||||
# include <GLES3/gl3.h>
|
||||
|
@ -136,6 +140,14 @@ typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei b
|
|||
# define GL_RGB10_A2_EXT 0x8059
|
||||
#endif // GL_RGB10_A2_EXT
|
||||
|
||||
#ifndef GL_RGBA16
|
||||
# define GL_RGBA16 0x805B
|
||||
#endif // GL_RGBA16
|
||||
|
||||
#ifndef GL_RGBA16F
|
||||
# define GL_RGBA16F 0x881A
|
||||
#endif // GL_RGBA16F
|
||||
|
||||
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
|
||||
# define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#endif // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
|
||||
|
@ -253,13 +265,17 @@ typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei b
|
|||
# define GL_UNPACK_ROW_LENGTH 0x0CF2
|
||||
#endif // GL_UNPACK_ROW_LENGTH
|
||||
|
||||
#ifndef GL_RGBA16
|
||||
# define GL_RGBA16 0x805B
|
||||
#endif // GL_RGBA16
|
||||
#ifndef GL_DEPTH_COMPONENT32
|
||||
# define GL_DEPTH_COMPONENT32 0x81A7
|
||||
#endif // GL_DEPTH_COMPONENT32
|
||||
|
||||
#ifndef GL_RGBA16F
|
||||
# define GL_RGBA16F 0x881A
|
||||
#endif // GL_RGBA16F
|
||||
#ifndef GL_DEPTH_COMPONENT32F
|
||||
# define GL_DEPTH_COMPONENT32F 0x8CAC
|
||||
#endif // GL_DEPTH_COMPONENT32F
|
||||
|
||||
#ifndef GL_DEPTH_STENCIL_ATTACHMENT
|
||||
# define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
|
||||
#endif // GL_DEPTH_STENCIL_ATTACHMENT
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
# include "glcontext_ppapi.h"
|
||||
|
|
Loading…
Reference in a new issue