From 5d0f97697ea399714266145b8c6e2d4c391f362b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 26 Mar 2018 18:23:20 +0800 Subject: [PATCH 01/10] Fixed some webgl binding issues. (#1168) * Fixes wrong conversion, lots of opengl should pass in `float` but we passed `int` value. * [ios] Initialize Application should be in firstStart: method. * Implements unpackFlipY for GL_RGBA & GL_RGB format texture. * FIxed some webgl binding issues. --- native/cocos/platform/CCGL.h | 12 + .../cocos/platform/ios/CCApplication-ios.mm | 55 ++-- .../js-bindings/manual/jsb_opengl_manual.cpp | 287 ++++++++++++------ 3 files changed, 229 insertions(+), 125 deletions(-) diff --git a/native/cocos/platform/CCGL.h b/native/cocos/platform/CCGL.h index 0dd90d846e..ee5ae2f08d 100644 --- a/native/cocos/platform/CCGL.h +++ b/native/cocos/platform/CCGL.h @@ -79,6 +79,18 @@ THE SOFTWARE. #define GL_HIGH_INT 0x8DF5 #endif +#ifndef GL_MAX_VERTEX_UNIFORM_VECTORS +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#endif + +#ifndef GL_MAX_FRAGMENT_UNIFORM_VECTORS +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#endif + +#ifndef GL_MAX_VARYING_VECTORS +#define GL_MAX_VARYING_VECTORS 0x8DFC +#endif + #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC #include "platform/mac/CCGL-mac.h" #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS diff --git a/native/cocos/platform/ios/CCApplication-ios.mm b/native/cocos/platform/ios/CCApplication-ios.mm index 46fbfa9eea..983bcd4790 100644 --- a/native/cocos/platform/ios/CCApplication-ios.mm +++ b/native/cocos/platform/ios/CCApplication-ios.mm @@ -32,6 +32,26 @@ #import "scripting/js-bindings/jswrapper/jsc/ScriptEngine.hpp" #import "scripting/js-bindings/event/EventDispatcher.h" +namespace +{ + bool setCanvasCallback(se::Object* global) + { + CGRect bounds = [UIScreen mainScreen].bounds; + float scale = [[UIScreen mainScreen] scale]; + float width = bounds.size.width * scale; + float height = bounds.size.height * scale; + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + char commandBuf[200] = {0}; + sprintf(commandBuf, "window.innerWidth = %d; window.innerHeight = %d;", + (int)(width), + (int)(height)); + se->evalString(commandBuf); + glViewport(0, 0, width, height); + glDepthMask(GL_TRUE); + return true; + } +} + @interface MainLoop : NSObject { id _displayLink; @@ -97,8 +117,15 @@ -(void) firstStart:(id) view { - if ([view isReady]) + if ([view isReady]) { + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + se->addRegisterCallback(setCanvasCallback); + + if(!_application->applicationDidFinishLaunching()) + return; + [self startMainLoop]; + } else [self performSelector:@selector(firstStart:) withObject:view afterDelay:0]; } @@ -149,26 +176,6 @@ @end -namespace -{ - bool setCanvasCallback(se::Object* global) - { - CGRect bounds = [UIScreen mainScreen].bounds; - float scale = [[UIScreen mainScreen] scale]; - float width = bounds.size.width * scale; - float height = bounds.size.height * scale; - se::ScriptEngine* se = se::ScriptEngine::getInstance(); - char commandBuf[200] = {0}; - sprintf(commandBuf, "window.innerWidth = %d; window.innerHeight = %d;", - (int)(width), - (int)(height)); - se->evalString(commandBuf); - glViewport(0, 0, width, height); - glDepthMask(GL_TRUE); - return true; - } -} - NS_CC_BEGIN Application* Application::_instance = nullptr; @@ -210,12 +217,6 @@ Application::~Application() void Application::start() { - se::ScriptEngine* se = se::ScriptEngine::getInstance(); - se->addRegisterCallback(setCanvasCallback); - - if(!applicationDidFinishLaunching()) - return; - if (_delegate) [(MainLoop*)_delegate performSelector:@selector(firstStart:) withObject:(CCEAGLView*)_view afterDelay:0]; } diff --git a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp index 63ea18f0e6..c9eb671414 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp @@ -34,8 +34,47 @@ namespace { + bool __unpackFlipY = false; + bool __premultiplyAlpha = false; + GLint __defaultFbo = 0; + //FIXME:cjh: ONLY SUPPORT RGBA format now. + void flipPixelsY(GLubyte *pixels, int bytesPerRow, int rows) + { + if( !pixels ) { return; } + + GLuint middle = rows/2; + GLuint intsPerRow = bytesPerRow / sizeof(GLuint); + GLuint remainingBytes = bytesPerRow - intsPerRow * sizeof(GLuint); + + for( GLuint rowTop = 0, rowBottom = rows-1; rowTop < middle; rowTop++, rowBottom-- ) { + + // Swap bytes in packs of sizeof(GLuint) bytes + GLuint *iTop = (GLuint *)(pixels + rowTop * bytesPerRow); + GLuint *iBottom = (GLuint *)(pixels + rowBottom * bytesPerRow); + + GLuint itmp; + GLint n = intsPerRow; + do { + itmp = *iTop; + *iTop++ = *iBottom; + *iBottom++ = itmp; + } while(--n > 0); + + // Swap the remaining bytes + GLubyte *bTop = (GLubyte *)iTop; + GLubyte *bBottom = (GLubyte *)iBottom; + + GLubyte btmp; + switch( remainingBytes ) { + case 3: btmp = *bTop; *bTop++ = *bBottom; *bBottom++ = btmp; + case 2: btmp = *bTop; *bTop++ = *bBottom; *bBottom++ = btmp; + case 1: btmp = *bTop; *bTop = *bBottom; *bBottom = btmp; + } + } + } + template class GLData { @@ -345,12 +384,12 @@ static bool JSB_glBlendColor(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 4, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; + float arg0; float arg1; float arg2; float arg3; - ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); + ok &= seval_to_float(args[0], &arg0 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); + ok &= seval_to_float(args[3], &arg3 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glBlendColor((GLclampf)arg0 , (GLclampf)arg1 , (GLclampf)arg2 , (GLclampf)arg3 )); @@ -541,12 +580,12 @@ static bool JSB_glClearColor(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 4, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; + float arg0; float arg1; float arg2; float arg3; - ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); + ok &= seval_to_float(args[0], &arg0 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); + ok &= seval_to_float(args[3], &arg3 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glClearColor((GLclampf)arg0 , (GLclampf)arg1 , (GLclampf)arg2 , (GLclampf)arg3 )); @@ -562,9 +601,9 @@ static bool JSB_glClearDepthf(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 1, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; + float arg0; - ok &= seval_to_int32(args[0], &arg0 ); + ok &= seval_to_float(args[0], &arg0 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glClearDepthf((GLclampf)arg0 )); @@ -863,10 +902,10 @@ static bool JSB_glDepthRangef(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 2, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; + float arg0; float arg1; - ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); + ok &= seval_to_float(args[0], &arg0 ); + ok &= seval_to_float(args[1], &arg1 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glDepthRangef((GLclampf)arg0 , (GLclampf)arg1 )); @@ -1337,9 +1376,9 @@ static bool JSB_glLineWidth(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 1, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; + float arg0; - ok &= seval_to_int32(args[0], &arg0 ); + ok &= seval_to_float(args[0], &arg0 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glLineWidth((GLfloat)arg0 )); @@ -1381,13 +1420,14 @@ static bool JSB_glPixelStorei(se::State& s) { if (arg0 == GL_UNPACK_FLIP_Y_WEBGL) { - SE_LOGE("cjh FIXME: support GL_UNPACK_FLIP_Y_WEBGL\n"); + __unpackFlipY = arg1 == 0 ? false : true; + SE_LOGE("cjh FIXME: support GL_UNPACK_FLIP_Y_WEBGL: %d\n", arg1); return true; } if (arg0 == GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL) { - SE_LOGE("cjh FIXME: support GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL\n"); + SE_LOGE("cjh FIXME: support GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: %d\n", arg1); return true; } @@ -1404,10 +1444,10 @@ static bool JSB_glPolygonOffset(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 2, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; + float arg0; float arg1; - ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); + ok &= seval_to_float(args[0], &arg0 ); + ok &= seval_to_float(args[1], &arg1 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glPolygonOffset((GLfloat)arg0 , (GLfloat)arg1 )); @@ -1481,9 +1521,9 @@ static bool JSB_glSampleCoverage(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 2, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; uint16_t arg1; + float arg0; uint16_t arg1; - ok &= seval_to_int32(args[0], &arg0 ); + ok &= seval_to_float(args[0], &arg0 ); ok &= seval_to_uint16(args[1], &arg1 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); @@ -1640,21 +1680,39 @@ static bool JSB_glTexImage2D(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 9, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; uint32_t arg6; uint32_t arg7; void* arg8; - ok &= seval_to_uint32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); - ok &= seval_to_int32(args[4], &arg4 ); - ok &= seval_to_int32(args[5], &arg5 ); - ok &= seval_to_uint32(args[6], &arg6 ); - ok &= seval_to_uint32(args[7], &arg7 ); + uint32_t target; int32_t level; int32_t internalformat; int32_t width; int32_t height; int32_t border; uint32_t format; uint32_t type; void* pixels; + + ok &= seval_to_uint32(args[0], &target ); + ok &= seval_to_int32(args[1], &level ); + ok &= seval_to_int32(args[2], &internalformat ); + ok &= seval_to_int32(args[3], &width ); + ok &= seval_to_int32(args[4], &height ); + ok &= seval_to_int32(args[5], &border ); + ok &= seval_to_uint32(args[6], &format ); + ok &= seval_to_uint32(args[7], &type ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr(args[8], &count, &arg8); + ok &= JSB_get_arraybufferview_dataptr(args[8], &count, &pixels); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glTexImage2D((GLenum)arg0 , (GLint)arg1 , (GLint)arg2 , (GLsizei)arg3 , (GLsizei)arg4 , (GLint)arg5 , (GLenum)arg6 , (GLenum)arg7 , (GLvoid*)arg8 )); + if (__unpackFlipY) + { + if (format == GL_RGBA) + { + flipPixelsY((GLubyte*)pixels, width * 4, height); + } + else if (format == GL_RGB) + { + flipPixelsY((GLubyte*)pixels, width * 3, height); + } + else + { + SE_LOGE("JSB_glTexImage2D: format: %d doesn't support upackFlipY!\n", format); + return false; + } + } + + JSB_GL_CHECK(glTexImage2D((GLenum)target , (GLint)level , (GLint)internalformat , (GLsizei)width , (GLsizei)height , (GLint)border , (GLenum)format , (GLenum)type , (GLvoid*)pixels)); s.rval().setUndefined(); return true; } @@ -1667,11 +1725,11 @@ static bool JSB_glTexParameterf(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 3, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; uint32_t arg1; int32_t arg2; + uint32_t arg0; uint32_t arg1; float arg2; ok &= seval_to_uint32(args[0], &arg0 ); ok &= seval_to_uint32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); + ok &= seval_to_float(args[2], &arg2 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glTexParameterf((GLenum)arg0 , (GLenum)arg1 , (GLfloat)arg2 )); @@ -1707,21 +1765,38 @@ static bool JSB_glTexSubImage2D(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 9, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; int32_t arg5; uint32_t arg6; uint32_t arg7; void* arg8; + uint32_t target; int32_t level; int32_t xoffset; int32_t yoffset; int32_t width; int32_t height; uint32_t format; uint32_t type; void* pixels; - ok &= seval_to_uint32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); - ok &= seval_to_int32(args[4], &arg4 ); - ok &= seval_to_int32(args[5], &arg5 ); - ok &= seval_to_uint32(args[6], &arg6 ); - ok &= seval_to_uint32(args[7], &arg7 ); + ok &= seval_to_uint32(args[0], &target ); + ok &= seval_to_int32(args[1], &level ); + ok &= seval_to_int32(args[2], &xoffset ); + ok &= seval_to_int32(args[3], &yoffset ); + ok &= seval_to_int32(args[4], &width ); + ok &= seval_to_int32(args[5], &height ); + ok &= seval_to_uint32(args[6], &format ); + ok &= seval_to_uint32(args[7], &type ); GLsizei count; - ok &= JSB_get_arraybufferview_dataptr(args[8], &count, &arg8); + ok &= JSB_get_arraybufferview_dataptr(args[8], &count, &pixels); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glTexSubImage2D((GLenum)arg0 , (GLint)arg1 , (GLint)arg2 , (GLint)arg3 , (GLsizei)arg4 , (GLsizei)arg5 , (GLenum)arg6 , (GLenum)arg7 , (GLvoid*)arg8 )); + if (__unpackFlipY) + { + if (format == GL_RGBA) + { + flipPixelsY((GLubyte*)pixels, width * 4, height); + } + else if (format == GL_RGB) + { + flipPixelsY((GLubyte*)pixels, width * 3, height); + } + else + { + SE_LOGE("JSB_glTexImage2D: format: %d doesn't support upackFlipY!\n", format); + return false; + } + } + + JSB_GL_CHECK(glTexSubImage2D((GLenum)target , (GLint)level , (GLint)xoffset , (GLint)yoffset , (GLsizei)width , (GLsizei)height , (GLenum)format , (GLenum)type , (GLvoid*)pixels)); s.rval().setUndefined(); return true; } @@ -1734,13 +1809,13 @@ static bool JSB_glUniform1f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 2, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; + int32_t arg0; float arg1; ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); + ok &= seval_to_float(args[1], &arg1 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glUniform1f((GLint)arg0 , (GLfloat)arg1 )); + JSB_GL_CHECK(glUniform1f(arg0, arg1)); s.rval().setUndefined(); return true; } @@ -1812,14 +1887,14 @@ static bool JSB_glUniform2f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 3, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; int32_t arg2; + int32_t arg0; float arg1; float arg2; ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glUniform2f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 )); + JSB_GL_CHECK(glUniform2f(arg0 , arg1 , arg2)); s.rval().setUndefined(); return true; } @@ -1892,15 +1967,15 @@ static bool JSB_glUniform3f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 4, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; + GLint arg0; float arg1; float arg2; float arg3; ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); + ok &= seval_to_float(args[3], &arg3 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glUniform3f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 )); + JSB_GL_CHECK(glUniform3f(arg0 , arg1 , arg2 , arg3)); s.rval().setUndefined(); return true; } @@ -1974,16 +2049,16 @@ static bool JSB_glUniform4f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 5, false, "Invalid number of arguments" ); bool ok = true; - int32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; + int32_t arg0; float arg1; float arg2; float arg3; float arg4; ok &= seval_to_int32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); - ok &= seval_to_int32(args[4], &arg4 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); + ok &= seval_to_float(args[3], &arg3 ); + ok &= seval_to_float(args[4], &arg4 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glUniform4f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 , (GLfloat)arg4 )); + JSB_GL_CHECK(glUniform4f((GLint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 , (GLfloat)arg4)); s.rval().setUndefined(); return true; } @@ -2157,10 +2232,10 @@ static bool JSB_glVertexAttrib1f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 2, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; int32_t arg1; + uint32_t arg0; float arg1; ok &= seval_to_uint32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); + ok &= seval_to_float(args[1], &arg1 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glVertexAttrib1f((GLuint)arg0 , (GLfloat)arg1 )); @@ -2196,11 +2271,11 @@ static bool JSB_glVertexAttrib2f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 3, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; int32_t arg1; int32_t arg2; + uint32_t arg0; float arg1; float arg2; ok &= seval_to_uint32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glVertexAttrib2f((GLuint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 )); @@ -2236,12 +2311,12 @@ static bool JSB_glVertexAttrib3f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 4, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; + uint32_t arg0; float arg1; float arg2; float arg3; ok &= seval_to_uint32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); + ok &= seval_to_float(args[3], &arg3 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glVertexAttrib3f((GLuint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 )); @@ -2277,13 +2352,13 @@ static bool JSB_glVertexAttrib4f(se::State& s) { int argc = (int)args.size(); SE_PRECONDITION2( argc == 5, false, "Invalid number of arguments" ); bool ok = true; - uint32_t arg0; int32_t arg1; int32_t arg2; int32_t arg3; int32_t arg4; + uint32_t arg0; float arg1; float arg2; float arg3; float arg4; ok &= seval_to_uint32(args[0], &arg0 ); - ok &= seval_to_int32(args[1], &arg1 ); - ok &= seval_to_int32(args[2], &arg2 ); - ok &= seval_to_int32(args[3], &arg3 ); - ok &= seval_to_int32(args[4], &arg4 ); + ok &= seval_to_float(args[1], &arg1 ); + ok &= seval_to_float(args[2], &arg2 ); + ok &= seval_to_float(args[3], &arg3 ); + ok &= seval_to_float(args[4], &arg4 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); JSB_GL_CHECK(glVertexAttrib4f((GLuint)arg0 , (GLfloat)arg1 , (GLfloat)arg2 , (GLfloat)arg3 , (GLfloat)arg4 )); @@ -2495,7 +2570,7 @@ static bool JSB_glShaderSource(se::State& s) { SE_PRECONDITION2(ok, false, "Error processing arguments"); #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - shaderSource = std::regex_replace(shaderSource, std::regex("precision\\s+(lowp|mediump|highp)\\s+float\\s*?;"), ""); + shaderSource = std::regex_replace(shaderSource, std::regex("precision\\s+(lowp|mediump|highp).*?;"), ""); shaderSource = std::regex_replace(shaderSource, std::regex("\\s(lowp|mediump|highp)\\s"), " "); #endif @@ -2911,10 +2986,6 @@ static bool JSB_glGetUniformfv(se::State& s) { } SE_BIND_FUNC(JSB_glGetUniformfv) -#ifndef GL_MAX_FRAGMENT_UNIFORM_VECTORS -#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8dfd -#endif - static bool JSB_glGetParameter(se::State& s) { const auto& args = s.args(); @@ -2945,6 +3016,28 @@ static bool JSB_glGetParameter(se::State& s) #else GL_CHECK(glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, intbuffer)); s.rval().setInt32(intbuffer[0]); +#endif + } + break; + case GL_MAX_VERTEX_UNIFORM_VECTORS: + { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + GL_CHECK(glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, intbuffer)); + s.rval().setInt32(intbuffer[0] / 4); +#else + GL_CHECK(glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, intbuffer)); + s.rval().setInt32(intbuffer[0]); +#endif + } + break; + case GL_MAX_VARYING_VECTORS: + { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +// GL_CHECK(glGetIntegerv(GL_MAX_VARYING_COMPONENTS, intbuffer)); + s.rval().setInt32(8);//FIXME:cjh: intbuffer[0] / 4); +#else + GL_CHECK(glGetIntegerv(GL_MAX_VARYING_VECTORS, intbuffer)); + s.rval().setInt32(intbuffer[0]); #endif } break; @@ -3007,10 +3100,11 @@ static bool JSB_glGetParameter(se::State& s) } break; - // WebGLBuffer + //FIXME:cjh: WebGLBuffer case GL_ARRAY_BUFFER_BINDING: case GL_ELEMENT_ARRAY_BUFFER_BINDING: - // JSB_GL_CHECK(glGetIntegerv(pname, intbuffer)); +// JSB_GL_CHECK(glGetIntegerv(pname, intbuffer)); +// ret.setInt32(intbuffer[0]); // ret = [buffers[@(intbuffer[0])] pointerValue]; break; @@ -3039,19 +3133,12 @@ static bool JSB_glGetParameter(se::State& s) // ret = [textures[@(intbuffer[0])] pointerValue]; break; - // Ejecta/WebGL specific - case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: - // device may support more, but we only map 8 here - // ret = JSValueMakeNumber(ctx, EJ_CANVAS_MAX_TEXTURE_UNITS); - break; - case GL_UNPACK_FLIP_Y_WEBGL: - // ret = JSValueMakeBoolean(ctx, unpackFlipY); + ret.setBoolean(__unpackFlipY); break; case GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: - SE_LOGD("GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: ...\n"); - // ret = JSValueMakeBoolean(ctx, premultiplyAlpha); + ret.setBoolean(__premultiplyAlpha); break; case GL_UNPACK_COLORSPACE_CONVERSION_WEBGL: @@ -3075,9 +3162,13 @@ static bool JSB_glGetParameter(se::State& s) JSB_GL_CHECK(glGetFloatv(pname, &floatvalue)); ret.setFloat(floatvalue); break; - + case GL_MAX_TEXTURE_IMAGE_UNITS: + JSB_GL_CHECK(glGetIntegerv(pname, intbuffer)); + ret.setInt32(intbuffer[0]); + break; // single int/long/bool - everything else default: + SE_LOGD("glGetIntegerv: pname: 0x%x\n", pname); JSB_GL_CHECK(glGetIntegerv(pname, intbuffer)); ret.setInt32(intbuffer[0]); break; @@ -3197,7 +3288,7 @@ bool JSB_register_opengl(se::Object* obj) __glObj->defineFunction("enableVertexAttribArray", _SE(JSB_glEnableVertexAttribArray)); __glObj->defineFunction("finish", _SE(JSB_glFinish)); __glObj->defineFunction("flush", _SE(JSB_glFlush)); - __glObj->defineFunction("framebufferRenderbuffer", _SE(JSB_glFramebufferRenderbuffer)); + __glObj->defineFunction("_framebufferRenderbuffer", _SE(JSB_glFramebufferRenderbuffer)); __glObj->defineFunction("_framebufferTexture2D", _SE(JSB_glFramebufferTexture2D)); __glObj->defineFunction("frontFace", _SE(JSB_glFrontFace)); __glObj->defineFunction("_createBuffer", _SE(JSB_glGenBuffers)); From deda8af50a21b7f319ff00e733bd02782597b43a Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 27 Mar 2018 15:38:47 +0800 Subject: [PATCH 02/10] premultiply alpha works. (#1169) * premultiply alpha works. * GL_UNPACK_COLORSPACE_CONVERSION_WEBGL isn't supported. --- .../js-bindings/manual/jsb_opengl_manual.cpp | 113 +++++++++++++++++- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp index c9eb671414..88464d87e5 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp @@ -75,6 +75,93 @@ namespace { } } + // Lookup tables for fast [un]premultiplied alpha color values + // From https://bugzilla.mozilla.org/show_bug.cgi?id=662130 + + GLubyte* __premultiplyTable = nullptr; + GLubyte* __unPremultiplyTable = nullptr; + + const GLubyte* premultiplyTable() + { + if( !__premultiplyTable ) { + __premultiplyTable = (GLubyte*)malloc(256*256); + + unsigned char *data = __premultiplyTable; + for( int a = 0; a <= 255; a++ ) { + for( int c = 0; c <= 255; c++ ) { + data[a*256+c] = (a * c + 254) / 255; + } + } + } + + return __premultiplyTable; + } + + const GLubyte* unPremultiplyTable() + { + if( !__unPremultiplyTable ) { + __unPremultiplyTable = (GLubyte*)malloc(256*256); + + unsigned char *data = __unPremultiplyTable; + // a == 0 case + for( int c = 0; c <= 255; c++ ) { + data[c] = c; + } + + for( int a = 1; a <= 255; a++ ) { + for( int c = 0; c <= 255; c++ ) { + data[a*256+c] = (c * 255) / a; + } + } + } + + return __unPremultiplyTable; + } + + void premultiplyPixels(const GLubyte *inPixels, GLubyte *outPixels, int byteLength, GLenum format) + { + const GLubyte *table = premultiplyTable(); + + if( format == GL_RGBA ) { + for( int i = 0; i < byteLength; i += 4 ) { + unsigned short a = inPixels[i+3] * 256; + outPixels[i+0] = table[ a + inPixels[i+0] ]; + outPixels[i+1] = table[ a + inPixels[i+1] ]; + outPixels[i+2] = table[ a + inPixels[i+2] ]; + outPixels[i+3] = inPixels[i+3]; + } + } + else if ( format == GL_LUMINANCE_ALPHA ) { + for( int i = 0; i < byteLength; i += 2 ) { + unsigned short a = inPixels[i+1] * 256; + outPixels[i+0] = table[ a + inPixels[i+0] ]; + outPixels[i+1] = inPixels[i+1]; + } + } + } + + void unPremultiplyPixels(const GLubyte *inPixels, GLubyte *outPixels, int byteLength, GLenum format) + { + const GLubyte *table = unPremultiplyTable(); + + if( format == GL_RGBA ) { + for( int i = 0; i < byteLength; i += 4 ) { + unsigned short a = inPixels[i+3] * 256; + outPixels[i+0] = table[ a + inPixels[i+0] ]; + outPixels[i+1] = table[ a + inPixels[i+1] ]; + outPixels[i+2] = table[ a + inPixels[i+2] ]; + outPixels[i+3] = inPixels[i+3]; + } + } + else if ( format == GL_LUMINANCE_ALPHA ) { + for( int i = 0; i < byteLength; i += 2 ) { + unsigned short a = inPixels[i+1] * 256; + outPixels[i+0] = table[ a + inPixels[i+0] ]; + outPixels[i+1] = inPixels[i+1]; + } + } + } + template class GLData { @@ -1421,13 +1508,16 @@ static bool JSB_glPixelStorei(se::State& s) { if (arg0 == GL_UNPACK_FLIP_Y_WEBGL) { __unpackFlipY = arg1 == 0 ? false : true; - SE_LOGE("cjh FIXME: support GL_UNPACK_FLIP_Y_WEBGL: %d\n", arg1); return true; } - - if (arg0 == GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL) + else if (arg0 == GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL) { - SE_LOGE("cjh FIXME: support GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: %d\n", arg1); + __premultiplyAlpha = arg1 == 0 ? false : true; + return true; + } + else if (arg0 == GL_UNPACK_COLORSPACE_CONVERSION_WEBGL) + { + SE_LOGE("Warning: UNPACK_COLORSPACE_CONVERSION_WEBGL is unsupported\n"); return true; } @@ -1712,6 +1802,19 @@ static bool JSB_glTexImage2D(se::State& s) { } } + if (__premultiplyAlpha) + { + if (format == GL_RGBA || format == GL_LUMINANCE_ALPHA) + { + int byteLength = 0; + if (format == GL_RGBA) + byteLength = width * height * 4; + else + byteLength = width * height * 2; + premultiplyPixels((GLubyte*)pixels, (GLubyte*)pixels, byteLength, format); + } + } + JSB_GL_CHECK(glTexImage2D((GLenum)target , (GLint)level , (GLint)internalformat , (GLsizei)width , (GLsizei)height , (GLint)border , (GLenum)format , (GLenum)type , (GLvoid*)pixels)); s.rval().setUndefined(); return true; @@ -3142,7 +3245,7 @@ static bool JSB_glGetParameter(se::State& s) break; case GL_UNPACK_COLORSPACE_CONVERSION_WEBGL: - // ret = JSValueMakeBoolean(ctx, false); + ret.setBoolean(false); break; // string From a668496b8ef3927d7719e80339a1c33018fb5641 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 28 Mar 2018 21:26:08 +0800 Subject: [PATCH 03/10] Comments initializing DeviceGraphics and textAlign supports middle. (#1171) * Comments initializing DeviceGraphics since runtime doesn't need renderer stuff temporarily. * textAlign supports middle. * reverts. --- native/cocos/platform/ios/CCApplication-ios.mm | 3 ++- native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm | 2 +- native/cocos/platform/mac/CCApplication-mac.mm | 5 +++-- native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/native/cocos/platform/ios/CCApplication-ios.mm b/native/cocos/platform/ios/CCApplication-ios.mm index 983bcd4790..9044f44c23 100644 --- a/native/cocos/platform/ios/CCApplication-ios.mm +++ b/native/cocos/platform/ios/CCApplication-ios.mm @@ -187,7 +187,8 @@ Application::Application(const std::string& name) createView(name); - renderer::DeviceGraphics::getInstance(); + //TODO: Runtime doesn't need renderer stuff temporarily. + // renderer::DeviceGraphics::getInstance(); se::ScriptEngine::getInstance(); EventDispatcher::init(); diff --git a/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm b/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm index b0c7bafd1b..d9d8f82848 100644 --- a/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm +++ b/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm @@ -493,7 +493,7 @@ void CanvasRenderingContext2D::set_textAlign(const std::string& textAlign) { _impl.textAlign = CanvasTextAlign::LEFT; } - else if (textAlign == "center") + else if (textAlign == "center" || textAlign == "middle") { _impl.textAlign = CanvasTextAlign::CENTER; } diff --git a/native/cocos/platform/mac/CCApplication-mac.mm b/native/cocos/platform/mac/CCApplication-mac.mm index 31838dfe10..2d8790db4a 100644 --- a/native/cocos/platform/mac/CCApplication-mac.mm +++ b/native/cocos/platform/mac/CCApplication-mac.mm @@ -67,8 +67,9 @@ Application::Application(const std::string& name) _scheduler = new Scheduler(); createView(name); - - renderer::DeviceGraphics::getInstance()->setScaleFactor(CAST_VIEW(_view)->getScaleFactor()); + + //TODO: Runtime doesn't need renderer stuff temporarily. +// renderer::DeviceGraphics::getInstance()->setScaleFactor(CAST_VIEW(_view)->getScaleFactor()); EventDispatcher::init(); se::ScriptEngine::getInstance(); } diff --git a/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm b/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm index 6eb6359a05..5aad04dea1 100644 --- a/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm +++ b/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm @@ -497,7 +497,7 @@ void CanvasRenderingContext2D::set_textAlign(const std::string& textAlign) { _impl.textAlign = CanvasTextAlign::LEFT; } - else if (textAlign == "center") + else if (textAlign == "center" || textAlign == "middle") { _impl.textAlign = CanvasTextAlign::CENTER; } From 73eb73c69048d6bd29d5e757336e59af52da1224 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 29 Mar 2018 15:50:38 +0800 Subject: [PATCH 04/10] [android] textAlign supports 'middle'. recreate buffer in the constructor of CanvasRenderingContext2D. (#1172) * [android] textAlign supports 'middle'. recreate buffer in the constructor of CanvasRenderingContext2D. * bug fix in CanvasRenderingContext2DImpl.java * java version 1.8 --- .../CCCanvasRenderingContext2D-android.cpp | 9 ++++--- .../lib/CanvasRenderingContext2DImpl.java | 25 ++++++++++++++++--- .../platform/android/libcocos2dx/build.gradle | 4 +++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp b/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp index d27bee5afa..de5ad2da5a 100644 --- a/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp +++ b/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp @@ -167,13 +167,14 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(float width, float height) : __width(width) , __height(height) { - SE_LOGD("CanvasGradient constructor: %p, width: %f, height: %f\n", this, width, height); + SE_LOGD("CanvasRenderingContext2D constructor: %p, width: %f, height: %f\n", this, width, height); _impl = new CanvasRenderingContext2DImpl(); + _impl->recreateBuffer(width, height); } CanvasRenderingContext2D::~CanvasRenderingContext2D() { - SE_LOGD("CanvasGradient destructor: %p\n", this); + SE_LOGD("CanvasRenderingContext2D destructor: %p\n", this); delete _impl; } @@ -185,7 +186,7 @@ void CanvasRenderingContext2D::recreateBuffer() void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height) { - SE_LOGD("CanvasGradient::clearRect: %p, %f, %f, %f, %f\n", this, x, y, width, height); + SE_LOGD("CanvasRenderingContext2D::clearRect: %p, %f, %f, %f, %f\n", this, x, y, width, height); _impl->clearRect(x, y, width, height); } @@ -333,7 +334,7 @@ void CanvasRenderingContext2D::set_textAlign(const std::string& textAlign) { _impl->setTextAlign(CanvasTextAlign::LEFT); } - else if (textAlign == "center") + else if (textAlign == "center" || textAlign == "middle") { _impl->setTextAlign(CanvasTextAlign::CENTER); } diff --git a/native/cocos/platform/android/java/src/org/cocos2dx/lib/CanvasRenderingContext2DImpl.java b/native/cocos/platform/android/java/src/org/cocos2dx/lib/CanvasRenderingContext2DImpl.java index 63d867a36b..3c03e8a90f 100644 --- a/native/cocos/platform/android/java/src/org/cocos2dx/lib/CanvasRenderingContext2DImpl.java +++ b/native/cocos/platform/android/java/src/org/cocos2dx/lib/CanvasRenderingContext2DImpl.java @@ -60,6 +60,9 @@ public class CanvasRenderingContext2DImpl { private int mFillStyleG = 0; private int mFillStyleB = 0; private int mFillStyleA = 255; + private String mFontName = "Arial"; + private float mFontSize = 40.0f; + private boolean mIsPaintDirty = false; private class Size { Size(float w, float h) { @@ -179,12 +182,24 @@ public class CanvasRenderingContext2DImpl { mBitmap.setPixels(clearColor, 0, mBitmap.getWidth(), 0, 0, mBitmap.getWidth(), mBitmap.getHeight()); } + private void updatePaint() { + if (mIsPaintDirty || mPaint == null) { + if (mPaint == null) { + mPaint = newPaint(mFontName, (int) mFontSize, false); //TODO: bold + } + + mPaint.setARGB(mFillStyleA, mFillStyleR, mFillStyleG, mFillStyleB); + mIsPaintDirty = false; + } + } + private void fillRect(float x, float y, float w, float h) { Log.d(TAG, "fillRect: " + x + ", " + y + ", " + ", " + w + ", " + h); } private void fillText(String text, float x, float y, float maxWidth) { Log.d(TAG, "fillText: " + text + ", " + x + ", " + y + ", " + ", " + maxWidth); + updatePaint(); Point pt = convertDrawPoint(new Point(x, y), text); // Convert to baseline Y float baselineY = pt.y - mPaint.getFontMetrics().bottom; @@ -197,19 +212,24 @@ public class CanvasRenderingContext2DImpl { } private float measureText(String text) { + updatePaint(); float ret = mPaint.measureText(text); Log.d(TAG, "measureText: " + text + ", return: " + ret); return ret; } private Size measureTextReturnSize(String text) { + updatePaint(); Paint.FontMetrics fm = mPaint.getFontMetrics(); return new Size(measureText(text), fm.bottom - fm.top); } private void updateFont(String fontName, float fontSize) { Log.d(TAG, "updateFont: " + fontName + ", " + fontSize); - mPaint = newPaint(fontName, (int)fontSize, false); //TODO: bold + mFontName = fontName; + mFontSize = fontSize; + mPaint = null; // Reset paint to re-create paint object in updatePaint + mIsPaintDirty = true; } private void setTextAlign(int align) { @@ -228,8 +248,7 @@ public class CanvasRenderingContext2DImpl { mFillStyleG = (int)(g * 255.0f); mFillStyleB = (int)(b * 255.0f); mFillStyleA = (int)(a * 255.0f); - - mPaint.setARGB(mFillStyleA, mFillStyleR, mFillStyleG, mFillStyleB); + mIsPaintDirty = true; } private Point convertDrawPoint(final Point point, String text) { diff --git a/native/cocos/platform/android/libcocos2dx/build.gradle b/native/cocos/platform/android/libcocos2dx/build.gradle index fe444ea3b8..5da9218bd4 100644 --- a/native/cocos/platform/android/libcocos2dx/build.gradle +++ b/native/cocos/platform/android/libcocos2dx/build.gradle @@ -23,6 +23,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { From 3c1da2db6c73cdb5a467ddefbe9220db3f083bf5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 29 Mar 2018 16:24:36 +0800 Subject: [PATCH 05/10] alphabetic textBaseline support. (#1173) --- .../platform/android/CCCanvasRenderingContext2D-android.cpp | 2 +- native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm | 2 +- native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp b/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp index de5ad2da5a..546164d20a 100644 --- a/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp +++ b/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp @@ -359,7 +359,7 @@ void CanvasRenderingContext2D::set_textBaseline(const std::string& textBaseline) { _impl->setTextBaseline(CanvasTextBaseline::MIDDLE); } - else if (textBaseline == "bottom") + else if (textBaseline == "bottom" || textBaseline == "alphabetic") //TODO:cjh, how to deal with alphabetic, currently we handle it as bottom mode. { _impl->setTextBaseline(CanvasTextBaseline::BOTTOM); } diff --git a/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm b/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm index d9d8f82848..cae9984620 100644 --- a/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm +++ b/native/cocos/platform/ios/CCCanvasRenderingContext2D-ios.mm @@ -518,7 +518,7 @@ void CanvasRenderingContext2D::set_textBaseline(const std::string& textBaseline) { _impl.textBaseLine = CanvasTextBaseline::MIDDLE; } - else if (textBaseline == "bottom") + else if (textBaseline == "bottom" || textBaseline == "alphabetic") //TODO:cjh, how to deal with alphabetic, currently we handle it as bottom mode. { _impl.textBaseLine = CanvasTextBaseline::BOTTOM; } diff --git a/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm b/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm index 5aad04dea1..f0c6f3870b 100644 --- a/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm +++ b/native/cocos/platform/mac/CCCanvasRenderingContext2D-mac.mm @@ -522,7 +522,7 @@ void CanvasRenderingContext2D::set_textBaseline(const std::string& textBaseline) { _impl.textBaseLine = CanvasTextBaseline::MIDDLE; } - else if (textBaseline == "bottom") + else if (textBaseline == "bottom" || textBaseline == "alphabetic") //TODO:cjh, how to deal with alphabetic, currently we handle it as bottom mode. { _impl.textBaseLine = CanvasTextBaseline::BOTTOM; } From d92ab3cbe7e972c5d5a1347ea791379b53d6a449 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 30 Mar 2018 07:41:59 +0800 Subject: [PATCH 06/10] touch event should also pass pageX, pageY. jsb.loadImage supports data base64 string. (#1174) * touch event should also pass pageX, pageY. * jsb.loadImage supports data base64 string. --- .../js-bindings/event/EventDispatcher.cpp | 2 + .../js-bindings/manual/jsb_global.cpp | 39 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/native/cocos/scripting/js-bindings/event/EventDispatcher.cpp b/native/cocos/scripting/js-bindings/event/EventDispatcher.cpp index 1ac1be9e3a..635c46dd6c 100644 --- a/native/cocos/scripting/js-bindings/event/EventDispatcher.cpp +++ b/native/cocos/scripting/js-bindings/event/EventDispatcher.cpp @@ -107,6 +107,8 @@ void EventDispatcher::dispatchTouchEvent(const struct TouchEvent& touchEvent) jsTouch->setProperty("identifier", se::Value(touch.index)); jsTouch->setProperty("clientX", se::Value(touch.x)); jsTouch->setProperty("clientY", se::Value(touch.y)); + jsTouch->setProperty("pageX", se::Value(touch.x)); + jsTouch->setProperty("pageY", se::Value(touch.y)); _jsTouchObjArray->setArrayElement(touchIndex, se::Value(jsTouch)); ++touchIndex; diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index c3b5ee73f5..6f6235eb05 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -575,13 +575,36 @@ static bool js_loadImage(se::State& s) assert(callbackVal.isObject()); assert(callbackVal.toObject()->isFunction()); - std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path); - if (fullPath.empty()) + if (path.empty()) { - SE_REPORT_ERROR("File (%s) doesn't exist!", path.c_str()); + SE_REPORT_ERROR("src is empty!"); return false; } + std::string fullPath; + int imageBytes = 0; + unsigned char* imageData = nullptr; + std::smatch match; + if (path.find("data:") == 0 && std::regex_match(path.cbegin(), path.cend(), match, std::regex("^data:image/\\w+;base64,(.*?)$"))) + { + std::string base64Str = match[1]; + imageBytes = base64Decode((const unsigned char *)base64Str.data(), (unsigned int)base64Str.length(), &imageData); + if (imageBytes <= 0 || imageData == nullptr) + { + SE_REPORT_ERROR("Decode base64 image data failed!"); + return false; + } + } + else + { + fullPath = FileUtils::getInstance()->fullPathForFilename(path); + if (fullPath.empty()) + { + SE_REPORT_ERROR("File (%s) doesn't exist!", path.c_str()); + return false; + } + } + Image* img = new (std::nothrow) Image(); __threadPool->pushTask([=](int tid){ @@ -590,7 +613,15 @@ static bool js_loadImage(se::State& s) // cause thread race issues. Therefore, we get the full path of file before // going into task callback. // Be careful of invoking any Cocos2d-x interface in a sub-thread. - bool loadSucceed = img->initWithImageFile(fullPath); + bool loadSucceed = false; + if (fullPath.empty()) + { + loadSucceed = img->initWithImageData(imageData, imageBytes); + } + else + { + loadSucceed = img->initWithImageFile(fullPath); + } Application::getInstance()->getScheduler()->performFunctionInCocosThread([=](){ if (loadSucceed) From 8dc0f35714f2ed821d6efb2b265309be908a2bfe Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 30 Mar 2018 17:44:08 +0800 Subject: [PATCH 07/10] [ios] Fixes bugs about multisampling and GL_DEPTCH_STENCIL_ATTACHMENT (#1175) * [ios] Fixes bugs about multisampling. * [ios] Should use opengl es2 * Fixes compilation issues in DeviceGraphics after switching back to opengles2. * glFramebufferRenderbuffer GL_DEPTH_STENCIL_ATTACHMENT fix in webgl binding. * Comment some code of invoking opengles3.0 methods in gfx/Texture2D.cpp. --- native/cocos/platform/CCGL.h | 4 +++ native/cocos/platform/ios/CCEAGLView-ios.h | 3 -- native/cocos/platform/ios/CCEAGLView-ios.mm | 35 +++++++++++-------- native/cocos/platform/ios/CCGL-ios.h | 6 ++-- native/cocos/renderer/gfx/DeviceGraphics.cpp | 2 +- native/cocos/renderer/gfx/Texture2D.cpp | 20 ++++++----- .../js-bindings/manual/jsb_opengl_manual.cpp | 24 +++++++++---- 7 files changed, 58 insertions(+), 36 deletions(-) diff --git a/native/cocos/platform/CCGL.h b/native/cocos/platform/CCGL.h index ee5ae2f08d..f3ba11cb5a 100644 --- a/native/cocos/platform/CCGL.h +++ b/native/cocos/platform/CCGL.h @@ -91,6 +91,10 @@ THE SOFTWARE. #define GL_MAX_VARYING_VECTORS 0x8DFC #endif +#ifndef GL_DEPTH_STENCIL +#define GL_DEPTH_STENCIL 0x84F9 +#endif + #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC #include "platform/mac/CCGL-mac.h" #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS diff --git a/native/cocos/platform/ios/CCEAGLView-ios.h b/native/cocos/platform/ios/CCEAGLView-ios.h index 00cc38c26a..d487b0d14f 100644 --- a/native/cocos/platform/ios/CCEAGLView-ios.h +++ b/native/cocos/platform/ios/CCEAGLView-ios.h @@ -129,9 +129,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /** CCEAGLView uses double-buffer. This method swaps the buffers */ -(void) swapBuffers; -- (CGRect) convertRectFromViewToSurface:(CGRect)rect; -- (CGPoint) convertPointFromViewToSurface:(CGPoint)point; - - (BOOL) isReady; -(void) doAnimationWhenKeyboardMoveWithDuration:(float) duration distance:(float) dis; diff --git a/native/cocos/platform/ios/CCEAGLView-ios.mm b/native/cocos/platform/ios/CCEAGLView-ios.mm index a67eb208b0..a902653407 100644 --- a/native/cocos/platform/ios/CCEAGLView-ios.mm +++ b/native/cocos/platform/ios/CCEAGLView-ios.mm @@ -77,8 +77,6 @@ namespace else return GL_RGBA8_OES; } - - bool isReady = false; } //CLASS IMPLEMENTATIONS: @@ -110,6 +108,7 @@ namespace _pixelformatString = format; _pixelformat = pixelformat2glenum(_pixelformatString); _depthFormat = depth; + // Multisampling doc: https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html#//apple_ref/doc/uid/TP40008793-CH103-SW4 _multisampling = sampling; _requestedSamples = nSamples; _preserveBackbuffer = retained; @@ -212,6 +211,7 @@ namespace - (void) layoutSubviews { + glBindFramebuffer(GL_FRAMEBUFFER, _defaultFramebuffer); if (_defaultColorBuffer) { glBindRenderbuffer(GL_RENDERBUFFER, _defaultColorBuffer); @@ -235,6 +235,7 @@ namespace if (_multisampling) { + glBindFramebuffer(GL_FRAMEBUFFER, _msaaFramebuffer); if (_msaaColorBuffer) { glBindRenderbuffer(GL_RENDERBUFFER, _msaaColorBuffer); @@ -247,8 +248,11 @@ namespace glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, _requestedSamples, _depthFormat, backingWidth, backingHeight); } } - - glBindRenderbuffer(GL_RENDERBUFFER, _defaultColorBuffer); + else + { + glBindRenderbuffer(GL_RENDERBUFFER, _defaultColorBuffer); + } + CHECK_GL_ERROR(); GLenum error; @@ -305,7 +309,7 @@ namespace if (_multisampling) { - glGenRenderbuffers(1, &_msaaFramebuffer); + glGenFramebuffers(1, &_msaaFramebuffer); if (0 == _msaaFramebuffer) { NSLog(@"Can not create multi sampling frame buffer"); @@ -347,7 +351,6 @@ namespace } glBindRenderbuffer(GL_RENDERBUFFER, _msaaColorBuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _msaaColorBuffer); - CHECK_GL_ERROR(); return TRUE; } @@ -378,8 +381,8 @@ namespace if (!_multisampling || (0 == _msaaFramebuffer)) return TRUE; - glBindFramebuffer(GL_RENDERBUFFER, _msaaColorBuffer); - glGenBuffers(1, &_msaaDepthBuffer); + glBindFramebuffer(GL_FRAMEBUFFER, _msaaFramebuffer); + glGenRenderbuffers(1, &_msaaDepthBuffer); if (0 == _msaaDepthBuffer) { NSLog(@"Can not create multi sampling depth buffer."); @@ -394,7 +397,7 @@ namespace glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _msaaDepthBuffer); CHECK_GL_ERROR(); - + return TRUE; } @@ -404,19 +407,19 @@ namespace // - preconditions // -> context_ MUST be the OpenGL context // -> renderbuffer_ must be the RENDER BUFFER - + if (_multisampling) { /* Resolve from msaaFramebuffer to resolveFramebuffer */ - //glDisable(GL_SCISSOR_TEST); + //glDisable(GL_SCISSOR_TEST); glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, _msaaFramebuffer); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, _defaultFramebuffer); glResolveMultisampleFramebufferAPPLE(); } CHECK_GL_ERROR(); - if(_discardFramebufferSupported) + if (_discardFramebufferSupported) { if (_multisampling) { @@ -431,7 +434,7 @@ namespace glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments); } - glBindRenderbuffer(GL_RENDERBUFFER, _msaaColorBuffer); + } else if (_depthFormat) { @@ -442,7 +445,9 @@ namespace CHECK_GL_ERROR(); } - + + glBindRenderbuffer(GL_RENDERBUFFER, _defaultColorBuffer); + if(![_context presentRenderbuffer:GL_RENDERBUFFER]) NSLog(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__); diff --git a/native/cocos/platform/ios/CCGL-ios.h b/native/cocos/platform/ios/CCGL-ios.h index 32f3250dfa..e882d792c0 100644 --- a/native/cocos/platform/ios/CCGL-ios.h +++ b/native/cocos/platform/ios/CCGL-ios.h @@ -29,8 +29,8 @@ THE SOFTWARE. #include "platform/CCPlatformConfig.h" #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS -#include -#include +#include +#include #define glClearDepth glClearDepthf #define glDepthRange glDepthRangef @@ -40,7 +40,7 @@ THE SOFTWARE. //#define glMapBuffer glMapBufferOES //#define glUnmapBuffer glUnmapBufferOES // -//#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES +#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES //#define GL_DEPTH_STENCIL GL_DEPTH_STENCIL_OES //#define GL_WRITE_ONLY GL_WRITE_ONLY_OES diff --git a/native/cocos/renderer/gfx/DeviceGraphics.cpp b/native/cocos/renderer/gfx/DeviceGraphics.cpp index bd97d81ea0..49c2fd4af8 100644 --- a/native/cocos/renderer/gfx/DeviceGraphics.cpp +++ b/native/cocos/renderer/gfx/DeviceGraphics.cpp @@ -604,7 +604,7 @@ void DeviceGraphics::initCaps() GL_CHECK(glGetIntegerv(GL_MAX_TEXTURE_UNITS, &_caps.maxTextureUnits)); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) // FIXME: how to get these infomations _caps.maxColorAttatchments = 1; _caps.maxDrawBuffers = 1; diff --git a/native/cocos/renderer/gfx/Texture2D.cpp b/native/cocos/renderer/gfx/Texture2D.cpp index 81a51ca35d..e6f613670f 100644 --- a/native/cocos/renderer/gfx/Texture2D.cpp +++ b/native/cocos/renderer/gfx/Texture2D.cpp @@ -82,8 +82,9 @@ namespace { const GLint border = 0; if (IsTarget3D(target)) { - GL_CHECK(glTexImage3D(target, level, dui->internalFormat, width, height, depth, - border, dui->unpackFormat, dui->unpackType, data)); + assert(false); +// GL_CHECK(glTexImage3D(target, level, dui->internalFormat, width, height, depth, +// border, dui->unpackFormat, dui->unpackType, data)); } else { MOZ_ASSERT(depth == 1); GL_CHECK(glTexImage2D(target, level, dui->internalFormat, width, height, border, dui->unpackFormat, dui->unpackType, data)); @@ -96,7 +97,8 @@ namespace { const webgl::PackingInfo& pi, const void* data) { if (IsTarget3D(target)) { - GL_CHECK(glTexSubImage3D(target, level, xOffset, yOffset, zOffset, width, height, depth, pi.format, pi.type, data)); + assert(false); +// GL_CHECK(glTexSubImage3D(target, level, xOffset, yOffset, zOffset, width, height, depth, pi.format, pi.type, data)); } else { MOZ_ASSERT(zOffset == 0); MOZ_ASSERT(depth == 1); @@ -112,8 +114,9 @@ namespace { const GLint border = 0; if (IsTarget3D(target)) { - GL_CHECK(glCompressedTexImage3D(target, level, internalFormat, width, height, - depth, border, dataSize, data)); + assert(false); +// GL_CHECK(glCompressedTexImage3D(target, level, internalFormat, width, height, +// depth, border, dataSize, data)); } else { MOZ_ASSERT(depth == 1); GL_CHECK(glCompressedTexImage2D(target, level, internalFormat, width, height, @@ -128,9 +131,10 @@ namespace { GLsizei dataSize, const void* data) { if (IsTarget3D(target)) { - GL_CHECK(glCompressedTexSubImage3D(target, level, xOffset, yOffset, zOffset, - width, height, depth, sizedUnpackFormat, dataSize, - data)); + assert(false); +// GL_CHECK(glCompressedTexSubImage3D(target, level, xOffset, yOffset, zOffset, +// width, height, depth, sizedUnpackFormat, dataSize, +// data)); } else { MOZ_ASSERT(zOffset == 0); MOZ_ASSERT(depth == 1); diff --git a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp index 88464d87e5..b34fed1a38 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp @@ -1185,7 +1185,15 @@ static bool JSB_glFramebufferRenderbuffer(se::State& s) { ok &= seval_to_uint32(args[3], &arg3 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); - JSB_GL_CHECK(glFramebufferRenderbuffer((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 , (GLuint)arg3 )); + if( arg1 == GL_DEPTH_STENCIL_ATTACHMENT) { + JSB_GL_CHECK(glFramebufferRenderbuffer((GLenum)arg0, GL_DEPTH_ATTACHMENT, (GLenum)arg2 , (GLuint)arg3)); + JSB_GL_CHECK(glFramebufferRenderbuffer((GLenum)arg0, GL_STENCIL_ATTACHMENT, (GLenum)arg2 , (GLuint)arg3)); + } + else + { + JSB_GL_CHECK(glFramebufferRenderbuffer((GLenum)arg0 , (GLenum)arg1 , (GLenum)arg2 , (GLuint)arg3)); + } + s.rval().setUndefined(); return true; } @@ -1598,6 +1606,10 @@ static bool JSB_glRenderbufferStorage(se::State& s) { ok &= seval_to_int32(args[3], &arg3 ); SE_PRECONDITION2(ok, false, "Error processing arguments"); + if( arg1 == GL_DEPTH_STENCIL ) { + arg1 = GL_DEPTH24_STENCIL8; + } + JSB_GL_CHECK(glRenderbufferStorage((GLenum)arg0 , (GLenum)arg1 , (GLsizei)arg2 , (GLsizei)arg3 )); s.rval().setUndefined(); return true; @@ -3415,11 +3427,11 @@ bool JSB_register_opengl(se::Object* obj) __glObj->defineFunction("hint", _SE(JSB_glHint)); __glObj->defineFunction("isBuffer", _SE(JSB_glIsBuffer)); __glObj->defineFunction("isEnabled", _SE(JSB_glIsEnabled)); - __glObj->defineFunction("isFramebuffer", _SE(JSB_glIsFramebuffer)); - __glObj->defineFunction("isProgram", _SE(JSB_glIsProgram)); - __glObj->defineFunction("isRenderbuffer", _SE(JSB_glIsRenderbuffer)); - __glObj->defineFunction("isShader", _SE(JSB_glIsShader)); - __glObj->defineFunction("isTexture", _SE(JSB_glIsTexture)); + __glObj->defineFunction("_isFramebuffer", _SE(JSB_glIsFramebuffer)); + __glObj->defineFunction("_isProgram", _SE(JSB_glIsProgram)); + __glObj->defineFunction("_isRenderbuffer", _SE(JSB_glIsRenderbuffer)); + __glObj->defineFunction("_isShader", _SE(JSB_glIsShader)); + __glObj->defineFunction("_isTexture", _SE(JSB_glIsTexture)); __glObj->defineFunction("lineWidth", _SE(JSB_glLineWidth)); __glObj->defineFunction("_linkProgram", _SE(JSB_glLinkProgram)); __glObj->defineFunction("pixelStorei", _SE(JSB_glPixelStorei)); From 0bd5c94c84977e9e40b35b1a786cfe6a9e2c0f97 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 31 Mar 2018 20:26:17 +0800 Subject: [PATCH 08/10] updates buildTooVersion to 27.0.3. Uses implementation instead of compile. (#1177) --- native/cocos/platform/android/libcocos2dx/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/platform/android/libcocos2dx/build.gradle b/native/cocos/platform/android/libcocos2dx/build.gradle index 5da9218bd4..7bba23945a 100644 --- a/native/cocos/platform/android/libcocos2dx/build.gradle +++ b/native/cocos/platform/android/libcocos2dx/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 22 - buildToolsVersion '26.0.2' + buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 10 @@ -30,5 +30,5 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: '../java/libs') + implementation fileTree(include: ['*.jar'], dir: '../java/libs') } From 016553cdf3dc0b93e07a2a3d255c3627d501ec31 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 3 Apr 2018 10:09:13 +0800 Subject: [PATCH 09/10] [mac] Shader version should be at least 120 to fix "GLSL 110 does not allow sub- or super-matrix constructors" issue. (#1179) * Don't use regex match for getting base64 string. Uses string pointer offset instead. * [mac] Shader version should be at least 120 to fix "GLSL 110 does not allow sub- or super-matrix constructors" issue. * bug fix of shaderSource.find("#version", ...); --- .../cocos/scripting/js-bindings/manual/jsb_global.cpp | 10 ++++++---- .../scripting/js-bindings/manual/jsb_opengl_manual.cpp | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index 6f6235eb05..fc826c12cb 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -584,11 +584,13 @@ static bool js_loadImage(se::State& s) std::string fullPath; int imageBytes = 0; unsigned char* imageData = nullptr; - std::smatch match; - if (path.find("data:") == 0 && std::regex_match(path.cbegin(), path.cend(), match, std::regex("^data:image/\\w+;base64,(.*?)$"))) + size_t pos = std::string::npos; + if (path.find("data:") == 0 && (pos = path.find("base64,")) != std::string::npos) { - std::string base64Str = match[1]; - imageBytes = base64Decode((const unsigned char *)base64Str.data(), (unsigned int)base64Str.length(), &imageData); + size_t dataStartPos = pos + strlen("base64,"); + const char* base64Data = path.data() + dataStartPos; + size_t dataLen = path.length() - dataStartPos; + imageBytes = base64Decode((const unsigned char *)base64Data, (unsigned int)dataLen, &imageData); if (imageBytes <= 0 || imageData == nullptr) { SE_REPORT_ERROR("Decode base64 image data failed!"); diff --git a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp index b34fed1a38..edd7fc6406 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp @@ -2685,6 +2685,15 @@ static bool JSB_glShaderSource(se::State& s) { SE_PRECONDITION2(ok, false, "Error processing arguments"); #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 + size_t firstLinePos = shaderSource.find("\n"); + if (firstLinePos != std::string::npos) + { + std::string firstLine = shaderSource.substr(0, firstLinePos); + if (firstLine.find("#version") == std::string::npos) + { + shaderSource = "#version 120\n" + shaderSource; + } + } shaderSource = std::regex_replace(shaderSource, std::regex("precision\\s+(lowp|mediump|highp).*?;"), ""); shaderSource = std::regex_replace(shaderSource, std::regex("\\s(lowp|mediump|highp)\\s"), " "); #endif From 43973307774a4c246dc27e6ba84e2612a7fd2d8d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 3 Apr 2018 14:34:48 +0800 Subject: [PATCH 10/10] [runtime, android] Fix local reference table overflow error problem in CCCanvasRenderingContext2D-android.cpp. (#1180) --- .../platform/android/CCCanvasRenderingContext2D-android.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp b/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp index 546164d20a..792cbfe4d2 100644 --- a/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp +++ b/native/cocos/platform/android/CCCanvasRenderingContext2D-android.cpp @@ -29,6 +29,7 @@ public: { jobject obj = JniHelper::newObject("org/cocos2dx/lib/CanvasRenderingContext2DImpl"); _obj = JniHelper::getEnv()->NewGlobalRef(obj); + JniHelper::getEnv()->DeleteLocalRef(obj); } ~CanvasRenderingContext2DImpl()