remove DrawNode3D

This commit is contained in:
yangxiao 2014-08-08 15:06:45 +08:00
parent 7408250113
commit 97edd303b5
8 changed files with 1 additions and 375 deletions

View File

@ -604,10 +604,6 @@
3EA3EDBD1991CDFA00645534 /* CCCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA3EDBA1991CDFA00645534 /* CCCamera.cpp */; };
3EA3EDBE1991CDFA00645534 /* CCCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA3EDBB1991CDFA00645534 /* CCCamera.h */; };
3EA3EDBF1991CDFA00645534 /* CCCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA3EDBB1991CDFA00645534 /* CCCamera.h */; };
3EA3EDCC199234B500645534 /* CCDrawNode3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA3EDCA199234B500645534 /* CCDrawNode3D.cpp */; };
3EA3EDCD199234B500645534 /* CCDrawNode3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA3EDCA199234B500645534 /* CCDrawNode3D.cpp */; };
3EA3EDCE199234B500645534 /* CCDrawNode3D.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA3EDCB199234B500645534 /* CCDrawNode3D.h */; };
3EA3EDCF199234B500645534 /* CCDrawNode3D.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA3EDCB199234B500645534 /* CCDrawNode3D.h */; };
3EA47870195478E00068D9D1 /* CCBundleReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */; };
3EA47871195478E00068D9D1 /* CCBundleReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */; };
3EA47872195478E00068D9D1 /* CCBundleReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA4786F195478E00068D9D1 /* CCBundleReader.h */; };
@ -2489,8 +2485,6 @@
3EA2A83F1987A6810077B3D4 /* CCSkeleton3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCSkeleton3D.h; sourceTree = "<group>"; };
3EA3EDBA1991CDFA00645534 /* CCCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCCamera.cpp; path = ../base/CCCamera.cpp; sourceTree = "<group>"; };
3EA3EDBB1991CDFA00645534 /* CCCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCCamera.h; path = ../base/CCCamera.h; sourceTree = "<group>"; };
3EA3EDCA199234B500645534 /* CCDrawNode3D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCDrawNode3D.cpp; sourceTree = "<group>"; };
3EA3EDCB199234B500645534 /* CCDrawNode3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCDrawNode3D.h; sourceTree = "<group>"; };
3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBundleReader.cpp; sourceTree = "<group>"; };
3EA4786F195478E00068D9D1 /* CCBundleReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBundleReader.h; sourceTree = "<group>"; };
464AD6E3197EBB1400E502D8 /* pvr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pvr.cpp; path = ../base/pvr.cpp; sourceTree = "<group>"; };
@ -5202,8 +5196,6 @@
B29594B81926D61F003EEF37 /* 3d */ = {
isa = PBXGroup;
children = (
3EA3EDCA199234B500645534 /* CCDrawNode3D.cpp */,
3EA3EDCB199234B500645534 /* CCDrawNode3D.h */,
3EA2A83E1987A6810077B3D4 /* CCSkeleton3D.cpp */,
3EA2A83F1987A6810077B3D4 /* CCSkeleton3D.h */,
3E9E80E3198639EF00FA95D0 /* CCAttachNode.cpp */,
@ -5338,7 +5330,6 @@
1A570212180BCBF40088DEC7 /* CCProgressTimer.h in Headers */,
1A570216180BCBF40088DEC7 /* CCRenderTexture.h in Headers */,
1A01C69618F57BE800EFE3A6 /* CCInteger.h in Headers */,
3EA3EDCE199234B500645534 /* CCDrawNode3D.h in Headers */,
1A570223180BCC1A0088DEC7 /* CCParticleBatchNode.h in Headers */,
50ABBD891925AB4100A911A9 /* CCCustomCommand.h in Headers */,
5034CA43191D591100CE6051 /* ccShader_Label.vert in Headers */,
@ -5844,7 +5835,6 @@
503DD8F11926736A00CD74DD /* OpenGL_Internal.h in Headers */,
B37510801823ACA100B3BA6A /* CCPhysicsHelper_chipmunk.h in Headers */,
50ABBDAA1925AB4100A911A9 /* CCRenderCommand.h in Headers */,
3EA3EDCF199234B500645534 /* CCDrawNode3D.h in Headers */,
3E9E80F4198639EF00FA95D0 /* CCSubMeshState.h in Headers */,
50ABBE601925AB6F00A911A9 /* CCEventListener.h in Headers */,
50ABBEB21925AB6F00A911A9 /* CCUserDefault.h in Headers */,
@ -6836,7 +6826,6 @@
1A570229180BCC1A0088DEC7 /* CCParticleSystem.cpp in Sources */,
1A57022D180BCC1A0088DEC7 /* CCParticleSystemQuad.cpp in Sources */,
1A57027E180BCC900088DEC7 /* CCSprite.cpp in Sources */,
3EA3EDCC199234B500645534 /* CCDrawNode3D.cpp in Sources */,
1A570282180BCC900088DEC7 /* CCSpriteBatchNode.cpp in Sources */,
1A570286180BCC900088DEC7 /* CCSpriteFrame.cpp in Sources */,
B24AA989195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */,
@ -7100,7 +7089,6 @@
50ABBE461925AB6F00A911A9 /* CCEvent.cpp in Sources */,
50ABBEA01925AB6F00A911A9 /* CCScheduler.cpp in Sources */,
3E9E80EA198639EF00FA95D0 /* CCAttachNode.cpp in Sources */,
3EA3EDCD199234B500645534 /* CCDrawNode3D.cpp in Sources */,
50ABBE4E1925AB6F00A911A9 /* CCEventCustom.cpp in Sources */,
50ABBE761925AB6F00A911A9 /* CCEventListenerTouch.cpp in Sources */,
50ABBE5A1925AB6F00A911A9 /* CCEventKeyboard.cpp in Sources */,

View File

@ -1,240 +0,0 @@
/****************************************************************************
Copyright (c) 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 "CCDrawNode3D.h"
#include "CCGL.h"
#include "base/CCEventType.h"
#include "base/CCConfiguration.h"
#include "renderer/CCCustomCommand.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCGLProgramState.h"
#include "base/CCDirector.h"
#include "base/CCEventListenerCustom.h"
#include "base/CCEventDispatcher.h"
NS_CC_BEGIN
DrawNode3D::DrawNode3D()
: _vao(0)
, _vbo(0)
, _bufferCapacity(0)
, _bufferCount(0)
, _buffer(nullptr)
, _dirty(false)
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
}
DrawNode3D::~DrawNode3D()
{
free(_buffer);
_buffer = nullptr;
glDeleteBuffers(1, &_vbo);
_vbo = 0;
if (Configuration::getInstance()->supportsShareableVAO())
{
glDeleteVertexArrays(1, &_vao);
GL::bindVAO(0);
_vao = 0;
}
}
DrawNode3D* DrawNode3D::create()
{
DrawNode3D* ret = new DrawNode3D();
if (ret && ret->init())
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
}
void DrawNode3D::ensureCapacity(int count)
{
CCASSERT(count>=0, "capacity must be >= 0");
if(_bufferCount + count > _bufferCapacity)
{
_bufferCapacity += MAX(_bufferCapacity, count);
_buffer = (V3F_C4B*)realloc(_buffer, _bufferCapacity*sizeof(V3F_C4B));
}
}
bool DrawNode3D::init()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR));
ensureCapacity(512);
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
}
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices));
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors));
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
CHECK_GL_ERROR_DEBUG();
_dirty = true;
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
/** listen the event that coming to foreground on Android */
this->init();
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
return true;
}
void DrawNode3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(DrawNode3D::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void DrawNode3D::onDraw(const Mat4 &transform, uint32_t flags)
{
auto glProgram = getGLProgram();
glProgram->use();
glProgram->setUniformsForBuiltins(transform);
glEnable(GL_DEPTH_TEST);
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
if (_dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
_dirty = false;
}
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vao);
}
else
{
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors));
}
glDrawArrays(GL_LINES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount);
glDisable(GL_DEPTH_TEST);
CHECK_GL_ERROR_DEBUG();
}
void DrawNode3D::drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color)
{
unsigned int vertex_count = 2;
ensureCapacity(vertex_count);
Color4B col = Color4B(color);
V3F_C4B a = {Vec3(from.x, from.y, from.z), col};
V3F_C4B b = {Vec3(to.x, to.y, to.z), col, };
V3F_C4B *lines = (V3F_C4B *)(_buffer + _bufferCount);
lines[0] = a;
lines[1] = b;
_bufferCount += vertex_count;
_dirty = true;
}
void DrawNode3D::drawCube(Vec3* vertices, const Color4F &color)
{
// front face
drawLine(vertices[0], vertices[1], color);
drawLine(vertices[1], vertices[2], color);
drawLine(vertices[2], vertices[3], color);
drawLine(vertices[3], vertices[0], color);
// back face
drawLine(vertices[4], vertices[5], color);
drawLine(vertices[5], vertices[6], color);
drawLine(vertices[6], vertices[7], color);
drawLine(vertices[7], vertices[4], color);
// edge
drawLine(vertices[0], vertices[7], color);
drawLine(vertices[1], vertices[6], color);
drawLine(vertices[2], vertices[5], color);
drawLine(vertices[3], vertices[4], color);
}
void DrawNode3D::clear()
{
_bufferCount = 0;
_dirty = true;
}
const BlendFunc& DrawNode3D::getBlendFunc() const
{
return _blendFunc;
}
void DrawNode3D::setBlendFunc(const BlendFunc &blendFunc)
{
_blendFunc = blendFunc;
}
NS_CC_END

View File

@ -1,117 +0,0 @@
/****************************************************************************
Copyright (c) 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_DRAW_NODE_3D_H__
#define __CC_DRAW_NODE_3D_H__
#include "2d/CCNode.h"
#include "base/ccTypes.h"
#include "renderer/CCCustomCommand.h"
NS_CC_BEGIN
/**
* Copy DrawNode for 3D geometry drawing.
*/
class CC_DLL DrawNode3D: public Node
{
public:
/** creates and initialize a DrawNode3D node */
static DrawNode3D* create();
/**
* Draw 3D Line
*/
void drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color);
/**
* Draw 3D cube
* @param point to a vertex array who has 8 element.
* vertices[0]:Left-top-front,
* vertices[1]:Left-bottom-front,
* vertices[2]:Right-bottom-front,
* vertices[3]:Right-top-front,
* vertices[4]:Right-top-back,
* vertices[5]:Right-bottom-back,
* vertices[6]:Left-bottom-back,
* vertices[7]:Left-top-back.
* @param color
*/
void drawCube(Vec3* vertices, const Color4F &color);
/** Clear the geometry in the node's buffer. */
void clear();
/**
* @js NA
* @lua NA
*/
const BlendFunc& getBlendFunc() const;
/**
* @code
* When this function bound into js or lua,the parameter will be changed
* In js: var setBlendFunc(var src, var dst)
* @endcode
* @lua NA
*/
void setBlendFunc(const BlendFunc &blendFunc);
void onDraw(const Mat4 &transform, uint32_t flags);
// Overrides
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
CC_CONSTRUCTOR_ACCESS:
DrawNode3D();
virtual ~DrawNode3D();
virtual bool init();
protected:
struct V3F_C4B
{
Vec3 vertices;
Color4B colors;
};
void ensureCapacity(int count);
GLuint _vao;
GLuint _vbo;
int _bufferCapacity;
GLsizei _bufferCount;
V3F_C4B* _buffer;
BlendFunc _blendFunc;
CustomCommand _customCommand;
bool _dirty;
private:
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode3D);
};
NS_CC_END
#endif // __CCDRAWNODES_CCDRAW_NODE_H__

View File

@ -1,5 +1,4 @@
set(COCOS_3D_SRC
3d/CCDrawNode3D.cpp
3d/CCSkeleton3D.cpp
3d/CCAttachNode.cpp
3d/CCSubMesh.cpp

View File

@ -79,7 +79,6 @@ cocos2d.cpp \
3d/CCAttachNode.cpp \
3d/CCBundle3D.cpp \
3d/CCBundleReader.cpp \
3d/CCDrawNode3D.cpp \
3d/CCMesh.cpp \
3d/CCMeshSkin.cpp \
3d/CCSprite3DMaterial.cpp \

View File

@ -270,7 +270,6 @@ THE SOFTWARE.
#include "3d/CCSprite3DMaterial.h"
#include "3d/CCSubMeshState.h"
#include "3d/CCAttachNode.h"
#include "3d/CCDrawNode3D.h"
// Deprecated include
#include "deprecated/CCDictionary.h"

View File

@ -205,8 +205,6 @@
"cocos/3d/CCBundle3DData.h",
"cocos/3d/CCBundleReader.cpp",
"cocos/3d/CCBundleReader.h",
"cocos/3d/CCDrawNode3D.cpp",
"cocos/3d/CCDrawNode3D.h",
"cocos/3d/CCMesh.cpp",
"cocos/3d/CCMesh.h",
"cocos/3d/CCMeshSkin.cpp",

View File

@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h %
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console Mesh GLProgramCache GLProgramState SubMeshState AttachNode Camera DrawNode3D
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console Mesh GLProgramCache GLProgramState SubMeshState AttachNode Camera
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also