Added aditional render target color formats.

This commit is contained in:
bkaradzic 2013-03-28 22:34:59 -07:00
parent eb8ab50281
commit 365f2655b3
7 changed files with 215 additions and 181 deletions

View file

@ -478,20 +478,20 @@ int _main_(int /*_argc*/, char** /*_argv*/)
Mesh mesh;
mesh.load("meshes/bunny.bin");
bgfx::RenderTargetHandle rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA|BGFX_RENDER_TARGET_DEPTH|BGFX_RENDER_TARGET_MSAA_X8);
bgfx::RenderTargetHandle rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA8|BGFX_RENDER_TARGET_DEPTH);
bgfx::RenderTargetHandle lum[5];
lum[0] = bgfx::createRenderTarget(128, 128, BGFX_RENDER_TARGET_COLOR_RGBA);
lum[1] = bgfx::createRenderTarget( 64, 64, BGFX_RENDER_TARGET_COLOR_RGBA);
lum[2] = bgfx::createRenderTarget( 16, 16, BGFX_RENDER_TARGET_COLOR_RGBA);
lum[3] = bgfx::createRenderTarget( 4, 4, BGFX_RENDER_TARGET_COLOR_RGBA);
lum[4] = bgfx::createRenderTarget( 1, 1, BGFX_RENDER_TARGET_COLOR_RGBA);
lum[0] = bgfx::createRenderTarget(128, 128, BGFX_RENDER_TARGET_COLOR_RGBA8);
lum[1] = bgfx::createRenderTarget( 64, 64, BGFX_RENDER_TARGET_COLOR_RGBA8);
lum[2] = bgfx::createRenderTarget( 16, 16, BGFX_RENDER_TARGET_COLOR_RGBA8);
lum[3] = bgfx::createRenderTarget( 4, 4, BGFX_RENDER_TARGET_COLOR_RGBA8);
lum[4] = bgfx::createRenderTarget( 1, 1, BGFX_RENDER_TARGET_COLOR_RGBA8);
bgfx::RenderTargetHandle bright;
bright = bgfx::createRenderTarget(width/2, height/2, BGFX_RENDER_TARGET_COLOR_RGBA);
bright = bgfx::createRenderTarget(width/2, height/2, BGFX_RENDER_TARGET_COLOR_RGBA8);
bgfx::RenderTargetHandle blur;
blur = bgfx::createRenderTarget(width/8, height/8, BGFX_RENDER_TARGET_COLOR_RGBA);
blur = bgfx::createRenderTarget(width/8, height/8, BGFX_RENDER_TARGET_COLOR_RGBA8);
uint32_t oldWidth = 0;
uint32_t oldHeight = 0;
@ -508,9 +508,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::destroyRenderTarget(bright);
bgfx::destroyRenderTarget(blur);
rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA|BGFX_RENDER_TARGET_DEPTH|BGFX_RENDER_TARGET_MSAA_X8);
bright = bgfx::createRenderTarget(width/2, height/2, BGFX_RENDER_TARGET_COLOR_RGBA);
blur = bgfx::createRenderTarget(width/8, height/8, BGFX_RENDER_TARGET_COLOR_RGBA);
rt = bgfx::createRenderTarget(width, height, BGFX_RENDER_TARGET_COLOR_RGBA8|BGFX_RENDER_TARGET_DEPTH);
bright = bgfx::createRenderTarget(width/2, height/2, BGFX_RENDER_TARGET_COLOR_RGBA8);
blur = bgfx::createRenderTarget(width/8, height/8, BGFX_RENDER_TARGET_COLOR_RGBA8);
}
// This dummy draw call is here to make sure that view 0 is cleared

View file

@ -177,8 +177,12 @@
///
#define BGFX_RENDER_TARGET_NONE UINT32_C(0x00000000)
#define BGFX_RENDER_TARGET_COLOR_RGBA UINT32_C(0x00000001)
#define BGFX_RENDER_TARGET_COLOR_R32F UINT32_C(0x00000002)
#define BGFX_RENDER_TARGET_COLOR_RGBA8 UINT32_C(0x00000001)
#define BGFX_RENDER_TARGET_COLOR_RGB10A2 UINT32_C(0x00000002)
#define BGFX_RENDER_TARGET_COLOR_RGBA16 UINT32_C(0x00000003)
#define BGFX_RENDER_TARGET_COLOR_RGBA16F UINT32_C(0x00000004)
#define BGFX_RENDER_TARGET_COLOR_R16F UINT32_C(0x00000005)
#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)
@ -656,7 +660,7 @@ namespace bgfx
void destroyTexture(TextureHandle _handle);
/// Create render target.
RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags = BGFX_RENDER_TARGET_COLOR_RGBA, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags = BGFX_RENDER_TARGET_COLOR_RGBA8, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
/// Destroy render target.
void destroyRenderTarget(RenderTargetHandle _handle);

View file

@ -16,7 +16,7 @@ namespace bgfx
# include "glimports.h"
# undef GL_IMPORT
void GlContext::create(uint32_t _width, uint32_t _height)
void GlContext::create(uint32_t /*_width*/, uint32_t /*_height*/)
{
EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
EGLNativeWindowType nwt = (EGLNativeWindowType)NULL;
@ -86,7 +86,7 @@ namespace bgfx
m_context = NULL;
}
void GlContext::resize(uint32_t _width, uint32_t _height)
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/)
{
}

View file

@ -82,6 +82,10 @@ namespace bgfx
{
DXGI_FORMAT_UNKNOWN, // ignored
DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R10G10B10A2_UNORM,
DXGI_FORMAT_R16G16B16A16_UNORM,
DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R16_FLOAT,
DXGI_FORMAT_R32_FLOAT,
};

View file

@ -133,6 +133,10 @@ namespace bgfx
{
D3DFMT_UNKNOWN, // ignored
D3DFMT_A8R8G8B8,
D3DFMT_A2B10G10R10,
D3DFMT_A16B16G16R16,
D3DFMT_A16B16G16R16F,
D3DFMT_R16F,
D3DFMT_R32F,
};

View file

@ -57,6 +57,8 @@ namespace bgfx
OES_vertex_array_object,
ATI_meminfo,
NVX_gpu_memory_info,
OES_rgb8_rgba8,
EXT_texture_storage,
Count
};
@ -109,8 +111,15 @@ namespace bgfx
{ "OES_vertex_array_object", false, true },
{ "GL_ATI_meminfo", false, true },
{ "GL_NVX_gpu_memory_info", false, true },
{ "GL_OES_rgb8_rgba8", false, true },
{ "GL_EXT_texture_storage", false, true },
};
#if BGFX_CONFIG_RENDERER_OPENGLES3
# define s_vertexAttribDivisor glVertexAttribDivisor
# define s_drawArraysInstanced glDrawArraysInstanced
# define s_drawElementsInstanced glDrawElementsInstanced
#else
static void GL_APIENTRY stubVertexAttribDivisor(GLuint /*_index*/, GLuint /*_divisor*/)
{
}
@ -125,11 +134,6 @@ namespace bgfx
GL_CHECK(glDrawElements(_mode, _count, _type, _indices) );
}
#if BGFX_CONFIG_RENDERER_OPENGLES3
# define s_vertexAttribDivisor glVertexAttribDivisor
# define s_drawArraysInstanced glDrawArraysInstanced
# define s_drawElementsInstanced glDrawElementsInstanced
#else
static PFNGLVERTEXATTRIBDIVISORBGFXPROC s_vertexAttribDivisor = stubVertexAttribDivisor;
static PFNGLDRAWARRAYSINSTANCEDBGFXPROC s_drawArraysInstanced = stubDrawArraysInstanced;
static PFNGLDRAWELEMENTSINSTANCEDBGFXPROC s_drawElementsInstanced = stubDrawElementsInstanced;
@ -246,6 +250,10 @@ namespace bgfx
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
}
#else
BX_UNUSED(_width);
BX_UNUSED(_height);
BX_UNUSED(_msaa);
#endif // BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
}
@ -610,11 +618,15 @@ namespace bgfx
// Specifies the internal format of the texture.
// Must be one of the following symbolic constants:
// GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA.
static const GLenum s_colorFormat[] =
static const GLenum s_colorFormat[][2] =
{
0, // ignored
GL_RGBA,
GL_RGBA,
{ 0, 0 }, // ignored
{ GL_RGBA8, GL_UNSIGNED_BYTE },
{ GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV },
{ GL_RGBA16, GL_UNSIGNED_SHORT },
{ GL_RGBA16F, GL_HALF_FLOAT },
{ GL_R16F, GL_HALF_FLOAT },
{ GL_R32F, GL_FLOAT },
};
static const GLenum s_depthFormat[] =
@ -1418,10 +1430,10 @@ namespace bgfx
GL_CHECK(glBindTexture(m_target, 0) );
}
void Texture::createColor(uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag)
void Texture::createColor(uint32_t _colorFormat, uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag)
{
GLenum internalFormat = /*_fp ? GL_RGBA16F_ARB :*/ GL_RGBA;
GLenum type = /*_fp ? GL_HALF_FLOAT_ARB :*/ GL_UNSIGNED_BYTE;
GLenum internalFormat = s_colorFormat[_colorFormat][0];
GLenum type = s_colorFormat[_colorFormat][1];
m_target = GL_TEXTURE_2D;
GL_CHECK(glGenTextures(1, &m_id) );
@ -1488,6 +1500,9 @@ namespace bgfx
void Texture::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, const Memory* _mem)
{
BX_UNUSED(_z);
BX_UNUSED(_depth);
GL_CHECK(glBindTexture(m_target, m_id) );
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) );
@ -1604,7 +1619,7 @@ namespace bgfx
if (0 < colorFormat)
{
m_color.createColor(_width, _height, minFilter, magFilter);
m_color.createColor(colorFormat, _width, _height, minFilter, magFilter);
}
#if 0 // GLES can't create texture with depth texture format...
@ -1624,7 +1639,7 @@ namespace bgfx
GL_CHECK(glGenRenderbuffers(1, &m_colorRbo) );
BX_CHECK(0 != m_colorRbo, "Failed to generate color renderbuffer id.");
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) );
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_msaa, GL_RGBA8, _width, _height) );
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_msaa, s_colorFormat[colorFormat][0], _width, _height) );
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0) );
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER

View file

@ -74,7 +74,10 @@
# define glGenVertexArrays glGenVertexArraysOES
# define GL_PROGRAM_BINARY_LENGTH GL_PROGRAM_BINARY_LENGTH_OES
# define GL_HALF_FLOAT GL_HALF_FLOAT_OES
# define GL_RGBA8 GL_RGBA8_OES
# define GL_RGB10_A2 GL_RGB10_A2_EXT
# define GL_R16F GL_R16F_EXT
# define GL_R32F GL_R32F_EXT
# define GL_UNSIGNED_INT_2_10_10_10_REV GL_UNSIGNED_INT_2_10_10_10_REV_EXT
# define GL_SAMPLER_3D GL_SAMPLER_3D_OES
# elif BGFX_CONFIG_RENDERER_OPENGLES3
@ -105,6 +108,10 @@ typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei b
# define GL_BGRA_EXT 0x80E1
# endif // GL_BGRA_EXT
# ifndef GL_R32F_EXT
# define GL_R32F_EXT 0x822E
# endif // GL_R32F_EXT
# ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
# define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
# endif // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
@ -438,7 +445,7 @@ namespace bgfx
}
void create(const Memory* _mem, uint32_t _flags);
void createColor(uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag);
void createColor(uint32_t _colorFormat, uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag);
void createDepth(uint32_t _width, uint32_t _height);
void destroy();
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, const Memory* _mem);