Fixed noise.

This commit is contained in:
Pacemaker 2016-03-15 17:30:57 +01:00
parent 43748d5d5f
commit 34822357b4
2 changed files with 110 additions and 112 deletions

View File

@ -30,127 +30,125 @@ namespace bgfx { namespace gl
_layer.opaque = true; _layer.opaque = true;
_layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys _layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys
: [NSNumber numberWithBool:false] : [NSNumber numberWithBool:false]
, kEAGLDrawablePropertyRetainedBacking , kEAGLDrawablePropertyRetainedBacking
, kEAGLColorFormatRGBA8 , kEAGLColorFormatRGBA8
, kEAGLDrawablePropertyColorFormat , kEAGLDrawablePropertyColorFormat
, nil , nil];
];
[EAGLContext setCurrentContext:_context];
[EAGLContext setCurrentContext:_context]; GL_CHECK(glGenFramebuffers(1, &m_fbo) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) );
GL_CHECK(glGenFramebuffers(1, &m_fbo) ); GL_CHECK(glGenRenderbuffers(1, &m_colorRbo) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) );
GL_CHECK(glGenRenderbuffers(1, &m_colorRbo) ); [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_layer];
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRbo) );
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_layer]; GLint width;
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRbo) ); GLint height;
GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width) );
GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height) );
BX_TRACE("Screen size: %d x %d", width, height);
GLint width; m_width = width;
GLint height; m_height = height;
GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width) ); m_layer = _layer;
GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height) );
BX_TRACE("Screen size: %d x %d", width, height);
m_width = width; createFrameBuffers(m_width, m_height);
m_height = height;
m_layer = _layer;
createFrameBuffers(m_width, m_height);
} }
~SwapChainGL() ~SwapChainGL()
{ {
destroyFrameBuffers(); destroyFrameBuffers();
} }
void destroyFrameBuffers() void destroyFrameBuffers()
{ {
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0) );
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0) );
if (0 != m_fbo) if (0 != m_fbo)
{ {
GL_CHECK(glDeleteFramebuffers(1, &m_fbo) ); GL_CHECK(glDeleteFramebuffers(1, &m_fbo) );
m_fbo = 0; m_fbo = 0;
} }
if (0 != m_colorRbo) if (0 != m_colorRbo)
{ {
GL_CHECK(glDeleteRenderbuffers(1, &m_colorRbo) ); GL_CHECK(glDeleteRenderbuffers(1, &m_colorRbo) );
m_colorRbo = 0; m_colorRbo = 0;
} }
if (0 != m_depthStencilRbo) if (0 != m_depthStencilRbo)
{ {
GL_CHECK(glDeleteRenderbuffers(1, &m_depthStencilRbo) ); GL_CHECK(glDeleteRenderbuffers(1, &m_depthStencilRbo) );
m_depthStencilRbo = 0; m_depthStencilRbo = 0;
} }
} }
void createFrameBuffers(GLint _width, GLint _height) void createFrameBuffers(GLint _width, GLint _height)
{ {
GL_CHECK(glGenRenderbuffers(1, &m_depthStencilRbo) ); GL_CHECK(glGenRenderbuffers(1, &m_depthStencilRbo) );
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilRbo) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilRbo) );
GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, _width, _height) ); // from OES_packed_depth_stencil GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, _width, _height) ); // from OES_packed_depth_stencil
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) );
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) );
BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)
, "glCheckFramebufferStatus failed 0x%08x" , "glCheckFramebufferStatus failed 0x%08x"
, glCheckFramebufferStatus(GL_FRAMEBUFFER) , glCheckFramebufferStatus(GL_FRAMEBUFFER)
); );
makeCurrent(); makeCurrent();
GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ); GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f) );
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) );
swapBuffers(); swapBuffers();
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) );
swapBuffers(); swapBuffers();
} }
void makeCurrent() void makeCurrent()
{ {
[EAGLContext setCurrentContext:m_context]; [EAGLContext setCurrentContext:m_context];
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) );
GLint newWidth = m_layer.bounds.size.width*[UIScreen mainScreen].scale; GLint newWidth = m_layer.bounds.size.width*[UIScreen mainScreen].scale;
GLint newHeight = m_layer.bounds.size.height*[UIScreen mainScreen].scale; GLint newHeight = m_layer.bounds.size.height*[UIScreen mainScreen].scale;
resize(newWidth, newHeight); resize(newWidth, newHeight);
} }
void resize(GLint _width, GLint _height) void resize(GLint _width, GLint _height)
{ {
if(m_width == _width && m_height == _height) if(m_width == _width && m_height == _height)
{ {
return; return;
} }
destroyFrameBuffers(); destroyFrameBuffers();
m_width = _width; m_width = _width;
m_height = _height; m_height = _height;
createFrameBuffers(m_width, m_height); createFrameBuffers(m_width, m_height);
} }
void swapBuffers() void swapBuffers()
{ {
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) );
[m_context presentRenderbuffer:GL_RENDERBUFFER]; [m_context presentRenderbuffer:GL_RENDERBUFFER];
} }
EAGLContext* m_context; EAGLContext* m_context;
CAEAGLLayer *m_layer; CAEAGLLayer *m_layer;
GLuint m_fbo; GLuint m_fbo;
GLuint m_colorRbo; GLuint m_colorRbo;
GLuint m_depthStencilRbo; GLuint m_depthStencilRbo;
GLint m_width; GLint m_width;
GLint m_height; GLint m_height;
}; };
void GlContext::create(uint32_t _width, uint32_t _height) void GlContext::create(uint32_t _width, uint32_t _height)
@ -201,12 +199,12 @@ namespace bgfx { namespace gl
, glCheckFramebufferStatus(GL_FRAMEBUFFER) , glCheckFramebufferStatus(GL_FRAMEBUFFER)
); );
makeCurrent(); makeCurrent();
GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ); GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f) );
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) );
swap(NULL); swap(NULL);
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) );
swap(NULL); swap(NULL);
import(); import();
@ -306,18 +304,18 @@ namespace bgfx { namespace gl
void GlContext::swap(SwapChainGL* _swapChain) void GlContext::swap(SwapChainGL* _swapChain)
{ {
makeCurrent(_swapChain); makeCurrent(_swapChain);
if (NULL == _swapChain) if (NULL == _swapChain)
{ {
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) );
EAGLContext* context = (EAGLContext*)m_context; EAGLContext* context = (EAGLContext*)m_context;
[context presentRenderbuffer:GL_RENDERBUFFER]; [context presentRenderbuffer:GL_RENDERBUFFER];
} }
else else
{ {
_swapChain->swapBuffers(); _swapChain->swapBuffers();
} }
} }
void GlContext::makeCurrent(SwapChainGL* _swapChain) void GlContext::makeCurrent(SwapChainGL* _swapChain)
@ -328,8 +326,8 @@ namespace bgfx { namespace gl
if (NULL == _swapChain) if (NULL == _swapChain)
{ {
[EAGLContext setCurrentContext:(EAGLContext*)m_context]; [EAGLContext setCurrentContext:(EAGLContext*)m_context];
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) );
} }
else else
{ {

View File

@ -2562,15 +2562,15 @@ namespace bgfx { namespace gl
{ {
FrameBufferGL& frameBuffer = m_frameBuffers[_fbh.idx]; FrameBufferGL& frameBuffer = m_frameBuffers[_fbh.idx];
_height = frameBuffer.m_height; _height = frameBuffer.m_height;
if (UINT16_MAX != frameBuffer.m_denseIdx) if (UINT16_MAX != frameBuffer.m_denseIdx)
{ {
m_glctx.makeCurrent(frameBuffer.m_swapChain); m_glctx.makeCurrent(frameBuffer.m_swapChain);
} }
else else
{ {
m_glctx.makeCurrent(NULL); m_glctx.makeCurrent(NULL);
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) );
} }
} }
m_fbh = _fbh; m_fbh = _fbh;