Cocos2d-x is a suite of open-source, cross-platform, game-development tools used by millions of developers all over the world.
There is an issue related to vertices pages boundary overlap. Result is extra random triangles or missed triangles. Issue reproduced on my devices iPad Mini (iOS 15.7.1), iPhone 7+ (iOS 15.7.5) and all Simulators (iOS 13.7, 14.2, 16.4).
Simplified sample code. Triangles should fill-up all node to make glitches easy visible. 5 vertices per iteration used to guarantee pages overlap.
- (void) draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
{
int verticesCount = 65535*2+10; // to make two pages overlaps
int trianglesDrawsCount = (verticesCount/5);
GLKVector4 redColor = [CCColor colorWithRed:1. green:0. blue:0. alpha:1.].glkVector4;
CGFloat x,y,d;
int trianlgesPerRow = 132;
d = <triangle size to fill-up node with triangles>;
CGFloat vertexArray[10];
CGPoint points[5];
for (int trianglesDraw=0; trianglesDraw<trianglesDrawsCount; trianglesDraw++) {
x = d*(trianglesDraw%trianlgesPerRow);
y = d*(trianglesDraw/trianlgesPerRow);
vertexArray[0] = x;
vertexArray[1] = y;
vertexArray[2] = x+d;
vertexArray[3] = y;
vertexArray[4] = x+d;
vertexArray[5] = y+d;
vertexArray[6] = x;
vertexArray[7] = y+d;
vertexArray[8] = x+d;
vertexArray[9] = y+d;
CCRenderBuffer buffer = [renderer enqueueTriangles:2 andVertexes:5 withState:self.renderState globalSortOrder:0];
for (int i=0; i<5; ++i) {
points[i] = ccp(vertexArray[2*i], vertexArray[2*i+1]);
CCRenderBufferSetVertex(buffer, i, CCVertexApplyTransform((CCVertex){{points[i].x, points[i].y, 0, 1}, {0, 0}, {0, 0}, redColor}, transform));
}
CCRenderBufferSetTriangle(buffer, 0, 0, 1, 2);
CCRenderBufferSetTriangle(buffer, 1, 0, 3, 4);
}
}
Result is in attachment.
Take a look into CCNoARC.m file. Method CCRenderer::enqueueLines:andVertexes:withState:globalSortOrder:
-(CCRenderBuffer)enqueueTriangles:(NSUInteger)triangleCount andVertexes:(NSUInteger)vertexCount withState:(CCRenderState *)renderState globalSortOrder:(NSInteger)globalSortOrder;
{
// Need to record the first vertex or element index before pushing more vertexes.
NSUInteger firstVertex = _buffers->_vertexBuffer->_count;
NSUInteger firstIndex = _buffers->_indexBuffer->_count;
// Value is 0 unless there a page boundary overlap would occur.
NSUInteger vertexPageOffset = PageOffset(firstVertex, vertexCount);
if (vertexPageOffset>0) {
int stop=0; // #1 if we got here then visual bug will be
}
// Split vertexes into pages of 2^16 vertexes since GLES2 requires indexing with shorts.
NSUInteger vertexPage = (firstVertex + vertexPageOffset) >> 16;
NSUInteger vertexPageIndex = (firstVertex + vertexPageOffset) & 0xFFFF;
// Ensure that the buffers have enough storage space.
NSUInteger indexCount = 3*triangleCount;
CCVertex *vertexes = CCGraphicsBufferPushElements(_buffers->_vertexBuffer, vertexCount + vertexPageOffset);
if (vertexPageOffset>0) {
vertexes = vertexes + vertexPageOffset; // #2 vertices will be stored from beginning of the next page
}
You can set breakpoint in line with my first comment to easily detect error.
if (vertexPageOffset>0) {
int stop=0; // #1 if we got here then visual bug will be
}
I've added last three lines to fix this issue. I don't know is it solution or just workaround, but it works now.
if (vertexPageOffset>0) {
vertexes = vertexes + vertexPageOffset; // #2 vertices will be stored from beginning of the next page
}
I hope it helps somebody.
Hello,
Does this project support Ninja generator?
I am trying to compile with Ninja and see error below.
[414/640] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/platform/apple/CCFileUtils-apple.mm.o FAILED: engine/cocos/core/CMakeFiles/cocos2d.dir/platform/apple/CCFileUtils-apple.mm.o /usr/local/opt/llvm@16/bin/clang++ -DCOCOS2D_DEBUG=1 -DLWS_WITH_LIBUV -DUSE_FILE32API -D__APPLE__ -I/System/Library/Frameworks -I/Users/panpaliamahen/github/game/cocos2d-x -I/Users/panpaliamahen/github/game/cocos2d-x/cocos -I/Users/panpaliamahen/github/game/cocos2d-x/extensions -I/Users/panpaliamahen/github/game/cocos2d-x/cocos/platform -I/Users/panpaliamahen/github/game/cocos2d-x/cocos/editor-support -I/Users/panpaliamahen/github/game/cocos2d-x/external/recast/.. -I/Users/panpaliamahen/github/game/cocos2d-x/external/tinyxml2/. -I/Users/panpaliamahen/github/game/cocos2d-x/external/xxhash/. -I/Users/panpaliamahen/github/game/cocos2d-x/external/xxtea/. -I/Users/panpaliamahen/github/game/cocos2d-x/external/clipper/. -I/Users/panpaliamahen/github/game/cocos2d-x/external/edtaa3func/. -I/Users/panpaliamahen/github/game/cocos2d-x/external/ConvertUTF/. -I/Users/panpaliamahen/github/game/cocos2d-x/external/poly2tri/.. -I/Users/panpaliamahen/github/game/cocos2d-x/external/md5/.. -I/Users/panpaliamahen/github/game/cocos2d-x/external/unzip/. -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/Box2D/include -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/chipmunk/include -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/freetype2/include/mac/freetype2 -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/bullet/include -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/bullet/include/bullet -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/jpeg/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/openssl/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/uv/include -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/webp/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/websockets/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/curl/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/png/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/glfw3/include/mac -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/zlib/include -isystem /Users/panpaliamahen/github/game/cocos2d-x/external/glsl-optimizer/include -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.6 -std=c++11 -Winvalid-pch -Xclang -include-pch -Xclang /Users/panpaliamahen/github/game/cocos2d-x/cmake-build-debug/engine/cocos/core/CMakeFiles/cocos2d.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/panpaliamahen/github/game/cocos2d-x/cmake-build-debug/engine/cocos/core/CMakeFiles/cocos2d.dir/cmake_pch.hxx -MD -MT engine/cocos/core/CMakeFiles/cocos2d.dir/platform/apple/CCFileUtils-apple.mm.o -MF engine/cocos/core/CMakeFiles/cocos2d.dir/platform/apple/CCFileUtils-apple.mm.o.d -o engine/cocos/core/CMakeFiles/cocos2d.dir/platform/apple/CCFileUtils-apple.mm.o -c /Users/panpaliamahen/github/game/cocos2d-x/cocos/platform/apple/CCFileUtils-apple.mm error: Objective-C was disabled in PCH file but is currently enabled 1 error generated.
Please let me know if you need more information?
Thanks, Mahendra