mirror of https://github.com/axmolengine/axmol.git
put TrianglesCommand in a seperate file
This commit is contained in:
parent
08006aa47a
commit
06eb6c2425
|
@ -1809,6 +1809,10 @@
|
|||
B21770471977ED34009EE11B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B21770461977ED34009EE11B /* QuartzCore.framework */; };
|
||||
B21770491977ED4C009EE11B /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B21770481977ED4C009EE11B /* libz.dylib */; };
|
||||
B217704E1977ED9F009EE11B /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B217704C1977ED8B009EE11B /* libsqlite3.dylib */; };
|
||||
B230ED7119B417AE00364AA8 /* CCTrianglesCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B230ED6F19B417AE00364AA8 /* CCTrianglesCommand.cpp */; };
|
||||
B230ED7219B417AE00364AA8 /* CCTrianglesCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B230ED6F19B417AE00364AA8 /* CCTrianglesCommand.cpp */; };
|
||||
B230ED7319B417AE00364AA8 /* CCTrianglesCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */; };
|
||||
B230ED7419B417AE00364AA8 /* CCTrianglesCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */; };
|
||||
B24AA985195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B24AA981195A675C007B4522 /* CCFastTMXLayer.cpp */; };
|
||||
B24AA986195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B24AA981195A675C007B4522 /* CCFastTMXLayer.cpp */; };
|
||||
B24AA987195A675C007B4522 /* CCFastTMXLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = B24AA982195A675C007B4522 /* CCFastTMXLayer.h */; };
|
||||
|
@ -2843,6 +2847,8 @@
|
|||
B21770481977ED4C009EE11B /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
|
||||
B217704A1977ED55009EE11B /* libcurl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.dylib; path = usr/lib/libcurl.dylib; sourceTree = SDKROOT; };
|
||||
B217704C1977ED8B009EE11B /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
|
||||
B230ED6F19B417AE00364AA8 /* CCTrianglesCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTrianglesCommand.cpp; sourceTree = "<group>"; };
|
||||
B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTrianglesCommand.h; sourceTree = "<group>"; };
|
||||
B24AA981195A675C007B4522 /* CCFastTMXLayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCFastTMXLayer.cpp; sourceTree = "<group>"; };
|
||||
B24AA982195A675C007B4522 /* CCFastTMXLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCFastTMXLayer.h; sourceTree = "<group>"; };
|
||||
B24AA983195A675C007B4522 /* CCFastTMXTiledMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCFastTMXTiledMap.cpp; sourceTree = "<group>"; };
|
||||
|
@ -4599,6 +4605,8 @@
|
|||
50ABBD731925AB4100A911A9 /* CCGroupCommand.h */,
|
||||
B29594B21926D5EC003EEF37 /* CCMeshCommand.cpp */,
|
||||
B29594B31926D5EC003EEF37 /* CCMeshCommand.h */,
|
||||
B230ED6F19B417AE00364AA8 /* CCTrianglesCommand.cpp */,
|
||||
B230ED7019B417AE00364AA8 /* CCTrianglesCommand.h */,
|
||||
50ABBD741925AB4100A911A9 /* CCQuadCommand.cpp */,
|
||||
50ABBD751925AB4100A911A9 /* CCQuadCommand.h */,
|
||||
50ABBD761925AB4100A911A9 /* CCRenderCommand.cpp */,
|
||||
|
@ -4993,6 +5001,7 @@
|
|||
15AE1BE519AAE01E00C27E9E /* CCTableView.h in Headers */,
|
||||
15AE1BD319AAE01E00C27E9E /* CCControlPotentiometer.h in Headers */,
|
||||
15AE1B6E19AADA9900C27E9E /* UIHelper.h in Headers */,
|
||||
B230ED7319B417AE00364AA8 /* CCTrianglesCommand.h in Headers */,
|
||||
15AE187F19AAD33D00C27E9E /* CCBKeyframe.h in Headers */,
|
||||
1A570073180BC5A10088DEC7 /* CCActionGrid.h in Headers */,
|
||||
15AE1BCC19AAE01E00C27E9E /* CCControlButton.h in Headers */,
|
||||
|
@ -5566,6 +5575,7 @@
|
|||
15AE181D19AAD2F700C27E9E /* CCBundle3D.h in Headers */,
|
||||
15AE192519AAD35100C27E9E /* CocoLoader.h in Headers */,
|
||||
15AE1BBB19AADFF000C27E9E /* HttpRequest.h in Headers */,
|
||||
B230ED7419B417AE00364AA8 /* CCTrianglesCommand.h in Headers */,
|
||||
15AE1A0019AAD3A700C27E9E /* AtlasAttachmentLoader.h in Headers */,
|
||||
15AE1ACB19AAD40300C27E9E /* b2MouseJoint.h in Headers */,
|
||||
50ABBD3F1925AB0000A911A9 /* CCGeometry.h in Headers */,
|
||||
|
@ -6246,6 +6256,7 @@
|
|||
15AE1A7819AAD40300C27E9E /* b2PolygonAndCircleContact.cpp in Sources */,
|
||||
15AE1A3419AAD3D500C27E9E /* b2EdgeShape.cpp in Sources */,
|
||||
15AE1BA319AADFDF00C27E9E /* UILayoutManager.cpp in Sources */,
|
||||
B230ED7119B417AE00364AA8 /* CCTrianglesCommand.cpp in Sources */,
|
||||
1A5702F2180BCE750088DEC7 /* CCTMXObjectGroup.cpp in Sources */,
|
||||
15AE1A5B19AAD40300C27E9E /* b2Timer.cpp in Sources */,
|
||||
15AE1B1219AAD43700C27E9E /* cpGearJoint.c in Sources */,
|
||||
|
@ -6438,6 +6449,7 @@
|
|||
50ABC0161926664800A911A9 /* CCImage.cpp in Sources */,
|
||||
1A01C6A518F58F7500EFE3A6 /* CCNotificationCenter.cpp in Sources */,
|
||||
15AE1BFB19AAE01E00C27E9E /* CCControlUtils.cpp in Sources */,
|
||||
B230ED7219B417AE00364AA8 /* CCTrianglesCommand.cpp in Sources */,
|
||||
15AE1B9019AADA9A00C27E9E /* UIWidget.cpp in Sources */,
|
||||
ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */,
|
||||
1A01C68F18F57BE800EFE3A6 /* CCDictionary.cpp in Sources */,
|
||||
|
|
|
@ -33,72 +33,6 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
TrianglesCommand::TrianglesCommand()
|
||||
:_materialID(0)
|
||||
,_textureID(0)
|
||||
,_glProgramState(nullptr)
|
||||
,_blendType(BlendFunc::DISABLE)
|
||||
{
|
||||
_type = RenderCommand::Type::TRIANGLES_COMMAND;
|
||||
}
|
||||
|
||||
void TrianglesCommand::init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, const Triangles& triangles,const Mat4& mv)
|
||||
{
|
||||
CCASSERT(glProgramState, "Invalid GLProgramState");
|
||||
CCASSERT(glProgramState->getVertexAttribsFlags() == 0, "No custom attributes are supported in QuadCommand");
|
||||
|
||||
_globalOrder = globalOrder;
|
||||
|
||||
_triangles = triangles;
|
||||
if(_triangles.indexCount % 3 != 0)
|
||||
{
|
||||
ssize_t count = _triangles.indexCount;
|
||||
_triangles.indexCount = count / 3 * 3;
|
||||
CCLOGERROR("Resize indexCount from %zd to %zd, size must be multiple times of 3", count, _triangles.indexCount);
|
||||
}
|
||||
_mv = mv;
|
||||
|
||||
if( _textureID != textureID || _blendType.src != blendType.src || _blendType.dst != blendType.dst || _glProgramState != glProgramState) {
|
||||
|
||||
_textureID = textureID;
|
||||
_blendType = blendType;
|
||||
_glProgramState = glProgramState;
|
||||
|
||||
generateMaterialID();
|
||||
}
|
||||
}
|
||||
|
||||
TrianglesCommand::~TrianglesCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void TrianglesCommand::generateMaterialID()
|
||||
{
|
||||
|
||||
if(_glProgramState->getUniformCount() > 0)
|
||||
{
|
||||
_materialID = TrianglesCommand::MATERIAL_ID_DO_NOT_BATCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
int glProgram = (int)_glProgramState->getGLProgram()->getProgram();
|
||||
int intArray[4] = { glProgram, (int)_textureID, (int)_blendType.src, (int)_blendType.dst};
|
||||
|
||||
_materialID = XXH32((const void*)intArray, sizeof(intArray), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TrianglesCommand::useMaterial() const
|
||||
{
|
||||
//Set texture
|
||||
GL::bindTexture2D(_textureID);
|
||||
|
||||
//set blend mode
|
||||
GL::blendFunc(_blendType.src, _blendType.dst);
|
||||
|
||||
_glProgramState->apply(_mv);
|
||||
}
|
||||
|
||||
QuadCommand::QuadCommand()
|
||||
:TrianglesCommand()
|
||||
,_quads(nullptr)
|
||||
|
|
|
@ -28,52 +28,9 @@
|
|||
#include "renderer/CCRenderCommand.h"
|
||||
#include "renderer/CCGLProgramState.h"
|
||||
#include "renderer/CCRenderCommandPool.h"
|
||||
#include "renderer/CCTrianglesCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
class CC_DLL TrianglesCommand : public RenderCommand
|
||||
{
|
||||
public:
|
||||
static const int MATERIAL_ID_DO_NOT_BATCH = 0;
|
||||
|
||||
public:
|
||||
struct Triangles
|
||||
{
|
||||
V3F_C4B_T2F* verts;
|
||||
unsigned short* indices;
|
||||
ssize_t vertCount;
|
||||
ssize_t indexCount;
|
||||
};
|
||||
|
||||
TrianglesCommand();
|
||||
~TrianglesCommand();
|
||||
|
||||
/** Initializes the command with a globalZOrder, a texture ID, a `GLProgram`, a blending function, a pointer to triangles,
|
||||
* quantity of quads, and the Model View transform to be used for the quads */
|
||||
void init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, const Triangles& triangles,const Mat4& mv);
|
||||
|
||||
void useMaterial() const;
|
||||
|
||||
inline uint32_t getMaterialID() const { return _materialID; }
|
||||
inline GLuint getTextureID() const { return _textureID; }
|
||||
inline const Triangles& getTriangles() const { return _triangles; }
|
||||
inline ssize_t getVertexCount() const { return _triangles.vertCount; }
|
||||
inline ssize_t getIndexCount() const { return _triangles.indexCount; }
|
||||
inline const V3F_C4B_T2F* getVertices() const { return _triangles.verts; }
|
||||
inline const unsigned short* getIndices() const { return _triangles.indices; }
|
||||
inline GLProgramState* getGLProgramState() const { return _glProgramState; }
|
||||
inline BlendFunc getBlendType() const { return _blendType; }
|
||||
inline const Mat4& getModelView() const { return _mv; }
|
||||
|
||||
protected:
|
||||
void generateMaterialID();
|
||||
|
||||
uint32_t _materialID;
|
||||
GLuint _textureID;
|
||||
GLProgramState* _glProgramState;
|
||||
BlendFunc _blendType;
|
||||
Triangles _triangles;
|
||||
Mat4 _mv;
|
||||
};
|
||||
|
||||
/** Command used to render one or more Quads */
|
||||
class CC_DLL QuadCommand : public TrianglesCommand
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "renderer/CCTrianglesCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCBatchCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/****************************************************************************
|
||||
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/CCTrianglesCommand.h"
|
||||
#include "renderer/ccGLStateCache.h"
|
||||
#include "renderer/CCGLProgram.h"
|
||||
#include "renderer/CCGLProgramState.h"
|
||||
#include "xxhash.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
TrianglesCommand::TrianglesCommand()
|
||||
:_materialID(0)
|
||||
,_textureID(0)
|
||||
,_glProgramState(nullptr)
|
||||
,_blendType(BlendFunc::DISABLE)
|
||||
{
|
||||
_type = RenderCommand::Type::TRIANGLES_COMMAND;
|
||||
}
|
||||
|
||||
void TrianglesCommand::init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, const Triangles& triangles,const Mat4& mv)
|
||||
{
|
||||
CCASSERT(glProgramState, "Invalid GLProgramState");
|
||||
CCASSERT(glProgramState->getVertexAttribsFlags() == 0, "No custom attributes are supported in QuadCommand");
|
||||
|
||||
_globalOrder = globalOrder;
|
||||
|
||||
_triangles = triangles;
|
||||
if(_triangles.indexCount % 3 != 0)
|
||||
{
|
||||
ssize_t count = _triangles.indexCount;
|
||||
_triangles.indexCount = count / 3 * 3;
|
||||
CCLOGERROR("Resize indexCount from %zd to %zd, size must be multiple times of 3", count, _triangles.indexCount);
|
||||
}
|
||||
_mv = mv;
|
||||
|
||||
if( _textureID != textureID || _blendType.src != blendType.src || _blendType.dst != blendType.dst || _glProgramState != glProgramState) {
|
||||
|
||||
_textureID = textureID;
|
||||
_blendType = blendType;
|
||||
_glProgramState = glProgramState;
|
||||
|
||||
generateMaterialID();
|
||||
}
|
||||
}
|
||||
|
||||
TrianglesCommand::~TrianglesCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void TrianglesCommand::generateMaterialID()
|
||||
{
|
||||
|
||||
if(_glProgramState->getUniformCount() > 0)
|
||||
{
|
||||
_materialID = TrianglesCommand::MATERIAL_ID_DO_NOT_BATCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
int glProgram = (int)_glProgramState->getGLProgram()->getProgram();
|
||||
int intArray[4] = { glProgram, (int)_textureID, (int)_blendType.src, (int)_blendType.dst};
|
||||
|
||||
_materialID = XXH32((const void*)intArray, sizeof(intArray), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TrianglesCommand::useMaterial() const
|
||||
{
|
||||
//Set texture
|
||||
GL::bindTexture2D(_textureID);
|
||||
|
||||
//set blend mode
|
||||
GL::blendFunc(_blendType.src, _blendType.dst);
|
||||
|
||||
_glProgramState->apply(_mv);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,79 @@
|
|||
/****************************************************************************
|
||||
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_TRIANGLES_COMMAND__
|
||||
#define __CC_TRIANGLES_COMMAND__
|
||||
|
||||
#include "renderer/CCRenderCommand.h"
|
||||
#include "renderer/CCGLProgramState.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
class CC_DLL TrianglesCommand : public RenderCommand
|
||||
{
|
||||
public:
|
||||
static const int MATERIAL_ID_DO_NOT_BATCH = 0;
|
||||
|
||||
public:
|
||||
struct Triangles
|
||||
{
|
||||
V3F_C4B_T2F* verts;
|
||||
unsigned short* indices;
|
||||
ssize_t vertCount;
|
||||
ssize_t indexCount;
|
||||
};
|
||||
|
||||
TrianglesCommand();
|
||||
~TrianglesCommand();
|
||||
|
||||
/** Initializes the command with a globalZOrder, a texture ID, a `GLProgram`, a blending function, a pointer to triangles,
|
||||
* quantity of quads, and the Model View transform to be used for the quads */
|
||||
void init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, const Triangles& triangles,const Mat4& mv);
|
||||
|
||||
void useMaterial() const;
|
||||
|
||||
inline uint32_t getMaterialID() const { return _materialID; }
|
||||
inline GLuint getTextureID() const { return _textureID; }
|
||||
inline const Triangles& getTriangles() const { return _triangles; }
|
||||
inline ssize_t getVertexCount() const { return _triangles.vertCount; }
|
||||
inline ssize_t getIndexCount() const { return _triangles.indexCount; }
|
||||
inline const V3F_C4B_T2F* getVertices() const { return _triangles.verts; }
|
||||
inline const unsigned short* getIndices() const { return _triangles.indices; }
|
||||
inline GLProgramState* getGLProgramState() const { return _glProgramState; }
|
||||
inline BlendFunc getBlendType() const { return _blendType; }
|
||||
inline const Mat4& getModelView() const { return _mv; }
|
||||
|
||||
protected:
|
||||
void generateMaterialID();
|
||||
|
||||
uint32_t _materialID;
|
||||
GLuint _textureID;
|
||||
GLProgramState* _glProgramState;
|
||||
BlendFunc _blendType;
|
||||
Triangles _triangles;
|
||||
Mat4 _mv;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // defined(__CC_TRIANGLES_COMMAND__)
|
Loading…
Reference in New Issue