V3 multisampling support (#18632)

* Multisampling support

* fix opengl initialization with multisampling

* fix merge conflict

* reverted default attributes
This commit is contained in:
newnon 2018-01-19 04:28:22 +03:00 committed by minggo
parent 5ddf8fb596
commit 5d006192aa
27 changed files with 68 additions and 41 deletions

View File

@ -91,7 +91,7 @@ namespace {
}
//default context attributions are set as follows
GLContextAttrs GLView::_glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs GLView::_glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
void GLView::setGLContextAttrs(GLContextAttrs& glContextAttrs)
{

View File

@ -82,6 +82,7 @@ struct GLContextAttrs
int alphaBits;
int depthBits;
int stencilBits;
int multisamplingCount;
};
NS_CC_BEGIN

View File

@ -347,9 +347,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
private int[] mConfigAttributes;
private final int EGL_OPENGL_ES2_BIT = 0x04;
private final int EGL_OPENGL_ES3_BIT = 0x40;
public Cocos2dxEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
public Cocos2dxEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize, int multisamplingCount)
{
mConfigAttributes = new int[] {redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize};
mConfigAttributes = new int[] {redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize, multisamplingCount};
}
public Cocos2dxEGLConfigChooser(int[] attributes)
{
@ -368,17 +368,34 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
EGL10.EGL_ALPHA_SIZE, mConfigAttributes[3],
EGL10.EGL_DEPTH_SIZE, mConfigAttributes[4],
EGL10.EGL_STENCIL_SIZE, mConfigAttributes[5],
EGL10.EGL_SAMPLE_BUFFERS, (mConfigAttributes[6] > 0) ? 1 : 0,
EGL10.EGL_SAMPLES, mConfigAttributes[6],
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE
},
{
// GL ES 2 with user set
// GL ES 2 with user set 16 bit depth buffer
EGL10.EGL_RED_SIZE, mConfigAttributes[0],
EGL10.EGL_GREEN_SIZE, mConfigAttributes[1],
EGL10.EGL_BLUE_SIZE, mConfigAttributes[2],
EGL10.EGL_ALPHA_SIZE, mConfigAttributes[3],
EGL10.EGL_DEPTH_SIZE, mConfigAttributes[4] >= 24 ? 16 : mConfigAttributes[4],
EGL10.EGL_STENCIL_SIZE, mConfigAttributes[5],
EGL10.EGL_SAMPLE_BUFFERS, (mConfigAttributes[6] > 0) ? 1 : 0,
EGL10.EGL_SAMPLES, mConfigAttributes[6],
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE
},
{
// GL ES 2 with user set 16 bit depth buffer without multisampling
EGL10.EGL_RED_SIZE, mConfigAttributes[0],
EGL10.EGL_GREEN_SIZE, mConfigAttributes[1],
EGL10.EGL_BLUE_SIZE, mConfigAttributes[2],
EGL10.EGL_ALPHA_SIZE, mConfigAttributes[3],
EGL10.EGL_DEPTH_SIZE, mConfigAttributes[4] >= 24 ? 16 : mConfigAttributes[4],
EGL10.EGL_STENCIL_SIZE, mConfigAttributes[5],
EGL10.EGL_SAMPLE_BUFFERS, 0,
EGL10.EGL_SAMPLES, 0,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE
},

View File

@ -114,12 +114,12 @@ JNIEXPORT jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNI
cocos2d::Application::getInstance()->initGLContextAttrs();
GLContextAttrs _glContextAttrs = GLView::getGLContextAttrs();
int tmp[6] = {_glContextAttrs.redBits, _glContextAttrs.greenBits, _glContextAttrs.blueBits,
_glContextAttrs.alphaBits, _glContextAttrs.depthBits, _glContextAttrs.stencilBits};
int tmp[7] = {_glContextAttrs.redBits, _glContextAttrs.greenBits, _glContextAttrs.blueBits,
_glContextAttrs.alphaBits, _glContextAttrs.depthBits, _glContextAttrs.stencilBits, _glContextAttrs.multisamplingCount};
jintArray glContextAttrsJava = env->NewIntArray(6);
env->SetIntArrayRegion(glContextAttrsJava, 0, 6, tmp);
jintArray glContextAttrsJava = env->NewIntArray(7);
env->SetIntArrayRegion(glContextAttrsJava, 0, 7, tmp);
return glContextAttrsJava;
}

View File

@ -288,6 +288,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
glfwWindowHint(GLFW_ALPHA_BITS,_glContextAttrs.alphaBits);
glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits);
glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits);
glfwWindowHint(GLFW_SAMPLES, _glContextAttrs.multisamplingCount);
int neededWidth = rect.size.width * _frameZoomFactor;
int neededHeight = rect.size.height * _frameZoomFactor;
@ -360,6 +362,9 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
// Enable point size by default.
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
if(_glContextAttrs.multisamplingCount > 0)
glEnable(GL_MULTISAMPLE);
// // GLFW v3.2 no longer emits "onGLFWWindowSizeFunCallback" at creation time. Force default viewport:
// setViewPortInPoints(0, 0, neededWidth, neededHeight);

View File

@ -56,6 +56,7 @@ public:
static void convertAttrs();
static void* _pixelFormat;
static int _depthFormat;
static int _multisamplingCount;
/** sets the content scale factor */
virtual bool setContentScaleFactor(float contentScaleFactor) override;

View File

@ -38,6 +38,7 @@ NS_CC_BEGIN
void* GLViewImpl::_pixelFormat = kEAGLColorFormatRGB565;
int GLViewImpl::_depthFormat = GL_DEPTH_COMPONENT16;
int GLViewImpl::_multisamplingCount = 0;
GLViewImpl* GLViewImpl::createWithEAGLView(void *eaglview)
{
@ -106,6 +107,8 @@ void GLViewImpl::convertAttrs()
{
CCASSERT(0, "Unsupported format for depth and stencil buffers. Using default");
}
_multisamplingCount = _glContextAttrs.multisamplingCount;
}
GLViewImpl::GLViewImpl()

View File

@ -40,8 +40,8 @@ AppDelegate::~AppDelegate()
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -48,8 +48,8 @@
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
multiSampling: cocos2d::GLViewImpl::_multisamling
numberOfSamples: cocos2d::GLViewImpl::_samples ];
// Enable or disable multiple touches
[eaglView setMultipleTouchEnabled:NO];

View File

@ -76,7 +76,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -44,8 +44,8 @@ AppDelegate::~AppDelegate()
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0 };
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -95,8 +95,8 @@ std::string getCurAppPath(void)
static void initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -22,7 +22,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -52,8 +52,8 @@ static AppDelegate s_sharedApplication;
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0];
multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount];
// Use RootViewController manage CCEAGLView

View File

@ -48,7 +48,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -56,8 +56,8 @@ static AppDelegate s_sharedApplication;
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
#if !defined(CC_TARGET_OS_TVOS)
[eaglView setMultipleTouchEnabled:YES];

View File

@ -69,7 +69,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -23,7 +23,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -51,8 +51,8 @@ static AppDelegate s_sharedApplication;
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
// Use RootViewController manage CCEAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];

View File

@ -21,7 +21,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -51,8 +51,8 @@ static AppDelegate s_sharedApplication;
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
#if !defined(CC_TARGET_OS_TVOS)
[eaglView setMultipleTouchEnabled:YES];

View File

@ -21,7 +21,7 @@ AppDelegate::~AppDelegate()
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -53,8 +53,8 @@ static AppDelegate s_sharedApplication;
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
// Enable or disable multiple touches
[eaglView setMultipleTouchEnabled:NO];

View File

@ -21,8 +21,8 @@ AppDelegate::~AppDelegate()
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -55,8 +55,8 @@ static AppDelegate s_sharedApplication;
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
[eaglView setMultipleTouchEnabled:YES];

View File

@ -116,8 +116,8 @@ static bool stringEndWith(const std::string& str, const std::string& needle)
static void initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}

View File

@ -88,8 +88,8 @@ std::string getCurAppPath(void)
static void initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
GLView::setGLContextAttrs(glContextAttrs);
}