summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/renderer_gl.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-04-08 15:13:38 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2015-04-08 15:13:38 +0200
commitd4a431f0ea75957702de88dd1b074bd9a22ef6d2 (patch)
tree7af8ada5b3b1b9b34eae232f03a6d9044da1ed2a /3rdparty/bgfx/src/renderer_gl.cpp
parent5a33ceba7536d45a84b0f0238c21e391f6e6abbc (diff)
latest BGFX (nw)
Diffstat (limited to '3rdparty/bgfx/src/renderer_gl.cpp')
-rw-r--r--3rdparty/bgfx/src/renderer_gl.cpp113
1 files changed, 76 insertions, 37 deletions
diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp
index c35e9c5a30f..86a0c06f287 100644
--- a/3rdparty/bgfx/src/renderer_gl.cpp
+++ b/3rdparty/bgfx/src/renderer_gl.cpp
@@ -1355,14 +1355,14 @@ namespace bgfx { namespace gl
: 0
;
- g_caps.maxTextureSize = glGet(GL_MAX_TEXTURE_SIZE);
+ g_caps.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) );
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
|| BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
|| s_extension[Extension::EXT_draw_buffers ].m_supported
|| s_extension[Extension::WEBGL_draw_buffers].m_supported)
{
- g_caps.maxFBAttachments = bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);
+ g_caps.maxFBAttachments = uint8_t(bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) );
}
m_vaoSupport = !!(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
@@ -1540,7 +1540,7 @@ namespace bgfx { namespace gl
// Init reserved part of view name.
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
{
- bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1, "%3d ", ii);
+ bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1, "%3d ", ii);
}
ovrPostReset();
@@ -1795,10 +1795,13 @@ namespace bgfx { namespace gl
void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE
{
- bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
- , _name
- , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
- );
+ if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
+ {
+ bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
+ , _name
+ , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
+ );
+ }
}
void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE
@@ -1899,10 +1902,10 @@ namespace bgfx { namespace gl
m_resolution = _resolution;
m_resolution.m_flags = flags;
- uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
- msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
- bool vsync = !!(m_resolution.m_flags&BGFX_RESET_VSYNC);
- setRenderContextSize(_resolution.m_width, _resolution.m_height, msaa, vsync);
+ setRenderContextSize(m_resolution.m_width
+ , m_resolution.m_height
+ , m_resolution.m_flags
+ );
updateCapture();
ovrPreReset();
@@ -1915,7 +1918,7 @@ namespace bgfx { namespace gl
}
}
- void setShaderUniform4f(uint8_t /*_flags*/, uint16_t _regIndex, const void* _val, uint16_t _numRegs)
+ void setShaderUniform4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
GL_CHECK(glUniform4fv(_regIndex
, _numRegs
@@ -1923,7 +1926,7 @@ namespace bgfx { namespace gl
) );
}
- void setShaderUniform4x4f(uint8_t /*_flags*/, uint16_t _regIndex, const void* _val, uint16_t _numRegs)
+ void setShaderUniform4x4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
GL_CHECK(glUniformMatrix4fv(_regIndex
, _numRegs
@@ -1932,7 +1935,7 @@ namespace bgfx { namespace gl
) );
}
- uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint8_t _discard = BGFX_CLEAR_NONE, bool _msaa = true)
+ 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
@@ -2068,7 +2071,7 @@ namespace bgfx { namespace gl
}
}
- void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _msaa = 0, bool _vsync = false)
+ void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _flags = 0)
{
if (_width != 0
|| _height != 0)
@@ -2086,9 +2089,12 @@ namespace bgfx { namespace gl
{
destroyMsaaFbo();
- m_glctx.resize(_width, _height, _vsync);
+ m_glctx.resize(_width, _height, _flags);
+
+ uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
+ msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
- createMsaaFbo(_width, _height, _msaa);
+ createMsaaFbo(_width, _height, msaa);
}
}
@@ -2629,7 +2635,7 @@ namespace bgfx { namespace gl
bool m_rtMsaa;
FrameBufferHandle m_fbh;
- uint32_t m_fbDiscard;
+ uint16_t m_fbDiscard;
Resolution m_resolution;
void* m_capture;
@@ -3056,9 +3062,9 @@ namespace bgfx { namespace gl
PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name);
if (PredefinedUniform::Count != predefined)
{
- m_predefined[m_numPredefined].m_loc = loc;
- m_predefined[m_numPredefined].m_type = predefined;
- m_predefined[m_numPredefined].m_count = num;
+ m_predefined[m_numPredefined].m_loc = loc;
+ m_predefined[m_numPredefined].m_count = uint16_t(num);
+ m_predefined[m_numPredefined].m_type = uint8_t(predefined);
m_numPredefined++;
}
else
@@ -3072,7 +3078,7 @@ namespace bgfx { namespace gl
}
UniformType::Enum type = convertGlType(gltype);
- m_constantBuffer->writeUniformHandle(type, 0, info->m_handle, num);
+ m_constantBuffer->writeUniformHandle(type, 0, info->m_handle, uint16_t(num) );
m_constantBuffer->write(loc);
BX_TRACE("store %s %d", name, info->m_handle);
}
@@ -3135,7 +3141,7 @@ namespace bgfx { namespace gl
memset(m_attributes, 0xff, sizeof(m_attributes) );
uint32_t used = 0;
- for (uint32_t ii = 0; ii < Attrib::Count; ++ii)
+ for (uint8_t ii = 0; ii < Attrib::Count; ++ii)
{
GLint loc = glGetAttribLocation(m_id, s_attribName[ii]);
if (-1 != loc)
@@ -3372,8 +3378,8 @@ namespace bgfx { namespace gl
if (imageParse(imageContainer, _mem->data, _mem->size) )
{
uint8_t numMips = imageContainer.m_numMips;
- const uint32_t startLod = bx::uint32_min(_skip, numMips-1);
- numMips -= uint8_t(startLod);
+ const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) );
+ numMips -= startLod;
const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) );
const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod);
const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod);
@@ -3450,7 +3456,7 @@ namespace bgfx { namespace gl
uint32_t height = textureHeight;
uint32_t depth = imageContainer.m_depth;
- for (uint32_t lod = 0, num = numMips; lod < num; ++lod)
+ for (uint8_t lod = 0, num = numMips; lod < num; ++lod)
{
width = bx::uint32_max(blockWidth, width);
height = bx::uint32_max(blockHeight, height);
@@ -4278,7 +4284,7 @@ namespace bgfx { namespace gl
}
}
- m_num = colorIdx;
+ m_num = uint8_t(colorIdx);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
{
@@ -4389,7 +4395,7 @@ namespace bgfx { namespace gl
}
}
- void FrameBufferGL::discard(uint8_t _flags)
+ void FrameBufferGL::discard(uint16_t _flags)
{
GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS+2];
uint32_t idx = 0;
@@ -4508,10 +4514,11 @@ namespace bgfx { namespace gl
uint32_t baseVertex = 0;
GLuint currentVao = 0;
+ bool wasCompute = false;
bool viewHasScissor = false;
Rect viewScissorRect;
viewScissorRect.clear();
- uint8_t discardFlags = BGFX_CLEAR_NONE;
+ uint16_t discardFlags = BGFX_CLEAR_NONE;
const bool blendIndependentSupported = s_extension[Extension::ARB_draw_buffers_blend].m_supported;
const bool computeSupported = (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) && s_extension[Extension::ARB_compute_shader].m_supported)
@@ -4592,18 +4599,26 @@ namespace bgfx { namespace gl
viewState.m_rect = _render->m_rect[view];
if (viewRestart)
{
- char* viewName = s_viewName[view];
- viewName[3] = eye ? 'R' : 'L';
- GL_CHECK(glInsertEventMarker(0, viewName) );
+ if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
+ {
+ char* viewName = s_viewName[view];
+ viewName[3] = ' ';
+ viewName[4] = eye ? 'R' : 'L';
+ GL_CHECK(glInsertEventMarker(0, viewName) );
+ }
viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2;
viewState.m_rect.m_width /= 2;
}
else
{
- char* viewName = s_viewName[view];
- viewName[3] = ' ';
- GL_CHECK(glInsertEventMarker(0, viewName) );
+ if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
+ {
+ char* viewName = s_viewName[view];
+ viewName[3] = ' ';
+ viewName[4] = ' ';
+ GL_CHECK(glInsertEventMarker(0, viewName) );
+ }
}
const Rect& scissorRect = _render->m_scissor[view];
@@ -4633,6 +4648,18 @@ namespace bgfx { namespace gl
if (isCompute)
{
+ if (!wasCompute)
+ {
+ wasCompute = true;
+
+ if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
+ {
+ char* viewName = s_viewName[view];
+ viewName[3] = 'C';
+ GL_CHECK(glInsertEventMarker(0, viewName) );
+ }
+ }
+
if (computeSupported)
{
const RenderCompute& compute = renderItem.compute;
@@ -4703,6 +4730,18 @@ namespace bgfx { namespace gl
continue;
}
+ if (wasCompute)
+ {
+ wasCompute = false;
+
+ if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
+ {
+ char* viewName = s_viewName[view];
+ viewName[3] = ' ';
+ GL_CHECK(glInsertEventMarker(0, viewName) );
+ }
+ }
+
const RenderDraw& draw = renderItem.draw;
const uint64_t newFlags = draw.m_flags;
@@ -4764,7 +4803,7 @@ namespace bgfx { namespace gl
GL_CHECK(glEnable(GL_STENCIL_TEST) );
uint32_t bstencil = unpackStencil(1, newStencil);
- uint32_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != unpackStencil(0, newStencil);
+ uint8_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != unpackStencil(0, newStencil);
// uint32_t bchanged = unpackStencil(1, changedStencil);
// if (BGFX_STENCIL_FUNC_RMASK_MASK & bchanged)
@@ -4773,7 +4812,7 @@ namespace bgfx { namespace gl
// GL_CHECK(glStencilMask(wmask) );
// }
- for (uint32_t ii = 0, num = frontAndBack+1; ii < num; ++ii)
+ for (uint8_t ii = 0, num = frontAndBack+1; ii < num; ++ii)
{
uint32_t stencil = unpackStencil(ii, newStencil);
uint32_t changed = unpackStencil(ii, changedStencil);