mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
fix cache reset (#3177)
This commit is contained in:
@@ -32,17 +32,16 @@ THE SOFTWARE.
|
||||
#include "cocos/bindings/event/EventDispatcher.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace cc {
|
||||
namespace gfx {
|
||||
|
||||
#if CC_DEBUG > 0
|
||||
|
||||
void GL_APIENTRY GLES2EGLDebugProc(GLenum source,
|
||||
GLenum type, GLuint id,
|
||||
GLenum severity, GLsizei length,
|
||||
const GLchar *message,
|
||||
const void *userParam) {
|
||||
GLenum type, GLuint id,
|
||||
GLenum severity, GLsizei length,
|
||||
const GLchar *message,
|
||||
const void *userParam) {
|
||||
String sourceDesc;
|
||||
switch (source) {
|
||||
case GL_DEBUG_SOURCE_API_KHR: sourceDesc = "API"; break;
|
||||
@@ -262,7 +261,7 @@ bool GLES2Context::initialize(const ContextInfo &info) {
|
||||
|
||||
_eglSharedContext = _eglContext;
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [=](const CustomEvent &) -> void {
|
||||
if (_eglSurface != EGL_NO_SURFACE) {
|
||||
eglDestroySurface(_eglDisplay, _eglSurface);
|
||||
@@ -288,9 +287,9 @@ bool GLES2Context::initialize(const ContextInfo &info) {
|
||||
return;
|
||||
}
|
||||
|
||||
((GLES2Context*)_device->getContext())->MakeCurrent();
|
||||
((GLES2Context *)_device->getContext())->MakeCurrent();
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} else {
|
||||
GLES2Context *sharedCtx = (GLES2Context *)info.sharedCtx;
|
||||
@@ -344,7 +343,6 @@ bool GLES2Context::initialize(const ContextInfo &info) {
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void GLES2Context::destroy() {
|
||||
@@ -376,10 +374,9 @@ void GLES2Context::destroy() {
|
||||
bool GLES2Context::MakeCurrentImpl(bool bound) {
|
||||
bool succeeded;
|
||||
EGL_CHECK(succeeded = eglMakeCurrent(_eglDisplay,
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglContext : EGL_NO_CONTEXT
|
||||
));
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglContext : EGL_NO_CONTEXT));
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
@@ -423,49 +420,49 @@ bool GLES2Context::MakeCurrent(bool bound) {
|
||||
#endif
|
||||
|
||||
_isInitialized = true;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glActiveTexture(GL_TEXTURE0));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glEnable(GL_SCISSOR_TEST));
|
||||
GL_CHECK(glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(glCullFace(GL_BACK));
|
||||
|
||||
GL_CHECK(glFrontFace(GL_CCW));
|
||||
|
||||
//GL_CHECK(glDisable(GL_MULTISAMPLE));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// DepthStencilState
|
||||
GL_CHECK(glEnable(GL_DEPTH_TEST));
|
||||
GL_CHECK(glDepthMask(GL_TRUE));
|
||||
GL_CHECK(glDepthFunc(GL_LESS));
|
||||
|
||||
GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff));
|
||||
GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff));
|
||||
|
||||
GL_CHECK(glDisable(GL_STENCIL_TEST));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BlendState
|
||||
|
||||
GL_CHECK(glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE));
|
||||
GL_CHECK(glDisable(GL_BLEND));
|
||||
GL_CHECK(glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD));
|
||||
GL_CHECK(glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO));
|
||||
GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
|
||||
GL_CHECK(glBlendColor((GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glActiveTexture(GL_TEXTURE0));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glEnable(GL_SCISSOR_TEST));
|
||||
GL_CHECK(glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(glCullFace(GL_BACK));
|
||||
|
||||
GL_CHECK(glFrontFace(GL_CCW));
|
||||
|
||||
//GL_CHECK(glDisable(GL_MULTISAMPLE));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// DepthStencilState
|
||||
GL_CHECK(glEnable(GL_DEPTH_TEST));
|
||||
GL_CHECK(glDepthMask(GL_TRUE));
|
||||
GL_CHECK(glDepthFunc(GL_LESS));
|
||||
|
||||
GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff));
|
||||
GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff));
|
||||
|
||||
GL_CHECK(glDisable(GL_STENCIL_TEST));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BlendState
|
||||
|
||||
GL_CHECK(glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE));
|
||||
GL_CHECK(glDisable(GL_BLEND));
|
||||
GL_CHECK(glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD));
|
||||
GL_CHECK(glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO));
|
||||
GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
|
||||
GL_CHECK(glBlendColor((GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f));
|
||||
|
||||
CC_LOG_DEBUG("eglMakeCurrent() - SUCCEEDED, Context: 0x%p", this);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -222,7 +222,6 @@ void GLES2Device::bindRenderContext(bool bound) {
|
||||
|
||||
if (bound) {
|
||||
_threadID = std::hash<std::thread::id>()(std::this_thread::get_id());
|
||||
_gpuStateCache->reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,9 +238,7 @@ void GLES2Device::bindDeviceContext(bool bound) {
|
||||
_context = bound ? _deviceContext : nullptr;
|
||||
|
||||
if (bound) {
|
||||
std::hash<std::thread::id> hasher;
|
||||
_threadID = hasher(std::this_thread::get_id());
|
||||
_gpuStateCache->reset();
|
||||
_threadID = std::hash<std::thread::id>()(std::this_thread::get_id());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ bool GLES3Context::initialize(const ContextInfo &info) {
|
||||
|
||||
_eglSharedContext = _eglContext;
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [=](const CustomEvent &) -> void {
|
||||
if (_eglSurface != EGL_NO_SURFACE) {
|
||||
eglDestroySurface(_eglDisplay, _eglSurface);
|
||||
@@ -290,9 +290,9 @@ bool GLES3Context::initialize(const ContextInfo &info) {
|
||||
return;
|
||||
}
|
||||
|
||||
((GLES3Context*)_device->getContext())->MakeCurrent();
|
||||
((GLES3Context *)_device->getContext())->MakeCurrent();
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} else {
|
||||
GLES3Context *sharedCtx = (GLES3Context *)info.sharedCtx;
|
||||
@@ -376,10 +376,9 @@ void GLES3Context::destroy() {
|
||||
bool GLES3Context::MakeCurrentImpl(bool bound) {
|
||||
bool succeeded;
|
||||
EGL_CHECK(succeeded = eglMakeCurrent(_eglDisplay,
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglContext : EGL_NO_CONTEXT
|
||||
));
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglSurface : EGL_NO_SURFACE,
|
||||
bound ? _eglContext : EGL_NO_CONTEXT));
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
@@ -422,49 +421,49 @@ bool GLES3Context::MakeCurrent(bool bound) {
|
||||
#endif
|
||||
|
||||
_isInitialized = true;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glActiveTexture(GL_TEXTURE0));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glEnable(GL_SCISSOR_TEST));
|
||||
GL_CHECK(glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(glCullFace(GL_BACK));
|
||||
|
||||
GL_CHECK(glFrontFace(GL_CCW));
|
||||
|
||||
//GL_CHECK(glDisable(GL_MULTISAMPLE));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// DepthStencilState
|
||||
GL_CHECK(glEnable(GL_DEPTH_TEST));
|
||||
GL_CHECK(glDepthMask(GL_TRUE));
|
||||
GL_CHECK(glDepthFunc(GL_LESS));
|
||||
|
||||
GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff));
|
||||
GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff));
|
||||
|
||||
GL_CHECK(glDisable(GL_STENCIL_TEST));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BlendState
|
||||
|
||||
GL_CHECK(glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE));
|
||||
GL_CHECK(glDisable(GL_BLEND));
|
||||
GL_CHECK(glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD));
|
||||
GL_CHECK(glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO));
|
||||
GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
|
||||
GL_CHECK(glBlendColor((GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
|
||||
GL_CHECK(glActiveTexture(GL_TEXTURE0));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GL_CHECK(glEnable(GL_SCISSOR_TEST));
|
||||
GL_CHECK(glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(glCullFace(GL_BACK));
|
||||
|
||||
GL_CHECK(glFrontFace(GL_CCW));
|
||||
|
||||
//GL_CHECK(glDisable(GL_MULTISAMPLE));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// DepthStencilState
|
||||
GL_CHECK(glEnable(GL_DEPTH_TEST));
|
||||
GL_CHECK(glDepthMask(GL_TRUE));
|
||||
GL_CHECK(glDepthFunc(GL_LESS));
|
||||
|
||||
GL_CHECK(glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff));
|
||||
GL_CHECK(glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 1, 0xffffffff));
|
||||
GL_CHECK(glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP));
|
||||
GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff));
|
||||
|
||||
GL_CHECK(glDisable(GL_STENCIL_TEST));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BlendState
|
||||
|
||||
GL_CHECK(glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE));
|
||||
GL_CHECK(glDisable(GL_BLEND));
|
||||
GL_CHECK(glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD));
|
||||
GL_CHECK(glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO));
|
||||
GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
|
||||
GL_CHECK(glBlendColor((GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f, (GLclampf)0.0f));
|
||||
|
||||
CC_LOG_DEBUG("eglMakeCurrent() - SUCCEEDED, Context: 0x%p", this);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -212,7 +212,6 @@ void GLES3Device::bindRenderContext(bool bound) {
|
||||
|
||||
if (bound) {
|
||||
_threadID = std::hash<std::thread::id>()(std::this_thread::get_id());
|
||||
_gpuStateCache->reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,9 +228,7 @@ void GLES3Device::bindDeviceContext(bool bound) {
|
||||
_context = bound ? _deviceContext : nullptr;
|
||||
|
||||
if (bound) {
|
||||
std::hash<std::thread::id> hasher;
|
||||
_threadID = hasher(std::this_thread::get_id());
|
||||
_gpuStateCache->reset();
|
||||
_threadID = std::hash<std::thread::id>()(std::this_thread::get_id());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user