onscreen msaa from v3.0.2 to v3.1 (#3419)

* onscreen msaa from v3.0.2 to v3.1

* update external cfg
This commit is contained in:
Zeqiang Li
2021-04-17 14:05:32 +08:00
committed by GitHub
parent 74184e0eed
commit d93b3b1f4b
9 changed files with 284 additions and 76 deletions
+41 -6
View File
@@ -14638,6 +14638,33 @@ bool js_register_gfx_MemoryStatus(se::Object* obj)
se::Object* __jsb_cc_gfx_DeviceInfo_proto = nullptr;
se::Class* __jsb_cc_gfx_DeviceInfo_class = nullptr;
static bool js_gfx_DeviceInfo_get_isAntiAlias(se::State& s)
{
cc::gfx::DeviceInfo* cobj = SE_THIS_OBJECT<cc::gfx::DeviceInfo>(s);
SE_PRECONDITION2(cobj, false, "js_gfx_DeviceInfo_get_isAntiAlias : Invalid Native Object");
CC_UNUSED bool ok = true;
se::Value jsret;
ok &= nativevalue_to_se(cobj->isAntiAlias, jsret, s.thisObject() /*ctx*/);
s.rval() = jsret;
SE_HOLD_RETURN_VALUE(cobj->isAntiAlias, s.thisObject(), s.rval());
return true;
}
SE_BIND_PROP_GET(js_gfx_DeviceInfo_get_isAntiAlias)
static bool js_gfx_DeviceInfo_set_isAntiAlias(se::State& s)
{
const auto& args = s.args();
cc::gfx::DeviceInfo* cobj = SE_THIS_OBJECT<cc::gfx::DeviceInfo>(s);
SE_PRECONDITION2(cobj, false, "js_gfx_DeviceInfo_set_isAntiAlias : Invalid Native Object");
CC_UNUSED bool ok = true;
ok &= sevalue_to_native(args[0], &cobj->isAntiAlias, s.thisObject());
SE_PRECONDITION2(ok, false, "js_gfx_DeviceInfo_set_isAntiAlias : Error processing new value");
return true;
}
SE_BIND_PROP_SET(js_gfx_DeviceInfo_set_isAntiAlias)
static bool js_gfx_DeviceInfo_get_windowHandle(se::State& s)
{
cc::gfx::DeviceInfo* cobj = SE_THIS_OBJECT<cc::gfx::DeviceInfo>(s);
@@ -14813,6 +14840,10 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::DeviceInfo * to, se::Obje
}
se::Value field;
bool ok = true;
json->getProperty("isAntiAlias", &field);
if(!field.isNullOrUndefined()) {
ok &= sevalue_to_native(field, &(to->isAntiAlias), ctx);
}
json->getProperty("windowHandle", &field);
if(!field.isNullOrUndefined()) {
ok &= sevalue_to_native(field, &(to->windowHandle), ctx);
@@ -14876,22 +14907,25 @@ static bool js_gfx_DeviceInfo_constructor(se::State& s)
{
cc::gfx::DeviceInfo* cobj = JSB_ALLOC(cc::gfx::DeviceInfo);
if (argc > 0 && !args[0].isUndefined()) {
ok &= sevalue_to_native(args[0], &(cobj->windowHandle), nullptr);
ok &= sevalue_to_native(args[0], &(cobj->isAntiAlias), nullptr);
}
if (argc > 1 && !args[1].isUndefined()) {
ok &= sevalue_to_native(args[1], &(cobj->width), nullptr);
ok &= sevalue_to_native(args[1], &(cobj->windowHandle), nullptr);
}
if (argc > 2 && !args[2].isUndefined()) {
ok &= sevalue_to_native(args[2], &(cobj->height), nullptr);
ok &= sevalue_to_native(args[2], &(cobj->width), nullptr);
}
if (argc > 3 && !args[3].isUndefined()) {
ok &= sevalue_to_native(args[3], &(cobj->nativeWidth), nullptr);
ok &= sevalue_to_native(args[3], &(cobj->height), nullptr);
}
if (argc > 4 && !args[4].isUndefined()) {
ok &= sevalue_to_native(args[4], &(cobj->nativeHeight), nullptr);
ok &= sevalue_to_native(args[4], &(cobj->nativeWidth), nullptr);
}
if (argc > 5 && !args[5].isUndefined()) {
ok &= sevalue_to_native(args[5], &(cobj->bindingMappingInfo), nullptr);
ok &= sevalue_to_native(args[5], &(cobj->nativeHeight), nullptr);
}
if (argc > 6 && !args[6].isUndefined()) {
ok &= sevalue_to_native(args[6], &(cobj->bindingMappingInfo), nullptr);
}
if(!ok) {
@@ -14930,6 +14964,7 @@ bool js_register_gfx_DeviceInfo(se::Object* obj)
{
auto cls = se::Class::create("DeviceInfo", obj, nullptr, _SE(js_gfx_DeviceInfo_constructor));
cls->defineProperty("isAntiAlias", _SE(js_gfx_DeviceInfo_get_isAntiAlias), _SE(js_gfx_DeviceInfo_set_isAntiAlias));
cls->defineProperty("windowHandle", _SE(js_gfx_DeviceInfo_get_windowHandle), _SE(js_gfx_DeviceInfo_set_windowHandle));
cls->defineProperty("width", _SE(js_gfx_DeviceInfo_get_width), _SE(js_gfx_DeviceInfo_set_width));
cls->defineProperty("height", _SE(js_gfx_DeviceInfo_get_height), _SE(js_gfx_DeviceInfo_set_height));
+12 -3
View File
@@ -55,6 +55,7 @@ enum class VsyncMode {
};
struct DeviceInfo {
bool isAntiAlias = false;
uintptr_t windowHandle = 0U;
uint width = 0U;
uint height = 0U;
@@ -63,10 +64,18 @@ struct DeviceInfo {
BindingMappingInfo bindingMappingInfo;
};
enum class Performance {
HIGH_QUALITY,
LOW_POWER,
//BALANCE,
};
struct ContextInfo {
uintptr_t windowHandle = 0;
Context * sharedCtx = nullptr;
VsyncMode vsyncMode = VsyncMode::RELAXED;
bool msaaEnabled = false;
Performance performance = Performance::LOW_POWER;
VsyncMode vsyncMode = VsyncMode::RELAXED;
uintptr_t windowHandle = 0;
Context* sharedCtx = nullptr;
};
extern const DescriptorType DESCRIPTOR_BUFFER_TYPE;
@@ -146,18 +146,92 @@ bool GLES2Context::doInit(const ContextInfo &info) {
_colorFmt = Format::RGBA8;
_depthStencilFmt = Format::D24S8;
const EGLint attribs[] = {
bool msaaEnabled = info.msaaEnabled;
EGLint redSize{8}, greenSize{8}, blueSize{8}, alphaSize{8}, depthSize{24}, stencilSize{8}, sampleBufferSize{msaaEnabled ? EGL_DONT_CARE : 0}, sampleSize{msaaEnabled ? EGL_DONT_CARE : 0};
EGLint defaultAttribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
// EGL_BUFFER_SIZE, colorBuffSize,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_STENCIL_SIZE, 8,
EGL_BLUE_SIZE, blueSize,
EGL_GREEN_SIZE, greenSize,
EGL_RED_SIZE, redSize,
EGL_ALPHA_SIZE, alphaSize,
EGL_DEPTH_SIZE, depthSize,
EGL_STENCIL_SIZE, stencilSize,
EGL_SAMPLE_BUFFERS, sampleBufferSize,
EGL_SAMPLES, sampleSize,
EGL_NONE};
int numConfig = 0;
EGLConfig cfgs[128];
eglGetConfigs(_eglDisplay, cfgs, 128, &numConfig);
if (eglChooseConfig(_eglDisplay, defaultAttribs, NULL, 0, &numConfig)) {
_vecEGLConfig.resize(numConfig);
} else {
CC_LOG_ERROR("Query configuration failed.");
return false;
}
int count = numConfig;
if (eglChooseConfig(_eglDisplay, defaultAttribs, _vecEGLConfig.data(), count, &numConfig) == EGL_FALSE || !numConfig) {
CC_LOG_ERROR("eglChooseConfig configuration failed.");
return false;
}
EGLint depth{0}, stencil{0};
const uint8_t attrNums = 8;
uint64_t lastScore{0};
int params[attrNums] = {0};
const bool performancePreferred = info.performance == Performance::HIGH_QUALITY;
for (int i = 0; i < numConfig; i++) {
int depthValue{0};
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_RED_SIZE, &params[0]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_GREEN_SIZE, &params[1]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_BLUE_SIZE, &params[2]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_ALPHA_SIZE, &params[3]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_DEPTH_SIZE, &params[4]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_STENCIL_SIZE, &params[5]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_SAMPLE_BUFFERS, &params[6]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_SAMPLES, &params[7]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_DEPTH_ENCODING_NV, &depthValue);
int bNonLinearDepth = (depthValue == EGL_DEPTH_ENCODING_NONLINEAR_NV) ? 1 : 0;
/*------------------------------------------ANGLE's priority-----------------------------------------------*/
// Favor EGLConfigLists by RGB, then Depth, then Non-linear Depth, then Stencil, then Alpha
uint64_t currScore{0};
currScore |= ((uint64_t)std::min(std::max(params[6], 0), 15)) << 29;
currScore |= ((uint64_t)std::min(std::max(params[7], 0), 31)) << 24;
currScore |= std::min(std::abs(params[0] - redSize) +
std::abs(params[1] - greenSize) +
std::abs(params[2] - blueSize),
127)
<< 17;
currScore |= std::min(std::abs(params[4] - depthSize), 63) << 11;
currScore |= std::min(std::abs(1 - bNonLinearDepth), 1) << 10;
currScore |= std::min(std::abs(params[5] - stencilSize), 31) << 6;
currScore |= std::min(std::abs(params[3] - alphaSize), 31) << 0;
/*------------------------------------------ANGLE's priority-----------------------------------------------*/
// if msaaEnabled, sampleBuffers and sampleCount should be greater than 0, until iterate to the last one(can't find).
bool msaaLimit = msaaEnabled ? (params[6] > 0 && params[7] > 0) || (i == numConfig - 1) : (params[6] == 0 && params[7] == 0);
// performancePreferred ? [>=] : [<] , egl configurations store in "ascending order"
bool filter = (currScore < lastScore) ^ performancePreferred;
if ((filter || lastScore == 0) && msaaLimit) {
_eglConfig = _vecEGLConfig[i];
depth = params[4];
stencil = params[5];
_sampleBuffers = params[6];
_sampleCount = params[7];
lastScore = currScore;
}
}
// Find a suitable EGLConfig
// eglChooseConfig is provided by EGL to provide an easy way to select an appropriate configuration. It takes in the capabilities
// specified in the attribute list, and returns a list of available configurations that match or exceed the capabilities requested.
@@ -167,16 +241,7 @@ bool GLES2Context::doInit(const ContextInfo &info) {
// advanced applications choose to do. For this application however, taking the first EGLConfig that the function returns suits
// its needs perfectly, so we limit it to returning a single EGLConfig.
EGLint numConfigs;
if (eglChooseConfig(_eglDisplay, attribs, &_eglConfig, 1, &numConfigs) == EGL_FALSE ||
numConfigs <= 0) {
CC_LOG_ERROR("Choosing configuration failed.");
return false;
}
EGLint depth = attribs[13];
EGLint stencil = attribs[15];
CC_LOG_INFO("Setup EGLConfig: depth [%d] stencil [%d]", depth, stencil);
CC_LOG_INFO("Setup EGLConfig: depth [%d] stencil [%d] sampleBuffer [%d] sampleCount [%d]", depth, stencil, _sampleBuffers, _sampleCount);
if (depth == 16 && stencil == 0) {
_depthStencilFmt = Format::D16;
@@ -315,6 +380,10 @@ bool GLES2Context::doInit(const ContextInfo &info) {
void GLES2Context::doDestroy() {
EGL_CHECK(eglMakeCurrent(_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
if (!_vecEGLConfig.empty()) {
_vecEGLConfig.clear();
}
if (_eglContext != EGL_NO_CONTEXT) {
EGL_CHECK(eglDestroyContext(_eglDisplay, _eglContext));
_eglContext = EGL_NO_CONTEXT;
@@ -365,8 +434,8 @@ void GLES2Context::acquireSurface(uintptr_t windowHandle) {
}
// Device's size will be updated after recreate window (in resize event) and is incorrect for now.
auto *window = reinterpret_cast<ANativeWindow *>(_windowHandle);
uint width = ANativeWindow_getWidth(window);
uint height = ANativeWindow_getHeight(window);
uint width = ANativeWindow_getWidth(window);
uint height = ANativeWindow_getHeight(window);
ANativeWindow_setBuffersGeometry(window, width, height, nFmt);
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_windowHandle), nullptr));
@@ -425,8 +494,12 @@ bool GLES2Context::makeCurrent(bool bound) {
#if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION && CC_PLATFORM != CC_PLATFORM_MAC_IOS
GL_CHECK(glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR));
GL_CHECK(glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE));
GL_CHECK(glDebugMessageCallbackKHR(GLES2EGLDebugProc, NULL));
if (glDebugMessageControlKHR) {
GL_CHECK(glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE));
}
if (glDebugMessageCallbackKHR) {
GL_CHECK(glDebugMessageCallbackKHR(GLES2EGLDebugProc, NULL));
}
#endif
//////////////////////////////////////////////////////////////////////////
+16 -11
View File
@@ -25,6 +25,7 @@
#pragma once
#include <vector>
#include "GLES2Std.h"
#include "GLES2Wrangler.h"
#include "gfx-base/GFXContext.h"
@@ -54,9 +55,10 @@ public:
CC_INLINE EGLContext eglContext() const { return _eglContext; }
CC_INLINE EGLContext eglSharedCtx() const { return _eglSharedContext; }
#endif
CC_INLINE bool makeCurrent() { return makeCurrent(true); }
CC_INLINE int majorVer() const { return _majorVersion; }
CC_INLINE int minorVer() const { return _minorVersion; }
CC_INLINE bool makeCurrent() { return makeCurrent(true); }
CC_INLINE int majorVer() const { return _majorVersion; }
CC_INLINE int minorVer() const { return _minorVersion; }
CC_INLINE uint8_t multiSampleCount() const { return _sampleCount; }
bool makeCurrentImpl(bool bound);
@@ -72,7 +74,10 @@ protected:
bool doInit(const ContextInfo &info) override;
void doDestroy() override;
bool _isPrimaryContex = false;
bool _isPrimaryContex = false;
bool _isInitialized = false;
uint8_t _sampleBuffers = 0;
uint8_t _sampleCount = 0;
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
intptr_t _eaglContext = 0;
intptr_t _eaglSharedContext = 0;
@@ -81,17 +86,17 @@ protected:
uint _defaultColorBuffer = 0;
uint _defaultDepthStencilBuffer = 0;
#else
NativeDisplayType _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
NativeDisplayType _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
std::vector<EGLConfig> _vecEGLConfig;
#endif
int _majorVersion = 0;
int _minorVersion = 0;
StringArray _extensions;
bool _isInitialized = false;
};
} // namespace gfx
@@ -62,9 +62,11 @@ GLES2Device::~GLES2Device() {
GLES2Device::instance = nullptr;
}
bool GLES2Device::doInit(const DeviceInfo & /*info*/) {
bool GLES2Device::doInit(const DeviceInfo & info) {
ContextInfo ctxInfo;
ctxInfo.windowHandle = _windowHandle;
ctxInfo.msaaEnabled = info.isAntiAlias;
ctxInfo.performance = Performance::HIGH_QUALITY;
_renderContext = CC_NEW(GLES2Context);
if (!_renderContext->initialize(ctxInfo)) {
@@ -99,7 +101,7 @@ bool GLES2Device::doInit(const DeviceInfo & /*info*/) {
_features[static_cast<uint>(Feature::FORMAT_R11G11B10F)] = true;
_features[static_cast<uint>(Feature::FORMAT_D24S8)] = true;
_features[static_cast<uint>(Feature::MSAA)] = true;
_features[static_cast<uint>(Feature::MSAA)] = _renderContext->multiSampleCount() > 0;
if (checkExtension("GL_OES_element_index_uint")) {
_features[static_cast<uint>(Feature::ELEMENT_INDEX_UINT)] = true;
@@ -139,18 +139,95 @@ bool GLES3Context::doInit(const ContextInfo &info) {
_colorFmt = Format::RGBA8;
_depthStencilFmt = Format::D24S8;
const EGLint attribs[] = {
bool msaaEnabled = info.msaaEnabled;
EGLint redSize{8}, greenSize{8}, blueSize{8}, alphaSize{8}, depthSize{24}, stencilSize{8}, sampleBufferSize{msaaEnabled ? EGL_DONT_CARE : 0}, sampleSize{msaaEnabled ? EGL_DONT_CARE : 0};
EGLint defaultAttribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
// EGL_BUFFER_SIZE, colorBuffSize,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_STENCIL_SIZE, 8,
EGL_BLUE_SIZE, blueSize,
EGL_GREEN_SIZE, greenSize,
EGL_RED_SIZE, redSize,
EGL_ALPHA_SIZE, alphaSize,
EGL_DEPTH_SIZE, depthSize,
EGL_STENCIL_SIZE, stencilSize,
EGL_SAMPLE_BUFFERS, sampleBufferSize,
EGL_SAMPLES, sampleSize,
EGL_NONE};
int numConfig = 0;
unsigned int success = false;
do {
EGL_CHECK(success = eglChooseConfig(_eglDisplay, defaultAttribs, NULL, 0, &numConfig));
} while (0);
if (success) {
_vecEGLConfig.resize(numConfig);
} else {
CC_LOG_ERROR("Query configuration failed.");
return false;
}
int count = numConfig;
do {
EGL_CHECK(success = eglChooseConfig(_eglDisplay, defaultAttribs, _vecEGLConfig.data(), count, &numConfig));
} while (0);
if (success == EGL_FALSE || !numConfig) {
CC_LOG_ERROR("eglChooseConfig configuration failed.");
return false;
}
EGLint depth{0}, stencil{0};
const uint8_t attrNums = 8;
uint64_t lastScore{0};
int params[attrNums] = {0};
const bool performancePreferred = info.performance == Performance::HIGH_QUALITY;
for (int i = 0; i < numConfig; i++) {
int depthValue{0};
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_RED_SIZE, &params[0]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_GREEN_SIZE, &params[1]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_BLUE_SIZE, &params[2]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_ALPHA_SIZE, &params[3]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_DEPTH_SIZE, &params[4]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_STENCIL_SIZE, &params[5]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_SAMPLE_BUFFERS, &params[6]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_SAMPLES, &params[7]);
eglGetConfigAttrib(_eglDisplay, _vecEGLConfig[i], EGL_DEPTH_ENCODING_NV, &depthValue);
int bNonLinearDepth = (depthValue == EGL_DEPTH_ENCODING_NONLINEAR_NV) ? 1 : 0;
/*------------------------------------------ANGLE's priority-----------------------------------------------*/
// Favor EGLConfigLists by RGB, then Depth, then Non-linear Depth, then Stencil, then Alpha
uint64_t currScore{0};
currScore |= ((uint64_t)std::min(std::max(params[6], 0), 15)) << 29;
currScore |= ((uint64_t)std::min(std::max(params[7], 0), 31)) << 24;
currScore |= std::min(std::abs(params[0] - redSize) +
std::abs(params[1] - greenSize) +
std::abs(params[2] - blueSize),
127)
<< 17;
currScore |= std::min(std::abs(params[4] - depthSize), 63) << 11;
currScore |= std::min(std::abs(1 - bNonLinearDepth), 1) << 10;
currScore |= std::min(std::abs(params[5] - stencilSize), 31) << 6;
currScore |= std::min(std::abs(params[3] - alphaSize), 31) << 0;
/*------------------------------------------ANGLE's priority-----------------------------------------------*/
// if msaaEnabled, sampleBuffers and sampleCount should be greater than 0, until iterate to the last one(can't find).
bool msaaLimit = msaaEnabled ? (params[6] > 0 && params[7] > 0) || (i == numConfig - 1) : (params[6] == 0 && params[7] == 0);
// performancePreferred ? [>=] : [<] , egl configurations store in "ascending order"
bool filter = (currScore < lastScore) ^ performancePreferred;
if ((filter || lastScore == 0) && msaaLimit) {
_eglConfig = _vecEGLConfig[i];
depth = params[4];
stencil = params[5];
_sampleBuffers = params[6];
_sampleCount = params[7];
lastScore = currScore;
}
}
// Find a suitable EGLConfig
// eglChooseConfig is provided by EGL to provide an easy way to select an appropriate configuration. It takes in the capabilities
// specified in the attribute list, and returns a list of available configurations that match or exceed the capabilities requested.
@@ -160,15 +237,7 @@ bool GLES3Context::doInit(const ContextInfo &info) {
// advanced applications choose to do. For this application however, taking the first EGLConfig that the function returns suits
// its needs perfectly, so we limit it to returning a single EGLConfig.
EGLint numConfigs;
if (eglChooseConfig(_eglDisplay, attribs, &_eglConfig, 1, &numConfigs) == EGL_FALSE || numConfigs <= 0) {
CC_LOG_ERROR("Choosing configuration failed.");
return false;
}
EGLint depth = attribs[13];
EGLint stencil = attribs[15];
CC_LOG_INFO("Setup EGLConfig: depth [%d] stencil [%d]", depth, stencil);
CC_LOG_INFO("Setup EGLConfig: depth [%d] stencil [%d] sampleBuffer [%d] sampleCount [%d]", depth, stencil, _sampleBuffers, _sampleCount);
if (depth == 16 && stencil == 0) {
_depthStencilFmt = Format::D16;
@@ -316,6 +385,10 @@ bool GLES3Context::doInit(const ContextInfo &info) {
void GLES3Context::doDestroy() {
EGL_CHECK(eglMakeCurrent(_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
if (!_vecEGLConfig.empty()) {
_vecEGLConfig.clear();
}
if (_eglContext != EGL_NO_CONTEXT) {
EGL_CHECK(eglDestroyContext(_eglDisplay, _eglContext));
_eglContext = EGL_NO_CONTEXT;
@@ -426,8 +499,12 @@ bool GLES3Context::makeCurrent(bool bound) {
#if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION && CC_PLATFORM != CC_PLATFORM_MAC_IOS
GL_CHECK(glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR));
GL_CHECK(glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE));
GL_CHECK(glDebugMessageCallbackKHR(GLES3EGLDebugProc, NULL));
if (glDebugMessageControlKHR) {
GL_CHECK(glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE));
}
if (glDebugMessageCallbackKHR) {
GL_CHECK(glDebugMessageCallbackKHR(GLES3EGLDebugProc, NULL));
}
#endif
//////////////////////////////////////////////////////////////////////////
+16 -11
View File
@@ -25,6 +25,7 @@
#pragma once
#include <vector>
#include "GLES3Std.h"
#include "GLES3Wrangler.h"
#include "gfx-base/GFXContext.h"
@@ -54,9 +55,10 @@ public:
CC_INLINE EGLContext eglContext() const { return _eglContext; }
CC_INLINE EGLContext eglSharedCtx() const { return _eglSharedContext; }
#endif
CC_INLINE bool makeCurrent() { return makeCurrent(true); }
CC_INLINE int majorVer() const { return _majorVersion; }
CC_INLINE int minorVer() const { return _minorVersion; }
CC_INLINE bool makeCurrent() { return makeCurrent(true); }
CC_INLINE int majorVer() const { return _majorVersion; }
CC_INLINE int minorVer() const { return _minorVersion; }
CC_INLINE uint8_t multiSampleCount() const { return _sampleCount; }
void releaseSurface(uintptr_t windowHandle);
void acquireSurface(uintptr_t windowHandle);
@@ -71,7 +73,10 @@ protected:
bool doInit(const ContextInfo &info) override;
void doDestroy() override;
bool _isPrimaryContex = false;
bool _isPrimaryContex = false;
bool _isInitialized = false;
uint8_t _sampleBuffers = 0;
uint8_t _sampleCount = 0;
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
intptr_t _eaglContext = 0;
intptr_t _eaglSharedContext = 0;
@@ -80,17 +85,17 @@ protected:
uint _defaultColorBuffer = 0;
uint _defaultDepthStencilBuffer = 0;
#else
NativeDisplayType _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
NativeDisplayType _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
std::vector<EGLConfig> _vecEGLConfig;
#endif
int _majorVersion = 0;
int _minorVersion = 0;
StringArray _extensions;
bool _isInitialized = false;
};
} // namespace gfx
@@ -63,9 +63,11 @@ GLES3Device::~GLES3Device() {
GLES3Device::instance = nullptr;
}
bool GLES3Device::doInit(const DeviceInfo & /*info*/) {
bool GLES3Device::doInit(const DeviceInfo & info) {
ContextInfo ctxInfo;
ctxInfo.windowHandle = _windowHandle;
ctxInfo.msaaEnabled = info.isAntiAlias;
ctxInfo.performance = Performance::HIGH_QUALITY;
_renderContext = CC_NEW(GLES3Context);
if (!_renderContext->initialize(ctxInfo)) {
@@ -91,11 +93,11 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) {
String extStr = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
_extensions = StringUtil::split(extStr, " ");
_features[static_cast<uint>(Feature::MSAA)] = _renderContext->multiSampleCount() > 0;
_features[static_cast<uint>(Feature::TEXTURE_FLOAT)] = true;
_features[static_cast<uint>(Feature::TEXTURE_HALF_FLOAT)] = true;
_features[static_cast<uint>(Feature::FORMAT_R11G11B10F)] = true;
_features[static_cast<uint>(Feature::FORMAT_D24S8)] = true;
_features[static_cast<uint>(Feature::MSAA)] = true;
_features[static_cast<uint>(Feature::INSTANCED_ARRAYS)] = true;
_features[static_cast<uint>(Feature::MULTIPLE_RENDER_TARGETS)] = true;
_features[static_cast<uint>(Feature::BLEND_MINMAX)] = true;
+2 -2
View File
@@ -1,9 +1,9 @@
{
"version": "v3d-gfx-40",
"version": "v3d-gfx-41",
"from": {
"type": "github",
"owner": "cocos-creator",
"name": "engine-native-external",
"checkout": "v3d-gfx-40"
"checkout": "v3d-gfx-41"
}
}