Fixed creation of GLES3 textures with compute write flag.

This commit is contained in:
Branimir Karadžić 2015-04-22 15:11:45 -07:00
parent cc6649db0d
commit 0da98e8645
6 changed files with 73 additions and 38 deletions

View file

@ -206,7 +206,16 @@ namespace bgfx
void setPlatformData(const PlatformData& _pd)
{
BGFX_FATAL(NULL == s_ctx, Fatal::UnableToInitialize, "Must be set prior to initialization!");
if (NULL != s_ctx)
{
BGFX_FATAL(true
&& g_platformData.ndt == _pd.ndt
&& g_platformData.nwh == _pd.nwh
&& g_platformData.context == _pd.context
, Fatal::UnableToInitialize
, "Only backbuffer pointer can be changed after initialization!"
);
}
memcpy(&g_platformData, &_pd, sizeof(PlatformData) );
}

View file

@ -100,6 +100,13 @@ ivec2 imageSize(Texture2D _image)
return result;
}
ivec2 imageSize(Texture2D<uint> _image)
{
ivec2 result;
_image.GetDimensions(result.x, result.y);
return result;
}
ivec2 imageSize(RWTexture2D<float4> _image)
{
ivec2 result;

View file

@ -14,14 +14,6 @@
# include <bcm_host.h>
# endif // BX_PLATFORM_RPI
#ifndef EGL_CONTEXT_MAJOR_VERSION_KHR
# define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
#endif // EGL_CONTEXT_MAJOR_VERSION_KHR
#ifndef EGL_CONTEXT_MINOR_VERSION_KHR
# define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
#endif // EGL_CONTEXT_MINOR_VERSION_KHR
namespace bgfx { namespace gl
{
#if BGFX_USE_GL_DYNAMIC_LIB
@ -100,22 +92,7 @@ EGL_IMPORT
# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL
# include "glimports.h"
static const EGLint s_contextAttrs[] =
{
# if BGFX_CONFIG_RENDERER_OPENGLES >= 30
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
# if BGFX_CONFIG_RENDERER_OPENGLES >= 31
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
# else
// EGL_CONTEXT_MINOR_VERSION_KHR, 0,
# endif // BGFX_CONFIG_RENDERER_OPENGLES >= 31
# elif BGFX_CONFIG_RENDERER_OPENGLES
EGL_CONTEXT_MAJOR_VERSION_KHR, 2,
// EGL_CONTEXT_MINOR_VERSION_KHR, 0,
# endif // BGFX_CONFIG_RENDERER_
EGL_NONE
};
static EGLint s_contextAttrs[16];
struct SwapChainGL
{
@ -253,6 +230,27 @@ EGL_IMPORT
m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");
{
bx::StaticMemoryBlockWriter writer(s_contextAttrs, sizeof(s_contextAttrs) );
bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR) );
bx::write(&writer, EGLint(BGFX_CONFIG_RENDERER_OPENGLES / 10) );
bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR) );
bx::write(&writer, EGLint(BGFX_CONFIG_RENDERER_OPENGLES % 10) );
bx::write(&writer, EGLint(EGL_CONTEXT_FLAGS_KHR) );
EGLint flags = BGFX_CONFIG_DEBUG ? 0
| EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR
// | EGL_OPENGL_ES3_BIT_KHR
: 0
;
bx::write(&writer, flags);
bx::write(&writer, EGLint(EGL_NONE) );
}
m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, s_contextAttrs);
BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");

View file

@ -9,6 +9,7 @@
#if BGFX_USE_EGL
#include <EGL/egl.h>
#include <EGL/eglext.h>
namespace bgfx { namespace gl
{

View file

@ -1579,7 +1579,12 @@ BX_PRAGMA_DIAGNOSTIC_POP();
preReset();
if (NULL != m_swapChain)
if (NULL == m_swapChain)
{
// Updated backbuffer if it changed in PlatformData.
m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backbuffer;
}
else
{
if (resize)
{

View file

@ -214,8 +214,8 @@ namespace bgfx { namespace gl
{ GL_RG16F, GL_RG, GL_FLOAT, false }, // RG16F
{ GL_RG32UI, GL_RG, GL_UNSIGNED_INT, false }, // RG32
{ GL_RG32F, GL_RG, GL_FLOAT, false }, // RG32F
{ GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
{ GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8
{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
{ GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA16
{ GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F
{ GL_RGBA32UI, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32
@ -1511,14 +1511,20 @@ namespace bgfx { namespace gl
if (s_extension[Extension::ARB_debug_output].m_supported
|| s_extension[Extension::KHR_debug].m_supported)
{
GL_CHECK(glDebugMessageCallback(debugProcCb, NULL) );
GL_CHECK(glDebugMessageControl(GL_DONT_CARE
, GL_DONT_CARE
, GL_DEBUG_SEVERITY_MEDIUM
, 0
, NULL
, GL_TRUE
) );
if (NULL != glDebugMessageControl
&& NULL != glDebugMessageInsert
&& NULL != glDebugMessageCallback
&& NULL != glGetDebugMessageLog)
{
GL_CHECK(glDebugMessageCallback(debugProcCb, NULL) );
GL_CHECK(glDebugMessageControl(GL_DONT_CARE
, GL_DONT_CARE
, GL_DEBUG_SEVERITY_MEDIUM
, 0
, NULL
, GL_TRUE
) );
}
}
if (s_extension[Extension::ARB_seamless_cube_map].m_supported)
@ -3356,7 +3362,8 @@ namespace bgfx { namespace gl
m_requestedFormat = _format;
m_textureFormat = _format;
const bool bufferOnly = 0 != (m_flags&BGFX_TEXTURE_RT_BUFFER_ONLY);
const bool bufferOnly = 0 != (m_flags&BGFX_TEXTURE_RT_BUFFER_ONLY);
const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE );
if (!bufferOnly)
{
@ -3377,6 +3384,7 @@ namespace bgfx { namespace gl
const bool convert = false
|| (compressed && m_textureFormat != m_requestedFormat)
|| swizzle
|| !s_textureFormat[m_requestedFormat].m_supported
;
if (convert)
@ -3387,6 +3395,11 @@ namespace bgfx { namespace gl
m_type = tfiRgba8.m_type;
}
if (computeWrite)
{
GL_CHECK(glTexStorage2D(_target, _numMips, s_textureFormat[m_textureFormat].m_internalFmt, m_width, m_height));
}
setSamplerState(_flags);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
@ -3480,6 +3493,8 @@ namespace bgfx { namespace gl
return;
}
const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE);
target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target;
const GLenum internalFmt = s_textureFormat[m_textureFormat].m_internalFmt;
@ -3579,7 +3594,7 @@ namespace bgfx { namespace gl
);
}
}
else
else if (!computeWrite)
{
if (compressed)
{