mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3_renderPrimitive' of github.com:dabingnn/cocos2d-x into v3
This commit is contained in:
commit
031efaf242
|
@ -1253,6 +1253,7 @@
|
|||
50ABC0671926664800A911A9 /* CCPlatformDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 50ABBF541926664700A911A9 /* CCPlatformDefine.h */; };
|
||||
50ABC0691926664800A911A9 /* CCStdC.h in Headers */ = {isa = PBXBuildFile; fileRef = 50ABBF551926664700A911A9 /* CCStdC.h */; };
|
||||
A07A4CAF1783777C0073F6A7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1551A342158F2AB200E66CFE /* Foundation.framework */; };
|
||||
B2165EEA19921124000BE3E6 /* CCPrimitiveCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B257B45E198A353E00D9A687 /* CCPrimitiveCommand.cpp */; };
|
||||
B217703C1977ECB4009EE11B /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B217703B1977ECB4009EE11B /* IOKit.framework */; };
|
||||
B21770401977ECE6009EE11B /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B217703F1977ECE6009EE11B /* OpenGL.framework */; };
|
||||
B21770421977ECF8009EE11B /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B21770411977ECF8009EE11B /* ApplicationServices.framework */; };
|
||||
|
@ -1276,6 +1277,20 @@
|
|||
B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B24AA983195A675C007B4522 /* CCFastTMXTiledMap.cpp */; };
|
||||
B24AA98B195A675C007B4522 /* CCFastTMXTiledMap.h in Headers */ = {isa = PBXBuildFile; fileRef = B24AA984195A675C007B4522 /* CCFastTMXTiledMap.h */; };
|
||||
B24AA98C195A675C007B4522 /* CCFastTMXTiledMap.h in Headers */ = {isa = PBXBuildFile; fileRef = B24AA984195A675C007B4522 /* CCFastTMXTiledMap.h */; };
|
||||
B257B44E1989D5E800D9A687 /* CCPrimitive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B257B44C1989D5E800D9A687 /* CCPrimitive.cpp */; };
|
||||
B257B44F1989D5E800D9A687 /* CCPrimitive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B257B44C1989D5E800D9A687 /* CCPrimitive.cpp */; };
|
||||
B257B4501989D5E800D9A687 /* CCPrimitive.h in Headers */ = {isa = PBXBuildFile; fileRef = B257B44D1989D5E800D9A687 /* CCPrimitive.h */; };
|
||||
B257B4511989D5E800D9A687 /* CCPrimitive.h in Headers */ = {isa = PBXBuildFile; fileRef = B257B44D1989D5E800D9A687 /* CCPrimitive.h */; };
|
||||
B257B460198A353E00D9A687 /* CCPrimitiveCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B257B45E198A353E00D9A687 /* CCPrimitiveCommand.cpp */; };
|
||||
B257B461198A353E00D9A687 /* CCPrimitiveCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B257B45F198A353E00D9A687 /* CCPrimitiveCommand.h */; };
|
||||
B276EF5F1988D1D500CD400F /* CCVertexIndexData.h in Headers */ = {isa = PBXBuildFile; fileRef = B276EF5B1988D1D500CD400F /* CCVertexIndexData.h */; };
|
||||
B276EF601988D1D500CD400F /* CCVertexIndexData.h in Headers */ = {isa = PBXBuildFile; fileRef = B276EF5B1988D1D500CD400F /* CCVertexIndexData.h */; };
|
||||
B276EF611988D1D500CD400F /* CCVertexIndexData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */; };
|
||||
B276EF621988D1D500CD400F /* CCVertexIndexData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */; };
|
||||
B276EF631988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */; };
|
||||
B276EF641988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */; };
|
||||
B276EF651988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */; };
|
||||
B276EF661988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */; };
|
||||
B27AEE0219768934008BD575 /* libwebsockets.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AAF5384180E35A3000584C8 /* libwebsockets.a */; };
|
||||
B282B4801980E08F00666787 /* CCEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */; };
|
||||
B282B4811980E0A300666787 /* CCEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */; };
|
||||
|
@ -3008,6 +3023,14 @@
|
|||
B24EEA7619775ECE004493CC /* libcocosbuilder iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libcocosbuilder iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B24EEA7E19775EE1004493CC /* libspine iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libspine iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B24EEA8619775EF3004493CC /* libnetwork iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libnetwork iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B257B44C1989D5E800D9A687 /* CCPrimitive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPrimitive.cpp; sourceTree = "<group>"; };
|
||||
B257B44D1989D5E800D9A687 /* CCPrimitive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPrimitive.h; sourceTree = "<group>"; };
|
||||
B257B45E198A353E00D9A687 /* CCPrimitiveCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPrimitiveCommand.cpp; sourceTree = "<group>"; };
|
||||
B257B45F198A353E00D9A687 /* CCPrimitiveCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPrimitiveCommand.h; sourceTree = "<group>"; };
|
||||
B276EF5B1988D1D500CD400F /* CCVertexIndexData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCVertexIndexData.h; sourceTree = "<group>"; };
|
||||
B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexData.cpp; sourceTree = "<group>"; };
|
||||
B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCVertexIndexBuffer.h; sourceTree = "<group>"; };
|
||||
B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexBuffer.cpp; sourceTree = "<group>"; };
|
||||
B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCEditBoxImplMac.mm; sourceTree = "<group>"; };
|
||||
B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplMac.h; sourceTree = "<group>"; };
|
||||
B29594AF1926D5D9003EEF37 /* ccShader_3D_Color.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_Color.frag; sourceTree = "<group>"; };
|
||||
|
@ -4897,6 +4920,10 @@
|
|||
500DC89819105D41007B91BF /* renderer */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B276EF5B1988D1D500CD400F /* CCVertexIndexData.h */,
|
||||
B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */,
|
||||
B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */,
|
||||
B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */,
|
||||
50ABBD641925AB4100A911A9 /* CCBatchCommand.cpp */,
|
||||
50ABBD651925AB4100A911A9 /* CCBatchCommand.h */,
|
||||
50ABBD661925AB4100A911A9 /* CCCustomCommand.cpp */,
|
||||
|
@ -4930,6 +4957,10 @@
|
|||
50ABBD801925AB4100A911A9 /* CCTextureAtlas.h */,
|
||||
50ABBD811925AB4100A911A9 /* CCTextureCache.cpp */,
|
||||
50ABBD821925AB4100A911A9 /* CCTextureCache.h */,
|
||||
B257B44C1989D5E800D9A687 /* CCPrimitive.cpp */,
|
||||
B257B44D1989D5E800D9A687 /* CCPrimitive.h */,
|
||||
B257B45E198A353E00D9A687 /* CCPrimitiveCommand.cpp */,
|
||||
B257B45F198A353E00D9A687 /* CCPrimitiveCommand.h */,
|
||||
5034CA5D191D591900CE6051 /* shaders */,
|
||||
);
|
||||
name = renderer;
|
||||
|
@ -5258,6 +5289,7 @@
|
|||
B375107B1823AC9F00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */,
|
||||
46A170F01807CECA005B8026 /* CCPhysicsWorld.h in Headers */,
|
||||
50ABBEC11925AB6F00A911A9 /* CCValue.h in Headers */,
|
||||
B276EF631988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */,
|
||||
50ABBE871925AB6F00A911A9 /* ccMacros.h in Headers */,
|
||||
50ABBE731925AB6F00A911A9 /* CCEventListenerMouse.h in Headers */,
|
||||
1A570063180BC5A10088DEC7 /* CCAction.h in Headers */,
|
||||
|
@ -5268,6 +5300,7 @@
|
|||
5034CA3B191D591100CE6051 /* ccShader_PositionColor.vert in Headers */,
|
||||
1A570077180BC5A10088DEC7 /* CCActionGrid3D.h in Headers */,
|
||||
1A57007B180BC5A10088DEC7 /* CCActionInstant.h in Headers */,
|
||||
B276EF5F1988D1D500CD400F /* CCVertexIndexData.h in Headers */,
|
||||
1A57007F180BC5A10088DEC7 /* CCActionInterval.h in Headers */,
|
||||
1A01C69A18F57BE800EFE3A6 /* CCSet.h in Headers */,
|
||||
1A570083180BC5A10088DEC7 /* CCActionManager.h in Headers */,
|
||||
|
@ -5397,6 +5430,7 @@
|
|||
5034CA35191D591100CE6051 /* ccShader_PositionTexture.frag in Headers */,
|
||||
50ABBE6F1925AB6F00A911A9 /* CCEventListenerKeyboard.h in Headers */,
|
||||
50ABBE9D1925AB6F00A911A9 /* CCRefPtr.h in Headers */,
|
||||
B257B461198A353E00D9A687 /* CCPrimitiveCommand.h in Headers */,
|
||||
5034CA31191D591100CE6051 /* ccShader_PositionTexture_uColor.vert in Headers */,
|
||||
50ABBE7B1925AB6F00A911A9 /* CCEventMouse.h in Headers */,
|
||||
503DD8F91926B0DB00CD74DD /* CCIMEDispatcher.h in Headers */,
|
||||
|
@ -5404,6 +5438,7 @@
|
|||
50ABBE8F1925AB6F00A911A9 /* CCPlatformConfig.h in Headers */,
|
||||
50ABBE291925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */,
|
||||
50ABBE471925AB6F00A911A9 /* CCEvent.h in Headers */,
|
||||
B257B4501989D5E800D9A687 /* CCPrimitive.h in Headers */,
|
||||
50ABBE6B1925AB6F00A911A9 /* CCEventListenerFocus.h in Headers */,
|
||||
50ABBDA51925AB4100A911A9 /* CCQuadCommand.h in Headers */,
|
||||
50ABBD3A1925AB0000A911A9 /* CCAffineTransform.h in Headers */,
|
||||
|
@ -5628,6 +5663,7 @@
|
|||
5034CA40191D591100CE6051 /* ccShader_Position_uColor.vert in Headers */,
|
||||
50ABBEC21925AB6F00A911A9 /* CCValue.h in Headers */,
|
||||
50ABBECA1925AB6F00A911A9 /* firePngData.h in Headers */,
|
||||
B257B4511989D5E800D9A687 /* CCPrimitive.h in Headers */,
|
||||
50ABBE401925AB6F00A911A9 /* CCDataVisitor.h in Headers */,
|
||||
1A570064180BC5A10088DEC7 /* CCAction.h in Headers */,
|
||||
503DD8EC1926736A00CD74DD /* CCGLViewImpl.h in Headers */,
|
||||
|
@ -5802,6 +5838,7 @@
|
|||
50ABBDBC1925AB4100A911A9 /* CCTextureAtlas.h in Headers */,
|
||||
50ABBE541925AB6F00A911A9 /* CCEventDispatcher.h in Headers */,
|
||||
1A12775A18DFCC4F0005F345 /* CCTweenFunction.h in Headers */,
|
||||
B276EF601988D1D500CD400F /* CCVertexIndexData.h in Headers */,
|
||||
50ABBD5F1925AB0000A911A9 /* Vec3.h in Headers */,
|
||||
50ABBE921925AB6F00A911A9 /* CCPlatformMacros.h in Headers */,
|
||||
50ABBE821925AB6F00A911A9 /* CCEventType.h in Headers */,
|
||||
|
@ -5819,6 +5856,7 @@
|
|||
1A01C6A718F58F7500EFE3A6 /* CCNotificationCenter.h in Headers */,
|
||||
50ABBEDA1925AB6F00A911A9 /* ZipUtils.h in Headers */,
|
||||
50ABBDC01925AB4100A911A9 /* CCTextureCache.h in Headers */,
|
||||
B276EF641988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */,
|
||||
ED9C6A9718599AD8000A5232 /* CCNodeGrid.h in Headers */,
|
||||
50ABC0201926664800A911A9 /* CCThread.h in Headers */,
|
||||
1A01C69318F57BE800EFE3A6 /* CCDouble.h in Headers */,
|
||||
|
@ -6758,6 +6796,7 @@
|
|||
1A570065180BC5A10088DEC7 /* CCActionCamera.cpp in Sources */,
|
||||
50ABBEAB1925AB6F00A911A9 /* ccTypes.cpp in Sources */,
|
||||
1A570069180BC5A10088DEC7 /* CCActionCatmullRom.cpp in Sources */,
|
||||
B257B44E1989D5E800D9A687 /* CCPrimitive.cpp in Sources */,
|
||||
1A57006D180BC5A10088DEC7 /* CCActionEase.cpp in Sources */,
|
||||
1A570071180BC5A10088DEC7 /* CCActionGrid.cpp in Sources */,
|
||||
B37510761823AC9F00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */,
|
||||
|
@ -6776,6 +6815,7 @@
|
|||
3E9E80E9198639EF00FA95D0 /* CCAttachNode.cpp in Sources */,
|
||||
1A570098180BC5C10088DEC7 /* CCAtlasNode.cpp in Sources */,
|
||||
1A57009E180BC5D20088DEC7 /* CCNode.cpp in Sources */,
|
||||
B257B460198A353E00D9A687 /* CCPrimitiveCommand.cpp in Sources */,
|
||||
50ABBE651925AB6F00A911A9 /* CCEventListenerCustom.cpp in Sources */,
|
||||
B37510781823AC9F00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp in Sources */,
|
||||
50ABBE391925AB6F00A911A9 /* CCData.cpp in Sources */,
|
||||
|
@ -6820,6 +6860,7 @@
|
|||
1A570210180BCBF40088DEC7 /* CCProgressTimer.cpp in Sources */,
|
||||
50ABBDB51925AB4100A911A9 /* CCTexture2D.cpp in Sources */,
|
||||
1A570214180BCBF40088DEC7 /* CCRenderTexture.cpp in Sources */,
|
||||
B276EF651988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */,
|
||||
50ABBE411925AB6F00A911A9 /* CCDirector.cpp in Sources */,
|
||||
1A570221180BCC1A0088DEC7 /* CCParticleBatchNode.cpp in Sources */,
|
||||
1A570225180BCC1A0088DEC7 /* CCParticleExamples.cpp in Sources */,
|
||||
|
@ -6874,6 +6915,7 @@
|
|||
50ABBD481925AB0000A911A9 /* Mat4.cpp in Sources */,
|
||||
50ABBD8F1925AB4100A911A9 /* CCGLProgramCache.cpp in Sources */,
|
||||
50ABBD441925AB0000A911A9 /* CCVertex.cpp in Sources */,
|
||||
B276EF611988D1D500CD400F /* CCVertexIndexData.cpp in Sources */,
|
||||
503DD8F71926B0DB00CD74DD /* CCIMEDispatcher.cpp in Sources */,
|
||||
50ABBE751925AB6F00A911A9 /* CCEventListenerTouch.cpp in Sources */,
|
||||
50ABBE511925AB6F00A911A9 /* CCEventDispatcher.cpp in Sources */,
|
||||
|
@ -7063,20 +7105,24 @@
|
|||
1A01C6A518F58F7500EFE3A6 /* CCNotificationCenter.cpp in Sources */,
|
||||
ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */,
|
||||
1A01C68F18F57BE800EFE3A6 /* CCDictionary.cpp in Sources */,
|
||||
B276EF621988D1D500CD400F /* CCVertexIndexData.cpp in Sources */,
|
||||
50ABBE561925AB6F00A911A9 /* CCEventFocus.cpp in Sources */,
|
||||
503DD8E11926736A00CD74DD /* CCApplication.mm in Sources */,
|
||||
50ABC01A1926664800A911A9 /* CCSAXParser.cpp in Sources */,
|
||||
B2CC507C19776DD10041958E /* CCPhysicsJoint.cpp in Sources */,
|
||||
B2165EEA19921124000BE3E6 /* CCPrimitiveCommand.cpp in Sources */,
|
||||
503DD8EE1926736A00CD74DD /* CCImage.mm in Sources */,
|
||||
3EA47871195478E00068D9D1 /* CCBundleReader.cpp in Sources */,
|
||||
B37510811823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */,
|
||||
46A170FC1807CECB005B8026 /* CCPhysicsBody.cpp in Sources */,
|
||||
50ABBD941925AB4100A911A9 /* CCGLProgramState.cpp in Sources */,
|
||||
B257B44F1989D5E800D9A687 /* CCPrimitive.cpp in Sources */,
|
||||
50ABBE281925AB6F00A911A9 /* CCAutoreleasePool.cpp in Sources */,
|
||||
46A170FE1807CECB005B8026 /* CCPhysicsContact.cpp in Sources */,
|
||||
1A570062180BC5A10088DEC7 /* CCAction.cpp in Sources */,
|
||||
1A570066180BC5A10088DEC7 /* CCActionCamera.cpp in Sources */,
|
||||
3E9E80F2198639EF00FA95D0 /* CCSubMeshState.cpp in Sources */,
|
||||
B276EF661988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */,
|
||||
1A57006A180BC5A10088DEC7 /* CCActionCatmullRom.cpp in Sources */,
|
||||
1A57006E180BC5A10088DEC7 /* CCActionEase.cpp in Sources */,
|
||||
50ABBD8C1925AB4100A911A9 /* CCGLProgram.cpp in Sources */,
|
||||
|
|
|
@ -121,8 +121,10 @@ TMXLayer::TMXLayer()
|
|||
, _useAutomaticVertexZ(false)
|
||||
, _dirty(true)
|
||||
, _quadsDirty(true)
|
||||
, _vertexBuffer(nullptr)
|
||||
, _vData(nullptr)
|
||||
, _indexBuffer(nullptr)
|
||||
{
|
||||
_buffersVBO[0] = _buffersVBO[1] = 0;
|
||||
}
|
||||
|
||||
TMXLayer::~TMXLayer()
|
||||
|
@ -130,15 +132,10 @@ TMXLayer::~TMXLayer()
|
|||
CC_SAFE_RELEASE(_tileSet);
|
||||
CC_SAFE_RELEASE(_texture);
|
||||
CC_SAFE_DELETE_ARRAY(_tiles);
|
||||
if(glIsBuffer(_buffersVBO[0]))
|
||||
{
|
||||
glDeleteBuffers(1, &_buffersVBO[0]);
|
||||
}
|
||||
CC_SAFE_RELEASE(_vData);
|
||||
CC_SAFE_RELEASE(_vertexBuffer);
|
||||
CC_SAFE_RELEASE(_indexBuffer);
|
||||
|
||||
if(glIsBuffer(_buffersVBO[1]))
|
||||
{
|
||||
glDeleteBuffers(1, &_buffersVBO[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
|
||||
|
@ -156,43 +153,47 @@ void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
|
|||
|
||||
updateTiles(rect);
|
||||
updateIndexBuffer();
|
||||
updatePrimitives();
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
if(_renderCommands.size() < _indicesVertexZNumber.size())
|
||||
if(_renderCommands.size() < _primitives.size())
|
||||
{
|
||||
_renderCommands.resize(_indicesVertexZNumber.size());
|
||||
_renderCommands.resize(_primitives.size());
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for(const auto& iter : _indicesVertexZNumber)
|
||||
// for(const auto& iter : _indicesVertexZNumber)
|
||||
// {
|
||||
// auto& cmd = _renderCommands[index++];
|
||||
//
|
||||
// cmd.init(iter.first);
|
||||
// cmd.func = CC_CALLBACK_0(TMXLayer::onDraw, this, _indicesVertexZOffsets[iter.first], iter.second);
|
||||
// renderer->addCommand(&cmd);
|
||||
// }
|
||||
for(const auto& iter : _primitives)
|
||||
{
|
||||
auto& cmd = _renderCommands[index++];
|
||||
|
||||
cmd.init(iter.first);
|
||||
cmd.func = CC_CALLBACK_0(TMXLayer::onDraw, this, _indicesVertexZOffsets[iter.first], iter.second);
|
||||
renderer->addCommand(&cmd);
|
||||
if(iter.second->getCount() > 0)
|
||||
{
|
||||
auto& cmd = _renderCommands[index++];
|
||||
//cmd.init(iter.first);
|
||||
//cmd.func = CC_CALLBACK_0(TMXLayer::onDraw, this, iter.second);
|
||||
cmd.init(iter.first, _texture->getName(), getGLProgramState(), BlendFunc::ALPHA_NON_PREMULTIPLIED, iter.second, _modelViewTransform);
|
||||
renderer->addCommand(&cmd);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TMXLayer::onDraw(int offset, int count)
|
||||
void TMXLayer::onDraw(Primitive *primitive)
|
||||
{
|
||||
GL::bindTexture2D(_texture->getName());
|
||||
getGLProgramState()->apply(_modelViewTransform);
|
||||
|
||||
GL::bindVAO(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
|
||||
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*)0);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_T2F, colors));
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_T2F, texCoords));
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)count * 6, GL_UNSIGNED_INT, (GLvoid*)(offset * 6 * sizeof(int)));
|
||||
primitive->draw();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, count * 4);
|
||||
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, primitive->getCount() * 4);
|
||||
}
|
||||
|
||||
void TMXLayer::updateTiles(const Rect& culledRect)
|
||||
|
@ -291,25 +292,32 @@ void TMXLayer::updateTiles(const Rect& culledRect)
|
|||
void TMXLayer::updateVertexBuffer()
|
||||
{
|
||||
GL::bindVAO(0);
|
||||
if(!glIsBuffer(_buffersVBO[0]))
|
||||
if(nullptr == _vData)
|
||||
{
|
||||
glGenBuffers(1, &_buffersVBO[0]);
|
||||
_vertexBuffer = VertexBuffer::create(sizeof(V3F_C4B_T2F), (int)_totalQuads.size() * 4);
|
||||
_vData = VertexData::create();
|
||||
_vData->setStream(_vertexBuffer, VertexStreamAttribute(0, GLProgram::VERTEX_ATTRIB_POSITION, GL_FLOAT, 3));
|
||||
_vData->setStream(_vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, colors), GLProgram::VERTEX_ATTRIB_COLOR, GL_UNSIGNED_BYTE, 4, true));
|
||||
_vData->setStream(_vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, texCoords), GLProgram::VERTEX_ATTRIB_TEX_COORD, GL_FLOAT, 2));
|
||||
CC_SAFE_RETAIN(_vData);
|
||||
CC_SAFE_RETAIN(_vertexBuffer);
|
||||
}
|
||||
if(_vertexBuffer)
|
||||
{
|
||||
_vertexBuffer->updateVertices((void*)&_totalQuads[0], (int)_totalQuads.size() * 4, 0);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B_T2F_Quad) * _totalQuads.size(), (GLvoid*)&_totalQuads[0], GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void TMXLayer::updateIndexBuffer()
|
||||
{
|
||||
if(!glIsBuffer(_buffersVBO[1]))
|
||||
if(nullptr == _indexBuffer)
|
||||
{
|
||||
glGenBuffers(1, &_buffersVBO[1]);
|
||||
_indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_UINT_32, (int)_indices.size());
|
||||
CC_SAFE_RETAIN(_indexBuffer);
|
||||
}
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * _indices.size(), &_indices[0], GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
_indexBuffer->updateIndices(&_indices[0], (int)_indices.size(), 0);
|
||||
|
||||
}
|
||||
|
||||
// FastTMXLayer - setup Tiles
|
||||
|
@ -405,6 +413,29 @@ Mat4 TMXLayer::tileToNodeTransform()
|
|||
|
||||
}
|
||||
|
||||
void TMXLayer::updatePrimitives()
|
||||
{
|
||||
for(const auto& iter : _indicesVertexZNumber)
|
||||
{
|
||||
int start = _indicesVertexZOffsets.at(iter.first);
|
||||
|
||||
auto primitiveIter= _primitives.find(iter.first);
|
||||
if(primitiveIter == _primitives.end())
|
||||
{
|
||||
auto primitive = Primitive::create(_vData, _indexBuffer, GL_TRIANGLES);
|
||||
primitive->setCount(iter.second * 6);
|
||||
primitive->setStart(start * 6);
|
||||
|
||||
_primitives.insert(iter.first, primitive);
|
||||
}
|
||||
else
|
||||
{
|
||||
primitiveIter->second->setCount(iter.second * 6);
|
||||
primitiveIter->second->setStart(start * 6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TMXLayer::updateTotalQuads()
|
||||
{
|
||||
if(_quadsDirty)
|
||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
|||
#include "CCNode.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCPrimitiveCommand.h"
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
@ -199,12 +200,12 @@ protected:
|
|||
//
|
||||
void updateTotalQuads();
|
||||
|
||||
void onDraw(int offset, int count);
|
||||
|
||||
void onDraw(Primitive* primitive);
|
||||
inline int getTileIndexByPos(int x, int y) const { return x + y * (int) _layerSize.width; }
|
||||
|
||||
void updateVertexBuffer();
|
||||
void updateIndexBuffer();
|
||||
void updatePrimitives();
|
||||
protected:
|
||||
|
||||
//! name of the layer
|
||||
|
@ -228,7 +229,7 @@ protected:
|
|||
/** container for sprite children. map<index, pair<sprite, gid> > */
|
||||
std::map<int, std::pair<Sprite*, int> > _spriteContainer;
|
||||
|
||||
GLuint _buffersVBO[2]; //0: vertex, 1: indices
|
||||
//GLuint _buffersVBO; //0: vertex, 1: indices
|
||||
|
||||
Size _screenGridSize;
|
||||
Rect _screenGridRect;
|
||||
|
@ -246,9 +247,17 @@ protected:
|
|||
std::vector<int> _indices;
|
||||
std::map<int/*vertexZ*/, int/*offset to _indices by quads*/> _indicesVertexZOffsets;
|
||||
std::unordered_map<int/*vertexZ*/, int/*number to quads*/> _indicesVertexZNumber;
|
||||
std::vector<CustomCommand> _renderCommands;
|
||||
std::vector<PrimitiveCommand> _renderCommands;
|
||||
bool _dirty;
|
||||
|
||||
VertexBuffer* _vertexBuffer;
|
||||
|
||||
VertexData* _vData;
|
||||
|
||||
IndexBuffer* _indexBuffer;
|
||||
|
||||
Map<int , Primitive*> _primitives;
|
||||
|
||||
public:
|
||||
/** Possible orientations of the TMX map */
|
||||
static const int FAST_TMX_ORIENTATION_ORTHO;
|
||||
|
|
|
@ -167,6 +167,10 @@ renderer/CCTextureAtlas.cpp \
|
|||
renderer/CCTextureCache.cpp \
|
||||
renderer/ccGLStateCache.cpp \
|
||||
renderer/ccShaders.cpp \
|
||||
renderer/CCVertexIndexBuffer.cpp \
|
||||
renderer/CCVertexIndexData.cpp \
|
||||
renderer/CCPrimitive.cpp \
|
||||
renderer/CCPrimitiveCommand.cpp \
|
||||
deprecated/CCArray.cpp \
|
||||
deprecated/CCSet.cpp \
|
||||
deprecated/CCString.cpp \
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "renderer/CCPrimitive.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Primitive* Primitive::create(VertexData* verts, IndexBuffer* indices, int type)
|
||||
{
|
||||
auto result = new (std::nothrow) Primitive();
|
||||
if( result && result->init(verts, indices, type))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VertexData* Primitive::getVertexData()
|
||||
{
|
||||
return _verts;
|
||||
}
|
||||
|
||||
IndexBuffer* Primitive::getIndexData()
|
||||
{
|
||||
return _indices;
|
||||
}
|
||||
|
||||
Primitive::Primitive()
|
||||
: _verts(nullptr)
|
||||
, _indices(nullptr)
|
||||
, _type(GL_POINTS)
|
||||
{
|
||||
}
|
||||
|
||||
Primitive::~Primitive()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_verts);
|
||||
CC_SAFE_RELEASE_NULL(_indices);
|
||||
}
|
||||
|
||||
bool Primitive::init(VertexData* verts, IndexBuffer* indices, int type)
|
||||
{
|
||||
if( nullptr == verts ) return false;
|
||||
if(verts != _verts)
|
||||
{
|
||||
CC_SAFE_RELEASE(_verts);
|
||||
CC_SAFE_RETAIN(verts);
|
||||
_verts = verts;
|
||||
}
|
||||
|
||||
if(indices != _indices)
|
||||
{
|
||||
CC_SAFE_RETAIN(indices);
|
||||
CC_SAFE_RELEASE(_indices);
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
_type = type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Primitive::draw()
|
||||
{
|
||||
if(_verts && _indices)
|
||||
{
|
||||
_verts->use();
|
||||
if(_indices!= nullptr)
|
||||
{
|
||||
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||
glDrawElements((GLenum)_type, _count, type, (GLvoid*)(_start * _indices->getSizePerIndex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays((GLenum)_type, _count, _start);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,67 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PRIMITIVE_H__
|
||||
#define __CC_PRIMITIVE_H__
|
||||
|
||||
#include "renderer/CCVertexIndexData.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Primitive : public Ref
|
||||
{
|
||||
public:
|
||||
static Primitive* create(VertexData* verts, IndexBuffer* indices, int type);
|
||||
|
||||
VertexData* getVertexData();
|
||||
|
||||
IndexBuffer* getIndexData();
|
||||
|
||||
int getType() const { return _type; }
|
||||
|
||||
//called by rendering framework
|
||||
void draw();
|
||||
|
||||
int getStart() const { return _start; }
|
||||
int getCount() const { return _count; }
|
||||
void setStart(int start) { _start = start; }
|
||||
void setCount(int count) { _count = count; }
|
||||
|
||||
protected:
|
||||
Primitive();
|
||||
virtual ~Primitive();
|
||||
|
||||
bool init(VertexData* verts, IndexBuffer* indices, int type);
|
||||
|
||||
protected:
|
||||
VertexData* _verts;
|
||||
IndexBuffer* _indices;
|
||||
int _start;
|
||||
int _count;
|
||||
int _type;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CC_PRIMITIVE_H__
|
|
@ -0,0 +1,82 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "renderer/CCPrimitiveCommand.h"
|
||||
|
||||
#include "renderer/ccGLStateCache.h"
|
||||
#include "renderer/CCGLProgram.h"
|
||||
#include "renderer/CCGLProgramState.h"
|
||||
#include "xxhash.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PrimitiveCommand::PrimitiveCommand()
|
||||
: _materialID(0)
|
||||
, _textureID(0)
|
||||
, _glProgramState(nullptr)
|
||||
, _blendType(BlendFunc::DISABLE)
|
||||
, _primitive(nullptr)
|
||||
{
|
||||
_type = RenderCommand::Type::PRIMITIVE_COMMAND;
|
||||
}
|
||||
|
||||
PrimitiveCommand::~PrimitiveCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void PrimitiveCommand::init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, Primitive* primitive,const Mat4& mv)
|
||||
{
|
||||
CCASSERT(glProgramState, "Invalid GLProgramState");
|
||||
CCASSERT(glProgramState->getVertexAttribsFlags() == 0, "No custom attributes are supported in PrimitiveCommand");
|
||||
CCASSERT(primitive != nullptr, "Could not render null primitive");
|
||||
|
||||
_globalOrder = globalOrder;
|
||||
|
||||
_primitive = primitive;
|
||||
|
||||
_mv = mv;
|
||||
|
||||
if( _textureID != textureID || _blendType.src != blendType.src || _blendType.dst != blendType.dst || _glProgramState != glProgramState) {
|
||||
|
||||
_textureID = textureID;
|
||||
_blendType = blendType;
|
||||
_glProgramState = glProgramState;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void PrimitiveCommand::execute() const
|
||||
{
|
||||
//Set texture
|
||||
GL::bindTexture2D(_textureID);
|
||||
|
||||
//set blend mode
|
||||
GL::blendFunc(_blendType.src, _blendType.dst);
|
||||
|
||||
_glProgramState->apply(_mv);
|
||||
|
||||
_primitive->draw();
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,60 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CC_PRIMITIVE_COMMAND_H__
|
||||
#define _CC_PRIMITIVE_COMMAND_H__
|
||||
|
||||
#include "renderer/CCPrimitive.h"
|
||||
#include "renderer/CCRenderCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
class GLProgramState;
|
||||
class PrimitiveCommand : public RenderCommand
|
||||
{
|
||||
public:
|
||||
PrimitiveCommand();
|
||||
~PrimitiveCommand();
|
||||
|
||||
void init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, Primitive* primitive,const Mat4& mv);
|
||||
|
||||
inline uint32_t getMaterialID() const { return _materialID; }
|
||||
inline GLuint getTextureID() const { return _textureID; }
|
||||
inline GLProgramState* getGLProgramState() const { return _glProgramState; }
|
||||
inline BlendFunc getBlendType() const { return _blendType; }
|
||||
inline const Mat4& getModelView() const { return _mv; }
|
||||
|
||||
void execute() const;
|
||||
protected:
|
||||
|
||||
uint32_t _materialID;
|
||||
GLuint _textureID;
|
||||
GLProgramState* _glProgramState;
|
||||
BlendFunc _blendType;
|
||||
Primitive* _primitive;
|
||||
Mat4 _mv;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_PRIMITIVE_COMMAND_H__
|
|
@ -49,6 +49,7 @@ public:
|
|||
BATCH_COMMAND,
|
||||
GROUP_COMMAND,
|
||||
MESH_COMMAND,
|
||||
PRIMITIVE_COMMAND,
|
||||
};
|
||||
|
||||
/** Get Render Command Id */
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "renderer/CCBatchCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCPrimitiveCommand.h"
|
||||
#include "renderer/CCGLProgramCache.h"
|
||||
#include "renderer/ccGLStateCache.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
|
@ -321,6 +322,12 @@ void Renderer::visitRenderQueue(const RenderQueue& queue)
|
|||
auto cmd = static_cast<BatchCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else if(RenderCommand::Type::PRIMITIVE_COMMAND == commandType)
|
||||
{
|
||||
flush();
|
||||
auto cmd = static_cast<PrimitiveCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else if (RenderCommand::Type::MESH_COMMAND == commandType)
|
||||
{
|
||||
flush2D();
|
||||
|
|
|
@ -0,0 +1,362 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "renderer/CCVertexIndexBuffer.h"
|
||||
#include "base/CCEventType.h"
|
||||
#include "base/CCEventListenerCustom.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
bool VertexBuffer::_enableShadowCopy = true;
|
||||
#else
|
||||
bool VertexBuffer::_enableShadowCopy = false;
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
bool IndexBuffer::_enableShadowCopy = true;
|
||||
#else
|
||||
bool IndexBuffer::_enableShadowCopy = false;
|
||||
#endif
|
||||
|
||||
VertexBuffer* VertexBuffer::create(int sizePerVertex, int vertexNumber)
|
||||
{
|
||||
auto result = new (std::nothrow) VertexBuffer();
|
||||
if(result && result->init(sizePerVertex, vertexNumber))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer()
|
||||
: _vbo(0)
|
||||
, _vertexNumber(0)
|
||||
, _sizePerVertex(0)
|
||||
{
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_COME_TO_BACKGROUND, CC_CALLBACK_1(VertexBuffer::listenToBackground, this));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
if(glIsBuffer(_vbo))
|
||||
{
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
_vbo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool VertexBuffer::init(int sizePerVertex, int vertexNumber)
|
||||
{
|
||||
if(0 == sizePerVertex || 0 == vertexNumber)
|
||||
return false;
|
||||
_sizePerVertex = sizePerVertex;
|
||||
_vertexNumber = vertexNumber;
|
||||
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
_shadowCopy.resize(sizePerVertex * _vertexNumber);
|
||||
}
|
||||
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, getSize(), nullptr, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
int VertexBuffer::getSizePerVertex() const
|
||||
{
|
||||
return _sizePerVertex;
|
||||
}
|
||||
|
||||
int VertexBuffer::getVertexNumber() const
|
||||
{
|
||||
return _vertexNumber;
|
||||
}
|
||||
|
||||
bool VertexBuffer::updateVertices(const void* verts, int count, int begin)
|
||||
{
|
||||
if(count <= 0 || nullptr == verts) return false;
|
||||
|
||||
if(begin < 0)
|
||||
{
|
||||
CCLOGERROR("Update vertices with begin = %d, will set begin to 0", begin);
|
||||
begin = 0;
|
||||
}
|
||||
|
||||
if(count + begin > _vertexNumber)
|
||||
{
|
||||
CCLOGERROR("updated vertices exceed the max size of vertex buffer, will set count to _vertexNumber-begin");
|
||||
count = _vertexNumber - begin;
|
||||
}
|
||||
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
memcpy(&_shadowCopy[begin * _sizePerVertex], verts, count * _sizePerVertex);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, begin * _sizePerVertex, count * _sizePerVertex, verts);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VertexBuffer::listenToBackground(EventCustom *event)
|
||||
{
|
||||
if(glIsBuffer(_vbo))
|
||||
{
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
_vbo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint VertexBuffer::getVBO() const
|
||||
{
|
||||
if(0 == _vbo)
|
||||
{
|
||||
recreateVBO();
|
||||
}
|
||||
return _vbo;
|
||||
}
|
||||
|
||||
void VertexBuffer::recreateVBO() const
|
||||
{
|
||||
CCLOG("come to foreground of VertexBuffer");
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
const void* buffer = nullptr;
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
buffer = &_shadowCopy[0];
|
||||
}
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, _sizePerVertex * _vertexNumber, buffer, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
if(!glIsBuffer(_vbo))
|
||||
{
|
||||
CCLOGERROR("recreate VertexBuffer Error");
|
||||
}
|
||||
}
|
||||
|
||||
//bool VertexBuffer::getVertices(void* verts, int count, int begin) const
|
||||
//{
|
||||
// if(count <= 0 || nullptr == verts) return false;
|
||||
//
|
||||
// if(begin < 0)
|
||||
// {
|
||||
// CCLOGERROR("get vertices with begin = %d, will set begin to 0", begin);
|
||||
// begin = 0;
|
||||
// }
|
||||
//
|
||||
// if(count + begin > _vertexNumber)
|
||||
// {
|
||||
// CCLOGERROR("get vertices exceed the max size of vertex buffer, will set count to _vertexNumber-begin");
|
||||
// count = _vertexNumber - begin;
|
||||
// }
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
// GLvoid* data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
// memcpy(verts, ((char*)data) + begin * _sizePerVertex, count * _sizePerVertex);
|
||||
// glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
int VertexBuffer::getSize() const
|
||||
{
|
||||
return _sizePerVertex * _vertexNumber;
|
||||
}
|
||||
|
||||
IndexBuffer* IndexBuffer::create(IndexType type, int number)
|
||||
{
|
||||
auto result = new (std::nothrow) IndexBuffer();
|
||||
if(result && result->init(type, number))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IndexBuffer::IndexBuffer()
|
||||
: _vbo(0)
|
||||
, _type(IndexType::INDEX_TYPE_SHORT_16)
|
||||
, _indexNumber(0)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_COME_TO_BACKGROUND, CC_CALLBACK_1(IndexBuffer::listenToBackground, this));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
IndexBuffer::~IndexBuffer()
|
||||
{
|
||||
if(glIsBuffer(_vbo))
|
||||
{
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
_vbo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool IndexBuffer::init(IndexBuffer::IndexType type, int number)
|
||||
{
|
||||
if(number <=0 ) return false;
|
||||
|
||||
_type = type;
|
||||
_indexNumber = number;
|
||||
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, getSize(), nullptr, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
_shadowCopy.resize(getSize());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IndexBuffer::IndexType IndexBuffer::getType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
int IndexBuffer::getSizePerIndex() const
|
||||
{
|
||||
return IndexType::INDEX_TYPE_SHORT_16 == _type ? 2 : 4;
|
||||
}
|
||||
|
||||
int IndexBuffer::getIndexNumber() const
|
||||
{
|
||||
return _indexNumber;
|
||||
}
|
||||
|
||||
bool IndexBuffer::updateIndices(const void* indices, int count, int begin)
|
||||
{
|
||||
if(count <= 0 || nullptr == indices) return false;
|
||||
|
||||
if(begin < 0)
|
||||
{
|
||||
CCLOGERROR("Update indices with begin = %d, will set begin to 0", begin);
|
||||
begin = 0;
|
||||
}
|
||||
|
||||
if(count + begin > _indexNumber)
|
||||
{
|
||||
CCLOGERROR("updated indices exceed the max size of vertex buffer, will set count to _indexNumber-begin");
|
||||
count = _indexNumber - begin;
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo);
|
||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, begin * getSizePerIndex(), count * getSizePerIndex(), indices);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
memcpy(&_shadowCopy[begin * getSizePerIndex()], indices, count * getSizePerIndex());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//bool IndexBuffer::getIndices(void* indices, int count, int begin)
|
||||
//{
|
||||
// if(count <= 0 || nullptr == indices) return false;
|
||||
//
|
||||
// if(begin < 0)
|
||||
// {
|
||||
// CCLOGERROR("get indices with begin = %d, will set begin to 0", begin);
|
||||
// begin = 0;
|
||||
// }
|
||||
//
|
||||
// if(count + begin > _indexNumber)
|
||||
// {
|
||||
// CCLOGERROR("get indices exceed the max size of vertex buffer, will set count to _indexNumber-begin");
|
||||
// count = _indexNumber - begin;
|
||||
// }
|
||||
//
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo);
|
||||
// GLvoid* data = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
// memcpy(indices, ((char*)data) + begin * getSizePerIndex(), count * getSizePerIndex());
|
||||
// glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
int IndexBuffer::getSize() const
|
||||
{
|
||||
return getSizePerIndex() * _indexNumber;
|
||||
}
|
||||
|
||||
void IndexBuffer::listenToBackground(EventCustom *event)
|
||||
{
|
||||
if(glIsBuffer(_vbo))
|
||||
{
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
_vbo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint IndexBuffer::getVBO() const
|
||||
{
|
||||
if(0 == _vbo)
|
||||
{
|
||||
recreateVBO();
|
||||
}
|
||||
|
||||
return _vbo;
|
||||
}
|
||||
|
||||
void IndexBuffer::recreateVBO() const
|
||||
{
|
||||
CCLOG("come to foreground of IndexBuffer");
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
const void* buffer = nullptr;
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
buffer = &_shadowCopy[0];
|
||||
}
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, getSize(), buffer, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
if(!glIsBuffer(_vbo))
|
||||
{
|
||||
CCLOGERROR("recreate IndexBuffer Error");
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,119 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_VERTEX_INDEX_BUFFER_H__
|
||||
#define __CC_VERTEX_INDEX_BUFFER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "base/CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class VertexBuffer : public Ref
|
||||
{
|
||||
public:
|
||||
static VertexBuffer* create(int sizePerVertex, int vertexNumber);
|
||||
|
||||
int getSizePerVertex() const;
|
||||
int getVertexNumber() const;
|
||||
bool updateVertices(const void* verts, int count, int begin);
|
||||
//bool getVertices(void* verts, int count, int begin) const;
|
||||
|
||||
int getSize() const;
|
||||
|
||||
GLuint getVBO() const;
|
||||
|
||||
protected:
|
||||
VertexBuffer();
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
bool init(int sizePerVertex, int vertexNumber);
|
||||
protected:
|
||||
//event listener for foreground and background
|
||||
void listenToBackground(EventCustom *event);
|
||||
void recreateVBO() const;
|
||||
protected:
|
||||
mutable GLuint _vbo;
|
||||
int _sizePerVertex;
|
||||
int _vertexNumber;
|
||||
//buffer used for shadow copy
|
||||
std::vector<unsigned char> _shadowCopy;
|
||||
protected:
|
||||
static bool _enableShadowCopy;
|
||||
public:
|
||||
static bool isShadowCopyEnabled() { return _enableShadowCopy; }
|
||||
static void enableShadowCopy(bool enabled) { _enableShadowCopy = enabled; }
|
||||
};
|
||||
|
||||
class IndexBuffer : public Ref
|
||||
{
|
||||
public:
|
||||
enum class IndexType
|
||||
{
|
||||
INDEX_TYPE_SHORT_16,
|
||||
INDEX_TYPE_UINT_32
|
||||
};
|
||||
|
||||
public:
|
||||
static IndexBuffer* create(IndexType type, int number);
|
||||
|
||||
IndexType getType() const;
|
||||
int getSizePerIndex() const;
|
||||
int getIndexNumber() const;
|
||||
bool updateIndices(const void* indices, int count, int begin);
|
||||
//bool getIndices(void* indices, int count, int begin);
|
||||
|
||||
int getSize() const;
|
||||
|
||||
GLuint getVBO() const;
|
||||
|
||||
protected:
|
||||
IndexBuffer();
|
||||
virtual ~IndexBuffer();
|
||||
|
||||
bool init(IndexType type, int number);
|
||||
|
||||
protected:
|
||||
mutable GLuint _vbo;
|
||||
IndexType _type;
|
||||
int _indexNumber;
|
||||
|
||||
protected:
|
||||
//event listener for foreground and background
|
||||
void listenToBackground(EventCustom *event);
|
||||
void recreateVBO() const;
|
||||
|
||||
//buffer used for shadow copy
|
||||
std::vector<unsigned char> _shadowCopy;
|
||||
protected:
|
||||
static bool _enableShadowCopy;
|
||||
public:
|
||||
static bool isShadowCopyEnabled() { return _enableShadowCopy; }
|
||||
static void enableShadowCopy(bool enabled) { _enableShadowCopy = enabled; }
|
||||
};
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* __CC_VERTEX_INDEX_BUFFER_H__*/
|
|
@ -0,0 +1,132 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "renderer/CCVertexIndexData.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
VertexData* VertexData::create()
|
||||
{
|
||||
VertexData* result = new (std::nothrow) VertexData();
|
||||
if(result)
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(result);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t VertexData::getVertexStreamCount() const
|
||||
{
|
||||
return _vertexStreams.size();
|
||||
}
|
||||
|
||||
bool VertexData::setStream(VertexBuffer* buffer, const VertexStreamAttribute& stream)
|
||||
{
|
||||
if( buffer == nullptr ) return false;
|
||||
auto iter = _vertexStreams.find(stream._semantic);
|
||||
if(iter == _vertexStreams.end())
|
||||
{
|
||||
buffer->retain();
|
||||
auto& bufferAttribute = _vertexStreams[stream._semantic];
|
||||
bufferAttribute._buffer = buffer;
|
||||
bufferAttribute._stream = stream;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->retain();
|
||||
iter->second._buffer->release();
|
||||
iter->second._stream = stream;
|
||||
iter->second._buffer = buffer;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VertexData::removeStream(int semantic)
|
||||
{
|
||||
auto iter = _vertexStreams.find(semantic);
|
||||
if(iter != _vertexStreams.end())
|
||||
{
|
||||
iter->second._buffer->release();
|
||||
_vertexStreams.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
const VertexStreamAttribute* VertexData::getStreamAttribute(int semantic) const
|
||||
{
|
||||
auto iter = _vertexStreams.find(semantic);
|
||||
if(iter == _vertexStreams.end()) return nullptr;
|
||||
else return &iter->second._stream;
|
||||
}
|
||||
|
||||
VertexStreamAttribute* VertexData::getStreamAttribute(int semantic)
|
||||
{
|
||||
auto iter = _vertexStreams.find(semantic);
|
||||
if(iter == _vertexStreams.end()) return nullptr;
|
||||
else return &iter->second._stream;
|
||||
}
|
||||
|
||||
VertexBuffer* VertexData::getStreamBuffer(int semantic) const
|
||||
{
|
||||
auto iter = _vertexStreams.find(semantic);
|
||||
if(iter == _vertexStreams.end()) return nullptr;
|
||||
else return iter->second._buffer;
|
||||
}
|
||||
|
||||
VertexData::VertexData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
VertexData::~VertexData()
|
||||
{
|
||||
for(auto& element : _vertexStreams)
|
||||
{
|
||||
element.second._buffer->release();
|
||||
}
|
||||
_vertexStreams.clear();
|
||||
}
|
||||
|
||||
void VertexData::use()
|
||||
{
|
||||
uint32_t flags;
|
||||
for(auto& element : _vertexStreams)
|
||||
{
|
||||
flags = flags | (1 << element.second._stream._semantic);
|
||||
}
|
||||
|
||||
GL::enableVertexAttribs(flags);
|
||||
|
||||
for(auto& element : _vertexStreams)
|
||||
{
|
||||
//glEnableVertexAttribArray((GLint)element.second._stream._semantic);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, element.second._buffer->getVBO());
|
||||
glVertexAttribPointer(GLint(element.second._stream._semantic),element.second._stream._size,
|
||||
element.second._stream._type,element.second._stream._normalize, element.second._buffer->getSizePerVertex(), (GLvoid*)element.second._stream._offset);
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,90 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_VERTEX_INDEX_DATA_H__
|
||||
#define __CC_VERTEX_INDEX_DATA_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "renderer/CCVertexIndexBuffer.h"
|
||||
#include "base/CCMap.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class VertexBuffer;
|
||||
|
||||
struct VertexStreamAttribute
|
||||
{
|
||||
VertexStreamAttribute()
|
||||
: _offset(0),_semantic(0),_type(0),_size(0), _normalize(false)
|
||||
{
|
||||
}
|
||||
|
||||
VertexStreamAttribute(int offset, int semantic, int type, int size)
|
||||
: _offset(offset),_semantic(semantic),_type(type),_size(size), _normalize(false)
|
||||
{
|
||||
}
|
||||
|
||||
VertexStreamAttribute(int offset, int semantic, int type, int size, bool normalize)
|
||||
: _offset(offset),_semantic(semantic),_type(type),_size(size), _normalize(normalize)
|
||||
{
|
||||
}
|
||||
|
||||
bool _normalize;
|
||||
int _offset;
|
||||
int _semantic;
|
||||
int _type;
|
||||
int _size;
|
||||
};
|
||||
|
||||
class VertexData : public Ref
|
||||
{
|
||||
public:
|
||||
static VertexData* create();
|
||||
|
||||
size_t getVertexStreamCount() const;
|
||||
bool setStream(VertexBuffer* buffer, const VertexStreamAttribute& stream);
|
||||
void removeStream(int semantic);
|
||||
const VertexStreamAttribute* getStreamAttribute(int semantic) const;
|
||||
VertexStreamAttribute* getStreamAttribute(int semantic);
|
||||
|
||||
VertexBuffer* getStreamBuffer(int semantic) const;
|
||||
|
||||
void use();
|
||||
protected:
|
||||
VertexData();
|
||||
virtual ~VertexData();
|
||||
protected:
|
||||
struct BufferAttribute
|
||||
{
|
||||
VertexBuffer* _buffer;
|
||||
VertexStreamAttribute _stream;
|
||||
};
|
||||
|
||||
std::map<int, BufferAttribute> _vertexStreams;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CC_VERTEX_INDEX_DATA_H__
|
|
@ -15,4 +15,8 @@ set(COCOS_RENDERER_SRC
|
|||
renderer/CCTexture2D.cpp
|
||||
renderer/CCTextureAtlas.cpp
|
||||
renderer/CCTextureCache.cpp
|
||||
renderer/CCVertexIndexBuffer.cpp
|
||||
renderer/CCVertexIndexData.cpp
|
||||
renderer/CCPrimitive.cpp
|
||||
renderer/CCPrimitiveCommand.cpp
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue