mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 02:52:39 +08:00
@@ -44,6 +44,8 @@ THE SOFTWARE.
|
||||
#include "renderer/CCMaterial.h"
|
||||
#include "math/TransformUtils.h"
|
||||
|
||||
#include "editor-support/creator/CCCameraNode.h"
|
||||
|
||||
|
||||
#if CC_NODE_RENDER_SUBPIXEL
|
||||
#define RENDER_IN_SUBPIXEL
|
||||
@@ -1238,6 +1240,19 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren
|
||||
_director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
_director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
||||
|
||||
auto camera = creator::CameraNode::getInstance();
|
||||
if (camera) {
|
||||
if (camera->visitingIndex <= 0) {
|
||||
if (camera->containsNode(this)) {
|
||||
camera->visitingIndex ++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
camera->visitingIndex ++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!_children.empty())
|
||||
{
|
||||
sortAllChildren();
|
||||
@@ -1263,6 +1278,10 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren
|
||||
{
|
||||
this->draw(renderer, _modelViewTransform, flags);
|
||||
}
|
||||
|
||||
if (camera && camera->visitingIndex > 0) {
|
||||
camera->visitingIndex --;
|
||||
}
|
||||
|
||||
_director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
****************************************************************************/
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
|
||||
#define LOG_TAG "AudioEngineImpl"
|
||||
|
||||
#include "audio/android/AudioEngine-inl.h"
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -261,7 +263,7 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||
player->setId(audioId);
|
||||
_audioPlayers.insert(std::make_pair(audioId, player));
|
||||
|
||||
player->setPlayEventCallback([this, player](IAudioPlayer::State state){
|
||||
player->setPlayEventCallback([this, player, filePath](IAudioPlayer::State state){
|
||||
|
||||
if (state != IAudioPlayer::State::OVER && state != IAudioPlayer::State::STOPPED)
|
||||
{
|
||||
@@ -270,12 +272,14 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||
}
|
||||
|
||||
int id = player->getId();
|
||||
std::string filePath = *AudioEngine::_audioIDInfoMap[id].filePath;
|
||||
|
||||
ALOGV("Removing player id=%d, state:%d", id, (int)state);
|
||||
|
||||
AudioEngine::remove(id);
|
||||
_audioPlayers.erase(id);
|
||||
if (_audioPlayers.find(id) != _audioPlayers.end())
|
||||
{
|
||||
_audioPlayers.erase(id);
|
||||
}
|
||||
|
||||
auto iter = _callbackMap.find(id);
|
||||
if (iter != _callbackMap.end())
|
||||
|
||||
@@ -56,11 +56,22 @@ bool PcmAudioPlayer::prepare(const std::string &url, const PcmData &decResult)
|
||||
|
||||
std::thread::id callerThreadId = _callerThreadUtils->getCallerThreadId();
|
||||
|
||||
// @note The logic may cause this issue https://github.com/cocos2d/cocos2d-x/issues/17707
|
||||
// Assume that AudioEngine::stop(id) is invoked and the audio is played over meanwhile.
|
||||
// Since State::OVER and State::DESTROYED are triggered in the audio mixing thread, it will
|
||||
// call 'performFunctionInCallerThread' to post events to cocos's message queue.
|
||||
// Therefore, the sequence in cocos's thread will be |STOP|OVER|DESTROYED|.
|
||||
// Although, we remove the audio id in |STOPPED| callback, because it's asynchronous operation,
|
||||
// |OVER| and |DESTROYED| callbacks will still be invoked in cocos's thread.
|
||||
// HOW TO FIX: If the previous state is |STOPPED| and the current state
|
||||
// is |OVER|, just skip to invoke |OVER| callback.
|
||||
|
||||
_track->onStateChanged = [this, callerThreadId](Track::State state) {
|
||||
// It maybe in sub thread
|
||||
auto func = [this, state](){
|
||||
Track::State prevState = _track->getPrevState();
|
||||
auto func = [this, state, prevState](){
|
||||
// It's in caller's thread
|
||||
if (state == Track::State::OVER)
|
||||
if (state == Track::State::OVER && prevState != Track::State::STOPPED)
|
||||
{
|
||||
if (_playEventCallback != nullptr)
|
||||
{
|
||||
@@ -81,11 +92,11 @@ bool PcmAudioPlayer::prepare(const std::string &url, const PcmData &decResult)
|
||||
};
|
||||
|
||||
if (callerThreadId == std::this_thread::get_id())
|
||||
{
|
||||
{ // onStateChanged(Track::State::STOPPED) is in caller's (Cocos's) thread.
|
||||
func();
|
||||
}
|
||||
else
|
||||
{
|
||||
{ // onStateChanged(Track::State::OVER) or onStateChanged(Track::State::DESTROYED) are in audio mixing thread.
|
||||
_callerThreadUtils->performFunctionInCallerThread(func);
|
||||
}
|
||||
};
|
||||
@@ -148,26 +159,26 @@ void PcmAudioPlayer::setPlayEventCallback(const PlayEventCallback &playEventCall
|
||||
void PcmAudioPlayer::play()
|
||||
{
|
||||
// put track to AudioMixerController
|
||||
ALOGV("PcmAudioPlayer (%p) play (%s) ...", this, _url.c_str());
|
||||
ALOGV("PcmAudioPlayer (%p) play, url: %s", this, _url.c_str());
|
||||
_controller->addTrack(_track);
|
||||
_track->setState(Track::State::PLAYING);
|
||||
}
|
||||
|
||||
void PcmAudioPlayer::pause()
|
||||
{
|
||||
ALOGV("PcmAudioPlayer (%p) pause ...", this);
|
||||
ALOGV("PcmAudioPlayer (%p) pause, url: %s", this, _url.c_str());
|
||||
_track->setState(Track::State::PAUSED);
|
||||
}
|
||||
|
||||
void PcmAudioPlayer::resume()
|
||||
{
|
||||
ALOGV("PcmAudioPlayer (%p) resume ...", this);
|
||||
ALOGV("PcmAudioPlayer (%p) resume, url: %s", this, _url.c_str());
|
||||
_track->setState(Track::State::RESUMED);
|
||||
}
|
||||
|
||||
void PcmAudioPlayer::stop()
|
||||
{
|
||||
ALOGV("PcmAudioPlayer (%p) stop ...", this);
|
||||
ALOGV("PcmAudioPlayer (%p) stop, url: %s", this, _url.c_str());
|
||||
_track->setState(Track::State::STOPPED);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ NS_CC_BEGIN
|
||||
|
||||
CC_DLL const char* cocos2dVersion()
|
||||
{
|
||||
return "1.5.0";
|
||||
return "1.5.1";
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
@@ -13,15 +13,23 @@
|
||||
using namespace cocos2d;
|
||||
|
||||
namespace creator {
|
||||
cocos2d::Mat4 CameraNode::_tempMat;
|
||||
static CameraNode* _cameraInstance;
|
||||
|
||||
|
||||
CameraNode::CameraNode()
|
||||
{
|
||||
_mat.setIdentity();
|
||||
_cameraInstance = this;
|
||||
visitingIndex = 0;
|
||||
}
|
||||
|
||||
CameraNode::~CameraNode()
|
||||
{
|
||||
_cameraInstance = nullptr;
|
||||
}
|
||||
|
||||
CameraNode* CameraNode::getInstance() {
|
||||
return _cameraInstance;
|
||||
}
|
||||
|
||||
void CameraNode::setTransform(float a, float b, float c, float d, float tx, float ty)
|
||||
@@ -33,18 +41,41 @@ namespace creator {
|
||||
m[5] = d;
|
||||
m[12] = tx;
|
||||
m[13] = ty;
|
||||
|
||||
_inverseMat = _mat;
|
||||
_inverseMat.inverse();
|
||||
|
||||
_visibleRect.origin = Director::getInstance()->getVisibleOrigin();
|
||||
_visibleRect.size = Director::getInstance()->getVisibleSize();
|
||||
|
||||
_visibleRect = RectApplyTransform(_visibleRect, _inverseMat);
|
||||
}
|
||||
|
||||
const cocos2d::Rect& CameraNode::getVisibleRect()
|
||||
{
|
||||
return _visibleRect;
|
||||
}
|
||||
|
||||
bool CameraNode::containsNode(cocos2d::Node* node)
|
||||
{
|
||||
while (node) {
|
||||
if (std::find(_nodes.begin(), _nodes.end(), node) !=_nodes.end()) {
|
||||
return true;
|
||||
}
|
||||
node = node->getParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CameraNode::addTarget(Node* target)
|
||||
{
|
||||
for (auto i = _commands.begin(); i != _commands.end(); i++)
|
||||
{
|
||||
if (i->target == target)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (std::find(_nodes.begin(), _nodes.end(), target) !=_nodes.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_nodes.push_back(target);
|
||||
|
||||
CustomCommand* beforeVisitCommand = new CustomCommand();
|
||||
CustomCommand* afterVisitCommand = new CustomCommand();
|
||||
|
||||
@@ -79,6 +110,13 @@ namespace creator {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto i = _nodes.begin(); i != _nodes.end(); i++) {
|
||||
if (*i == target) {
|
||||
_nodes.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CameraNode::beforeVisit()
|
||||
|
||||
@@ -45,19 +45,29 @@ namespace creator {
|
||||
CameraNode();
|
||||
~CameraNode();
|
||||
|
||||
static CameraNode* getInstance();
|
||||
|
||||
void setTransform(float a, float b, float c, float d, float tx, float ty);
|
||||
|
||||
bool containsNode(cocos2d::Node* node);
|
||||
|
||||
void addTarget(cocos2d::Node* target);
|
||||
void removeTarget(cocos2d::Node* target);
|
||||
|
||||
const cocos2d::Rect& getVisibleRect();
|
||||
|
||||
int visitingIndex;
|
||||
public:
|
||||
void beforeVisit();
|
||||
void afterVisit();
|
||||
|
||||
protected:
|
||||
cocos2d::Mat4 _mat;
|
||||
static cocos2d::Mat4 _tempMat;
|
||||
cocos2d::Mat4 _inverseMat;
|
||||
cocos2d::Rect _visibleRect;
|
||||
|
||||
std::vector<CameraCommand> _commands;
|
||||
std::vector<cocos2d::Node*> _nodes;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 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
|
||||
@@ -21,7 +21,7 @@
|
||||
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 "CCGraphicsNode.h"
|
||||
@@ -83,7 +83,7 @@ GraphicsNode::GraphicsNode()
|
||||
, _curPath(nullptr)
|
||||
{
|
||||
_miterLimit = 10.0f;
|
||||
|
||||
|
||||
setDeviceRatio(1);
|
||||
|
||||
_strokeColor = Color4F::BLACK;
|
||||
@@ -140,7 +140,7 @@ void GraphicsNode::bezierCurveTo(float c1x, float c1y, float c2x, float c2y, flo
|
||||
}
|
||||
|
||||
tesselateBezier(last->x,last->y, c1x,c1y, c2x,c2y, x,y, 0, PT_CORNER);
|
||||
|
||||
|
||||
_commandx = x;
|
||||
_commandy = y;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ void GraphicsNode::rect(float x, float y, float w, float h)
|
||||
lineTo(x+w, y+h);
|
||||
lineTo(x+w, y);
|
||||
close();
|
||||
|
||||
|
||||
_curPath->complex = false;
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ void GraphicsNode::roundRect(float x, float y, float w, float h, float r)
|
||||
lineTo(x+rx, y);
|
||||
bezierCurveTo(x+rx*(1-VECTOR_KAPPA90), y, x, y+ry*(1-VECTOR_KAPPA90), x, y+ry);
|
||||
close();
|
||||
|
||||
|
||||
_curPath->complex = false;
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ void GraphicsNode::ellipse(float cx, float cy, float rx, float ry)
|
||||
bezierCurveTo(cx-rx*VECTOR_KAPPA90, cy-ry, cx-rx, cy-ry*VECTOR_KAPPA90, cx-rx, cy);
|
||||
|
||||
close();
|
||||
|
||||
|
||||
_curPath->complex = false;
|
||||
}
|
||||
|
||||
@@ -312,17 +312,17 @@ void GraphicsNode::circle(float cx, float cy, float r)
|
||||
{
|
||||
int divs = curveDivs(r, PI_2, _tessTol);
|
||||
float step = PI_2 / divs;
|
||||
|
||||
|
||||
moveTo(cx, cy + r);
|
||||
|
||||
|
||||
for (int i = 1; i < divs; i++) {
|
||||
float angle = step * i;
|
||||
float x = r * sin(angle);
|
||||
float y = r * cos(angle);
|
||||
|
||||
|
||||
lineTo(cx + x, cy + y);
|
||||
}
|
||||
|
||||
|
||||
close();
|
||||
_curPath->complex = false;
|
||||
}
|
||||
@@ -376,13 +376,13 @@ void GraphicsNode::clear(bool clean)
|
||||
_paths.pop_back();
|
||||
delete path;
|
||||
}
|
||||
|
||||
|
||||
for (int i = (int)_points.size() - 1; i >=0; i--) {
|
||||
VecPoint* p = _points[i];
|
||||
_points.pop_back();
|
||||
delete p;
|
||||
}
|
||||
|
||||
|
||||
CC_SAFE_DELETE(_verts);
|
||||
CC_SAFE_DELETE(_indices);
|
||||
|
||||
@@ -391,17 +391,17 @@ void GraphicsNode::clear(bool clean)
|
||||
}
|
||||
_commands.clear();
|
||||
}
|
||||
|
||||
|
||||
_nPoints = 0;
|
||||
|
||||
|
||||
_nPath = 0;
|
||||
_pathOffset = 0;
|
||||
|
||||
_vertsOffset = 0;
|
||||
_indicesOffset = 0;
|
||||
|
||||
|
||||
_curPath = nullptr;
|
||||
|
||||
|
||||
_nCommands = 0;
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ void GraphicsNode::addPoint(Path* path, float x, float y, int flags)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_nPoints ++;
|
||||
if (_nPoints > _points.size()) {
|
||||
pt = new VecPoint(x, y);
|
||||
@@ -527,7 +527,7 @@ void GraphicsNode::addPoint(Path* path, float x, float y, int flags)
|
||||
pt->x = x;
|
||||
pt->y = y;
|
||||
}
|
||||
|
||||
|
||||
pt->flags = (unsigned char)flags;
|
||||
path->points.push_back(pt);
|
||||
}
|
||||
@@ -537,23 +537,23 @@ Path* GraphicsNode::addPath()
|
||||
if (!(_curPath && _curPath->points.size() <= 1)) {
|
||||
_nPath ++;
|
||||
}
|
||||
|
||||
|
||||
Path* path = nullptr;
|
||||
|
||||
|
||||
|
||||
|
||||
if (_nPath > _paths.size()) {
|
||||
path = new Path();
|
||||
_paths.push_back(path);
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
path = _paths[_nPath - 1];
|
||||
path->points.clear();
|
||||
}
|
||||
|
||||
path->closed = false;
|
||||
path->complex = true;
|
||||
|
||||
|
||||
_curPath = path;
|
||||
|
||||
return path;
|
||||
@@ -592,11 +592,11 @@ void GraphicsNode::expandStroke(float w, int lineCap, int lineJoin, float miterL
|
||||
|
||||
allocVerts(cverts);
|
||||
allocIndices((cverts - 2*(_nPath-_pathOffset)) * 3);
|
||||
|
||||
|
||||
for (i = _pathOffset; i < _nPath; i++) {
|
||||
VecVertex* verts = _verts + _vertsOffset;
|
||||
int offset = _vertsOffset;
|
||||
|
||||
|
||||
Path* path = _paths[i];
|
||||
|
||||
VecPointVector& pts = path->points;
|
||||
@@ -669,16 +669,16 @@ void GraphicsNode::expandStroke(float w, int lineCap, int lineJoin, float miterL
|
||||
else if (lineCap == CAP_ROUND)
|
||||
roundCapEnd(p1, dx, dy, w, ncap, aa);
|
||||
}
|
||||
|
||||
|
||||
// stroke indices
|
||||
int indicesOffset = _indicesOffset;
|
||||
|
||||
|
||||
for (int start = offset+2, end = _vertsOffset; start < end; start++) {
|
||||
_indices[_indicesOffset++] = start - 2;
|
||||
_indices[_indicesOffset++] = start - 1;
|
||||
_indices[_indicesOffset++] = start;
|
||||
}
|
||||
|
||||
|
||||
float strokeMult = (_lineWidth*0.5f + _fringeWidth*0.5f) / _fringeWidth;
|
||||
pushCommand(_strokeColor, strokeMult, offset, _vertsOffset - offset, indicesOffset, _indicesOffset - indicesOffset);
|
||||
}
|
||||
@@ -711,10 +711,10 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
|
||||
|
||||
for (i = _pathOffset; i < _nPath; i++) {
|
||||
Path* path = _paths[i];
|
||||
|
||||
|
||||
VecVertex* verts = _verts + _vertsOffset;
|
||||
int offset = _vertsOffset;
|
||||
|
||||
|
||||
VecPointVector& pts = path->points;
|
||||
int pathSize = (int)pts.size();
|
||||
|
||||
@@ -724,7 +724,7 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
|
||||
|
||||
// Calculate shape vertices.
|
||||
woff = 0.5f*aa;
|
||||
|
||||
|
||||
if (fringe) {
|
||||
// Looping
|
||||
p0 = pts[pathSize-1];
|
||||
@@ -750,7 +750,7 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
|
||||
} else {
|
||||
vset(p1->x + (p1->dmx * woff), p1->y + (p1->dmy * woff), 0.5f,1);
|
||||
}
|
||||
|
||||
|
||||
if (j < (pathSize - 1)) {
|
||||
p0 = p1;
|
||||
p1 = pts[j + 1];
|
||||
@@ -761,27 +761,27 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
|
||||
vset(pts[j]->x, pts[j]->y, 0.5f,1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int nVerts = _vertsOffset - offset;
|
||||
int indicesOffset = _indicesOffset;
|
||||
|
||||
|
||||
if (path->complex) {
|
||||
// indices
|
||||
std::vector<int> indices;
|
||||
Triangulate::process(verts, 0, _vertsOffset - offset, indices);
|
||||
int nIndices = (int)indices.size();
|
||||
|
||||
|
||||
allocIndices(nIndices);
|
||||
|
||||
|
||||
for (j = 0; j < nIndices; j++) {
|
||||
_indices[j + _indicesOffset] = indices[j] + offset;
|
||||
}
|
||||
|
||||
|
||||
_indicesOffset += nIndices;
|
||||
}
|
||||
else {
|
||||
allocIndices((nVerts - 2) * 3);
|
||||
|
||||
|
||||
int first = offset;
|
||||
for (int start = offset+2, end = _vertsOffset; start < end; start++) {
|
||||
_indices[_indicesOffset++] = first;
|
||||
@@ -789,30 +789,30 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
|
||||
_indices[_indicesOffset++] = start;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pushCommand(_fillColor, 1, offset, _vertsOffset - offset, indicesOffset, _indicesOffset - indicesOffset);
|
||||
|
||||
|
||||
// Calculate fringe
|
||||
if (fringe) {
|
||||
verts = _verts + _vertsOffset;
|
||||
offset = _vertsOffset;
|
||||
|
||||
|
||||
float lw = w + woff;
|
||||
float rw = w - woff;
|
||||
float lu = 0;
|
||||
float ru = 1;
|
||||
|
||||
|
||||
// Create only half a fringe for convex shapes so that
|
||||
// the shape can be rendered without stenciling.
|
||||
if (convex) {
|
||||
lw = woff; // This should generate the same vertex as fill inset above.
|
||||
lu = 0.5f; // Set outline fade at middle.
|
||||
}
|
||||
|
||||
|
||||
// Looping
|
||||
p0 = pts[pathSize-1];
|
||||
p1 = pts[0];
|
||||
|
||||
|
||||
for (j = 0; j < pathSize; ++j) {
|
||||
if ((p1->flags & (PT_BEVEL | PT_INNERBEVEL)) != 0) {
|
||||
bevelJoin(p0, p1, lw, rw, lu, ru, _fringeWidth);
|
||||
@@ -826,23 +826,23 @@ void GraphicsNode::expandFill(float w, int lineJoin, float miterLimit)
|
||||
p1 = pts[j + 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Loop it
|
||||
vset(verts[0].x, verts[0].y, lu,1);
|
||||
vset(verts[1].x, verts[1].y, ru,1);
|
||||
|
||||
|
||||
// fill stroke indices
|
||||
nVerts = _vertsOffset - offset;
|
||||
indicesOffset = _indicesOffset;
|
||||
|
||||
|
||||
allocIndices((nVerts - 2) * 3);
|
||||
|
||||
|
||||
for (int start = offset+2, end = _vertsOffset; start < end; start++) {
|
||||
_indices[_indicesOffset++] = start - 2;
|
||||
_indices[_indicesOffset++] = start - 1;
|
||||
_indices[_indicesOffset++] = start;
|
||||
}
|
||||
|
||||
|
||||
pushCommand(_fillColor, 1, offset, nVerts, indicesOffset, _indicesOffset - indicesOffset);
|
||||
}
|
||||
}
|
||||
@@ -854,7 +854,7 @@ void GraphicsNode::flattenPaths()
|
||||
_nPath --;
|
||||
_curPath = _nPath > 0 ? _paths[_nPath - 1] : nullptr;
|
||||
}
|
||||
|
||||
|
||||
for (int i = _pathOffset; i < _nPath; i++) {
|
||||
Path* path = _paths[i];
|
||||
VecPointVector& pts = path->points;
|
||||
@@ -960,7 +960,7 @@ void GraphicsNode::calculateJoins(float w, int lineJoin, float miterLimit)
|
||||
void GraphicsNode::allocVerts(int count)
|
||||
{
|
||||
int nverts = _vertsOffset + count;
|
||||
|
||||
|
||||
if (nverts > _nVerts) {
|
||||
while (nverts > _nVerts) {
|
||||
_nVerts *= 2;
|
||||
@@ -972,7 +972,7 @@ void GraphicsNode::allocVerts(int count)
|
||||
void GraphicsNode::allocIndices(int count)
|
||||
{
|
||||
int nIndices = _indicesOffset + count;
|
||||
|
||||
|
||||
if (nIndices > _nIndices) {
|
||||
while (nIndices > _nIndices) {
|
||||
_nIndices *= 2;
|
||||
@@ -985,22 +985,22 @@ void GraphicsNode::allocIndices(int count)
|
||||
void GraphicsNode::vset(float x, float y, float u, float v)
|
||||
{
|
||||
VecVertex* vtx = &_verts[_vertsOffset];
|
||||
|
||||
|
||||
vtx->x = x;
|
||||
vtx->y = y;
|
||||
vtx->u = u;
|
||||
vtx->v = v;
|
||||
|
||||
|
||||
_vertsOffset ++;
|
||||
}
|
||||
|
||||
|
||||
void GraphicsNode::pushCommand(cocos2d::Color4F& color, float strokeMult, int vertsOffset, int nVerts, int indicesOffset, int nIndices)
|
||||
{
|
||||
Command* lastCmd = nullptr;
|
||||
if (_commands.size() >= _nCommands && _nCommands > 0) {
|
||||
lastCmd = _commands[_nCommands - 1];
|
||||
}
|
||||
|
||||
|
||||
if (lastCmd &&
|
||||
((lastCmd->vertsOffset + lastCmd->nVerts) == vertsOffset) &&
|
||||
((lastCmd->indicesOffset + lastCmd->nIndices) == indicesOffset) &&
|
||||
@@ -1011,7 +1011,7 @@ void GraphicsNode::pushCommand(cocos2d::Color4F& color, float strokeMult, int ve
|
||||
}
|
||||
else {
|
||||
Command* cmd;
|
||||
|
||||
|
||||
_nCommands ++;
|
||||
if (_nCommands > _commands.size()) {
|
||||
cmd = new Command();
|
||||
@@ -1020,7 +1020,7 @@ void GraphicsNode::pushCommand(cocos2d::Color4F& color, float strokeMult, int ve
|
||||
else {
|
||||
cmd = _commands[_nCommands - 1];
|
||||
}
|
||||
|
||||
|
||||
cmd->color = color;
|
||||
cmd->strokeMult = strokeMult;
|
||||
cmd->vertsOffset = vertsOffset;
|
||||
@@ -1061,7 +1061,7 @@ void GraphicsNode::roundCapStart(VecPoint* p, float dx, float dy, float w, int n
|
||||
float py = p->y;
|
||||
float dlx = dy;
|
||||
float dly = -dx;
|
||||
|
||||
|
||||
for (i = 0; i < ncap; i++) {
|
||||
float a = i/(float)(ncap-1) * PI;
|
||||
float ax = cosf(a) * w, ay = sinf(a) * w;
|
||||
@@ -1079,7 +1079,7 @@ void GraphicsNode::roundCapEnd(VecPoint* p, float dx, float dy, float w, int nca
|
||||
float py = p->y;
|
||||
float dlx = dy;
|
||||
float dly = -dx;
|
||||
|
||||
|
||||
vset(px + dlx*w, py + dly*w, 0,1);
|
||||
vset(px - dlx*w, py - dly*w, 1,1);
|
||||
for (i = 0; i < ncap; i++) {
|
||||
@@ -1097,17 +1097,17 @@ void GraphicsNode::roundJoin(VecPoint* p0, VecPoint* p1, float lw, float rw, flo
|
||||
float dly0 = -p0->dx;
|
||||
float dlx1 = p1->dy;
|
||||
float dly1 = -p1->dx;
|
||||
|
||||
|
||||
if (p1->flags & PT_LEFT) {
|
||||
float lx0,ly0,lx1,ly1,a0,a1;
|
||||
chooseBevel(p1->flags & PT_INNERBEVEL, p0, p1, lw, &lx0,&ly0, &lx1,&ly1);
|
||||
a0 = atan2f(-dly0, -dlx0);
|
||||
a1 = atan2f(-dly1, -dlx1);
|
||||
if (a1 > a0) a1 -= PI_2;
|
||||
|
||||
|
||||
vset(lx0, ly0, lu,1);
|
||||
vset(p1->x - dlx0*rw, p1->y - dly0*rw, ru,1);
|
||||
|
||||
|
||||
n = clampi((int)ceilf(((a0 - a1) / PI) * ncap), 2, ncap);
|
||||
for (i = 0; i < n; i++) {
|
||||
float u = i/(float)(n-1);
|
||||
@@ -1117,20 +1117,20 @@ void GraphicsNode::roundJoin(VecPoint* p0, VecPoint* p1, float lw, float rw, flo
|
||||
vset(p1->x, p1->y, 0.5f,1);
|
||||
vset(rx, ry, ru,1);
|
||||
}
|
||||
|
||||
|
||||
vset(lx1, ly1, lu,1);
|
||||
vset(p1->x - dlx1*rw, p1->y - dly1*rw, ru,1);
|
||||
|
||||
|
||||
} else {
|
||||
float rx0,ry0,rx1,ry1,a0,a1;
|
||||
chooseBevel(p1->flags & PT_INNERBEVEL, p0, p1, -rw, &rx0,&ry0, &rx1,&ry1);
|
||||
a0 = atan2f(dly0, dlx0);
|
||||
a1 = atan2f(dly1, dlx1);
|
||||
if (a1 < a0) a1 += PI_2;
|
||||
|
||||
|
||||
vset(p1->x + dlx0*rw, p1->y + dly0*rw, lu,1);
|
||||
vset(rx0, ry0, ru,1);
|
||||
|
||||
|
||||
n = clampi((int)ceilf(((a1 - a0) / PI) * ncap), 2, ncap);
|
||||
for (i = 0; i < n; i++) {
|
||||
float u = i/(float)(n-1);
|
||||
@@ -1140,10 +1140,10 @@ void GraphicsNode::roundJoin(VecPoint* p0, VecPoint* p1, float lw, float rw, flo
|
||||
vset(lx, ly, lu,1);
|
||||
vset(p1->x, p1->y, 0.5f,1);
|
||||
}
|
||||
|
||||
|
||||
vset(p1->x + dlx1*rw, p1->y + dly1*rw, lu,1);
|
||||
vset(rx1, ry1, ru,1);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1156,62 +1156,62 @@ void GraphicsNode::bevelJoin(VecPoint* p0, VecPoint* p1, float lw, float rw, flo
|
||||
float dly0 = -p0->dx;
|
||||
float dlx1 = p1->dy;
|
||||
float dly1 = -p1->dx;
|
||||
|
||||
|
||||
if (p1->flags & PT_LEFT) {
|
||||
chooseBevel(p1->flags & PT_INNERBEVEL, p0, p1, lw, &lx0,&ly0, &lx1,&ly1);
|
||||
|
||||
|
||||
vset(lx0, ly0, lu,1);
|
||||
vset(p1->x - dlx0*rw, p1->y - dly0*rw, ru,1);
|
||||
|
||||
|
||||
// if (p1->flags & PT_BEVEL) {
|
||||
// vset(lx0, ly0, lu,1);
|
||||
// vset(p1->x - dlx0*rw, p1->y - dly0*rw, ru,1);
|
||||
//
|
||||
//
|
||||
// vset(lx1, ly1, lu,1);
|
||||
// vset(p1->x - dlx1*rw, p1->y - dly1*rw, ru,1);
|
||||
// } else {
|
||||
// rx0 = p1->x - p1->dmx * rw;
|
||||
// ry0 = p1->y - p1->dmy * rw;
|
||||
//
|
||||
//
|
||||
// vset(p1->x, p1->y, 0.5f,1);
|
||||
// vset(p1->x - dlx0*rw, p1->y - dly0*rw, ru,1);
|
||||
//
|
||||
//
|
||||
// vset(rx0, ry0, ru,1);
|
||||
// vset(rx0, ry0, ru,1);
|
||||
//
|
||||
//
|
||||
// vset(p1->x, p1->y, 0.5f,1);
|
||||
// vset(p1->x - dlx1*rw, p1->y - dly1*rw, ru,1);
|
||||
// }
|
||||
|
||||
|
||||
vset(lx1, ly1, lu,1);
|
||||
vset(p1->x - dlx1*rw, p1->y - dly1*rw, ru,1);
|
||||
|
||||
|
||||
} else {
|
||||
chooseBevel(p1->flags & PT_INNERBEVEL, p0, p1, -rw, &rx0,&ry0, &rx1,&ry1);
|
||||
|
||||
|
||||
vset(p1->x + dlx0*lw, p1->y + dly0*lw, lu,1);
|
||||
vset(rx0, ry0, ru,1);
|
||||
|
||||
|
||||
// if (p1->flags & PT_BEVEL) {
|
||||
// vset(p1->x + dlx0*lw, p1->y + dly0*lw, lu,1);
|
||||
// vset(rx0, ry0, ru,1);
|
||||
//
|
||||
//
|
||||
// vset(p1->x + dlx1*lw, p1->y + dly1*lw, lu,1);
|
||||
// vset(rx1, ry1, ru,1);
|
||||
// } else {
|
||||
// lx0 = p1->x + p1->dmx * lw;
|
||||
// ly0 = p1->y + p1->dmy * lw;
|
||||
//
|
||||
//
|
||||
// vset(p1->x + dlx0*lw, p1->y + dly0*lw, lu,1);
|
||||
// vset(p1->x, p1->y, 0.5f,1);
|
||||
//
|
||||
//
|
||||
// vset(lx0, ly0, lu,1);
|
||||
// vset(lx0, ly0, lu,1);
|
||||
//
|
||||
//
|
||||
// vset(p1->x + dlx1*lw, p1->y + dly1*lw, lu,1);
|
||||
// vset(p1->x, p1->y, 0.5f,1);
|
||||
// }
|
||||
|
||||
|
||||
vset(p1->x + dlx1*lw, p1->y + dly1*lw, lu,1);
|
||||
vset(rx1, ry1, ru,1);
|
||||
}
|
||||
@@ -1229,7 +1229,7 @@ void GraphicsNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flag
|
||||
void GraphicsNode::onDraw(const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
if (!_verts || _nCommands <=0) return;
|
||||
|
||||
|
||||
auto program = getGLProgram();
|
||||
program->use();
|
||||
program->setUniformsForBuiltins(transform);
|
||||
@@ -1244,10 +1244,10 @@ void GraphicsNode::onDraw(const Mat4 &transform, uint32_t flags)
|
||||
|
||||
_vertsDirty = false;
|
||||
}
|
||||
|
||||
|
||||
if (_indicesDirty) {
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * _indicesOffset, _indices, GL_STREAM_DRAW);
|
||||
|
||||
|
||||
_indicesDirty = false;
|
||||
}
|
||||
|
||||
@@ -1263,14 +1263,14 @@ void GraphicsNode::onDraw(const Mat4 &transform, uint32_t flags)
|
||||
// draw paths
|
||||
for (int i = 0; i < _nCommands; i++) {
|
||||
Command* cmd = _commands[i];
|
||||
|
||||
|
||||
if (cmd->nIndices) {
|
||||
Color4F& color = cmd->color;
|
||||
program->setUniformLocationWith4f(colorLocation, color.r, color.g, color.b, color.a);
|
||||
program->setUniformLocationWith1f(strokeMultLocation, cmd->strokeMult);
|
||||
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->nIndices, GL_UNSIGNED_SHORT, (const GLvoid *)((size_t)cmd->indicesOffset*2));
|
||||
|
||||
|
||||
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, cmd->nVerts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 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
|
||||
@@ -21,7 +21,7 @@
|
||||
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 __CREATOR_CCGRAPHICSNODE_H__
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void reset () {
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
@@ -104,12 +104,12 @@ struct Path
|
||||
bool complex;
|
||||
};
|
||||
typedef struct Path Path;
|
||||
|
||||
|
||||
struct Command
|
||||
{
|
||||
cocos2d::Color4F color;
|
||||
float strokeMult;
|
||||
|
||||
|
||||
int nVerts;
|
||||
int vertsOffset;
|
||||
int nIndices;
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
void roundRect(float x, float y, float w, float h, float r);
|
||||
void ellipse(float cx, float cy, float rx, float ry);
|
||||
void circle(float cx, float cy, float r);
|
||||
|
||||
|
||||
void fillRect(float x, float y, float w, float h);
|
||||
|
||||
void close();
|
||||
@@ -203,7 +203,7 @@ protected:
|
||||
|
||||
static float normalize(float *x, float* y);
|
||||
static int curveDivs(float r, float arc, float tol);
|
||||
|
||||
|
||||
static void chooseBevel(int bevel, VecPoint* p0, VecPoint* p1, float w,
|
||||
float* x0, float* y0, float* x1, float* y1);
|
||||
|
||||
@@ -224,16 +224,16 @@ protected:
|
||||
|
||||
void allocVerts(int count);
|
||||
void allocIndices(int count);
|
||||
|
||||
|
||||
void vset(float x, float y, float u, float v);
|
||||
|
||||
|
||||
void pushCommand(cocos2d::Color4F& color, float strokeMult, int vertsOffset, int nVerts, int indicesOffset, int nIndices);
|
||||
|
||||
|
||||
void buttCapStart(VecPoint* p, float dx, float dy, float w, float d, float aa);
|
||||
void buttCapEnd(VecPoint* p, float dx, float dy, float w, float d, float aa);
|
||||
void roundCapStart(VecPoint* p, float dx, float dy, float w, int ncap, float aa);
|
||||
void roundCapEnd(VecPoint* p, float dx, float dy, float w, int ncap, float aa);
|
||||
|
||||
|
||||
void roundJoin(VecPoint* p0, VecPoint* p1, float lw, float rw, float lu, float ru, int ncap, float fringe);
|
||||
void bevelJoin(VecPoint* p0, VecPoint* p1, float lw, float rw, float lu, float ru, float fringe);
|
||||
protected:
|
||||
@@ -266,17 +266,17 @@ protected:
|
||||
// points
|
||||
int _nPoints;
|
||||
VecPointVector _points;
|
||||
|
||||
|
||||
// commands
|
||||
int _nCommands;
|
||||
CommandVector _commands;
|
||||
|
||||
|
||||
|
||||
|
||||
// path
|
||||
int _nPath;
|
||||
int _pathOffset;
|
||||
std::vector<Path*> _paths;
|
||||
|
||||
|
||||
Path* _curPath;
|
||||
|
||||
// verts
|
||||
|
||||
@@ -893,7 +893,8 @@ _distortionOffset(cocos2d::Vec2::ZERO),
|
||||
_distortionTiling(cocos2d::Vec2::ONE),
|
||||
_fillStart(0),
|
||||
_fillRange(0),
|
||||
_needRebuildRenderCommand(true)
|
||||
_needRebuildRenderCommand(true),
|
||||
_insideBounds(true)
|
||||
{
|
||||
this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
||||
this->setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
|
||||
@@ -1101,54 +1102,62 @@ void Scale9SpriteV2::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &tran
|
||||
if (!this->_spriteFrame || !this->_spriteFrame->getTexture()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this->_quadsDirty) {
|
||||
//rebuild quads
|
||||
this->_rebuildQuads();
|
||||
this->_needRebuildRenderCommand = true;
|
||||
}
|
||||
if(this->_needRebuildRenderCommand) {
|
||||
//fill triangles
|
||||
int vertsStep = this->_isTriangle ? 3 : 4;
|
||||
int indicesStep = this->_isTriangle ? 3 : 6;
|
||||
this->_verts.resize(_quads.size() * vertsStep);
|
||||
this->_indices.resize(_quads.size() * indicesStep);
|
||||
unsigned short indices[6];
|
||||
for(int index = 0; index < _quads.size(); ++index) {
|
||||
memcpy(&this->_verts[vertsStep * index], &this->_quads[index], sizeof(cocos2d::V3F_C4B_T2F) * vertsStep);
|
||||
if(this->_isTriangle) {
|
||||
indices[0] = indicesStep * index;
|
||||
indices[1] = indicesStep * index + 1;
|
||||
indices[2] = indicesStep * index + 2;
|
||||
|
||||
} else {
|
||||
indices[0] = vertsStep * index;
|
||||
indices[1] = vertsStep * index + 1;
|
||||
indices[2] = vertsStep * index + 2;
|
||||
indices[3] = vertsStep * index + 3;
|
||||
indices[4] = vertsStep * index + 2;
|
||||
indices[5] = vertsStep * index + 1;
|
||||
|
||||
}
|
||||
|
||||
memcpy(&this->_indices[indicesStep * index], indices, sizeof(unsigned short) * indicesStep);
|
||||
|
||||
#if CC_USE_CULLING
|
||||
// Don't calculate the culling if the transform was not updated
|
||||
_insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
|
||||
if (_insideBounds)
|
||||
#endif
|
||||
{
|
||||
if (this->_quadsDirty) {
|
||||
//rebuild quads
|
||||
this->_rebuildQuads();
|
||||
this->_needRebuildRenderCommand = true;
|
||||
}
|
||||
|
||||
this->_needRebuildRenderCommand = false;
|
||||
|
||||
}
|
||||
if (this->_needRebuildRenderCommand) {
|
||||
//fill triangles
|
||||
int vertsStep = this->_isTriangle ? 3 : 4;
|
||||
int indicesStep = this->_isTriangle ? 3 : 6;
|
||||
this->_verts.resize(_quads.size() * vertsStep);
|
||||
this->_indices.resize(_quads.size() * indicesStep);
|
||||
unsigned short indices[6];
|
||||
for (int index = 0; index < _quads.size(); ++index) {
|
||||
memcpy(&this->_verts[vertsStep * index], &this->_quads[index], sizeof(cocos2d::V3F_C4B_T2F) * vertsStep);
|
||||
if (this->_isTriangle) {
|
||||
indices[0] = indicesStep * index;
|
||||
indices[1] = indicesStep * index + 1;
|
||||
indices[2] = indicesStep * index + 2;
|
||||
|
||||
if (!_indices.empty() && !_verts.empty()) {
|
||||
cocos2d::TrianglesCommand::Triangles triangles;
|
||||
triangles.indices = &this->_indices[0];
|
||||
triangles.verts = &this->_verts[0];
|
||||
triangles.vertCount = (int)this->_verts.size();
|
||||
triangles.indexCount = (int)this->_indices.size();
|
||||
auto texture = this->_spriteFrame->getTexture();
|
||||
this->_renderCommand.init(_globalZOrder, texture->getName(), _glProgramState, _blendFunc, triangles, transform, 0);
|
||||
renderer->addCommand(&this->_renderCommand);
|
||||
}
|
||||
else {
|
||||
indices[0] = vertsStep * index;
|
||||
indices[1] = vertsStep * index + 1;
|
||||
indices[2] = vertsStep * index + 2;
|
||||
indices[3] = vertsStep * index + 3;
|
||||
indices[4] = vertsStep * index + 2;
|
||||
indices[5] = vertsStep * index + 1;
|
||||
|
||||
}
|
||||
|
||||
memcpy(&this->_indices[indicesStep * index], indices, sizeof(unsigned short) * indicesStep);
|
||||
|
||||
}
|
||||
|
||||
this->_needRebuildRenderCommand = false;
|
||||
|
||||
}
|
||||
|
||||
if (!_indices.empty() && !_verts.empty()) {
|
||||
cocos2d::TrianglesCommand::Triangles triangles;
|
||||
triangles.indices = &this->_indices[0];
|
||||
triangles.verts = &this->_verts[0];
|
||||
triangles.vertCount = (int)this->_verts.size();
|
||||
triangles.indexCount = (int)this->_indices.size();
|
||||
auto texture = this->_spriteFrame->getTexture();
|
||||
this->_renderCommand.init(_globalZOrder, texture->getName(), _glProgramState, _blendFunc, triangles, transform, 0);
|
||||
renderer->addCommand(&this->_renderCommand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ private:
|
||||
|
||||
cocos2d::Vec2 _distortionOffset;
|
||||
cocos2d::Vec2 _distortionTiling;
|
||||
bool _insideBounds;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include "base/CCEventType.h"
|
||||
#include "2d/CCScene.h"
|
||||
|
||||
#include "editor-support/creator/CCCameraNode.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// helper
|
||||
@@ -878,39 +880,24 @@ void Renderer::flushTriangles()
|
||||
}
|
||||
|
||||
// helpers
|
||||
bool Renderer::checkVisibility(const Mat4 &transform, const Size &size)
|
||||
bool Renderer::checkVisibility(const Mat4& transform, const Size& size)
|
||||
{
|
||||
auto scene = Director::getInstance()->getRunningScene();
|
||||
creator::CameraNode* camera = creator::CameraNode::getInstance();
|
||||
|
||||
//If draw to Rendertexture, return true directly.
|
||||
// only cull the default camera. The culling algorithm is valid for default camera.
|
||||
if (!scene)
|
||||
return true;
|
||||
|
||||
auto director = Director::getInstance();
|
||||
Rect visiableRect(director->getVisibleOrigin(), director->getVisibleSize());
|
||||
Rect visibleRect;
|
||||
if (!camera || camera->visitingIndex <= 0) {
|
||||
visibleRect.origin = Director::getInstance()->getVisibleOrigin();
|
||||
visibleRect.size = Director::getInstance()->getVisibleSize();
|
||||
}
|
||||
else {
|
||||
visibleRect = camera->getVisibleRect();
|
||||
}
|
||||
|
||||
// transform center point to screen space
|
||||
float hSizeX = size.width/2;
|
||||
float hSizeY = size.height/2;
|
||||
Vec3 v3p(hSizeX, hSizeY, 0);
|
||||
transform.transformPoint(&v3p);
|
||||
// Vec2 v2p = Camera::getVisitingCamera()->projectGL(v3p);
|
||||
|
||||
// convert content size to world coordinates
|
||||
float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4]));
|
||||
float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5]));
|
||||
|
||||
// enlarge visible rect half size in screen coord
|
||||
visiableRect.origin.x -= wshw;
|
||||
visiableRect.origin.y -= wshh;
|
||||
visiableRect.size.width += wshw * 2;
|
||||
visiableRect.size.height += wshh * 2;
|
||||
// bool ret = visiableRect.containsPoint(v2p);
|
||||
return true;
|
||||
Rect rect(0,0, size.width, size.height);
|
||||
rect = RectApplyTransform(rect, transform);
|
||||
return rect.intersectsRect(visibleRect);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::setClearColor(const Color4F &clearColor)
|
||||
{
|
||||
_clearColor = clearColor;
|
||||
|
||||
@@ -239,6 +239,7 @@ gl.DEPTH_COMPONENT32_OES = 0x81a7;
|
||||
gl.DEPTH_EXT = 0x1801;
|
||||
gl.DEPTH_FUNC = 0xb74;
|
||||
gl.DEPTH_RANGE = 0xb70;
|
||||
gl.DEPTH_STENCIL = 0x84f9;
|
||||
gl.DEPTH_STENCIL_OES = 0x84f9;
|
||||
gl.DEPTH_TEST = 0xb71;
|
||||
gl.DEPTH_WRITEMASK = 0xb72;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cocos2d-x-lite",
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1",
|
||||
"description": "Cocos2d-x, compact version ==========================",
|
||||
"main": "gulpfile.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user