mirror of https://github.com/axmolengine/axmol.git
fixed #560: upgrade misc_nodes to 1.0.0-rc3
This commit is contained in:
parent
652bd02f83
commit
6b97a381e9
|
@ -70,7 +70,7 @@ public:
|
|||
bool initWithFade(float fade, float seg, const char *imagePath, float width, float length, ccColor4B color);
|
||||
|
||||
/** polling function */
|
||||
void updateMotion(ccTime delta);
|
||||
void update(ccTime delta);
|
||||
protected:
|
||||
float m_fSegThreshold;
|
||||
float m_fWidth;
|
||||
|
|
|
@ -93,7 +93,7 @@ protected:
|
|||
float m_fPercentage;
|
||||
CCSprite *m_pSprite;
|
||||
int m_nVertexDataCount;
|
||||
ccV2F_C4F_T2F *m_pVertexData;
|
||||
ccV2F_C4B_T2F *m_pVertexData;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -97,11 +97,6 @@ protected:
|
|||
CCTexture2D* m_pTexture;
|
||||
|
||||
GLenum m_ePixelFormat;
|
||||
GLfloat m_aClearColor[4];
|
||||
|
||||
private:
|
||||
void saveGLstate();
|
||||
void restoreGLstate();
|
||||
};
|
||||
|
||||
} // namespace cocos2d
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -175,7 +176,7 @@ static inline ccTex2F tex2(const float u, const float v)
|
|||
typedef struct _ccPointSprite
|
||||
{
|
||||
ccVertex2F pos; // 8 bytes
|
||||
ccColor4F colors; // 16 bytes
|
||||
ccColor4B colors; // 4 bytes
|
||||
GLfloat size; // 4 bytes
|
||||
} ccPointSprite;
|
||||
|
||||
|
@ -211,6 +212,17 @@ ccg(const int x, const int y)
|
|||
return v;
|
||||
}
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4B
|
||||
typedef struct _ccV2F_C4B_T2F
|
||||
{
|
||||
//! vertices (2F)
|
||||
ccVertex2F vertices;
|
||||
//! colors (4B)
|
||||
ccColor4B colors;
|
||||
//! tex coords (2F)
|
||||
ccTex2F texCoords;
|
||||
} ccV2F_C4B_T2F;
|
||||
|
||||
//! a Point with a vertex point, a tex coord point and a color 4F
|
||||
typedef struct _ccV2F_C4F_T2F
|
||||
{
|
||||
|
@ -237,6 +249,19 @@ typedef struct _ccV3F_C4B_T2F
|
|||
ccTex2F texCoords; // 8 byts
|
||||
} ccV3F_C4B_T2F;
|
||||
|
||||
//! 4 ccVertex2FTex2FColor4B Quad
|
||||
typedef struct _ccV2F_C4B_T2F_Quad
|
||||
{
|
||||
//! bottom left
|
||||
ccV2F_C4B_T2F bl;
|
||||
//! bottom right
|
||||
ccV2F_C4B_T2F br;
|
||||
//! top left
|
||||
ccV2F_C4B_T2F tl;
|
||||
//! top right
|
||||
ccV2F_C4B_T2F tr;
|
||||
} ccV2F_C4B_T2F_Quad;
|
||||
|
||||
//! 4 ccVertex3FTex2FColor4B
|
||||
typedef struct _ccV3F_C4B_T2F_Quad
|
||||
{
|
||||
|
|
|
@ -58,12 +58,12 @@ bool CCMotionStreak::initWithFade(float fade, float seg, const char *imagePath,
|
|||
m_pRibbon = CCRibbon::ribbonWithWidth(m_fWidth, imagePath, length, color, fade);
|
||||
this->addChild(m_pRibbon);
|
||||
|
||||
// update ribbon position
|
||||
this->schedule(schedule_selector(CCMotionStreak::updateMotion), 0);
|
||||
// update ribbon position. Use schedule:interval and not scheduleUpdated. (cocos2d-iphone)issue #1075
|
||||
this->schedule(schedule_selector(CCMotionStreak::update), 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCMotionStreak::updateMotion(ccTime delta)
|
||||
void CCMotionStreak::update(ccTime delta)
|
||||
{
|
||||
CCPoint location = this->convertToWorldSpace(CCPointZero);
|
||||
m_pRibbon->setPosition(ccp(-1*location.x, -1*location.y));
|
||||
|
|
|
@ -96,19 +96,7 @@ void CCProgressTimer::setPercentage(float fPercentage)
|
|||
{
|
||||
if (m_fPercentage != fPercentage)
|
||||
{
|
||||
if (m_fPercentage < 0.f)
|
||||
{
|
||||
m_fPercentage = 0.f;
|
||||
} else
|
||||
if (fPercentage > 100.0f)
|
||||
{
|
||||
m_fPercentage = 100.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fPercentage = fPercentage;
|
||||
}
|
||||
|
||||
m_fPercentage = clampf(m_fPercentage, 0, 100);
|
||||
updateProgress();
|
||||
}
|
||||
}
|
||||
|
@ -176,18 +164,15 @@ ccVertex2F CCProgressTimer::vertexFromTexCoord(cocos2d::CCPoint texCoord)
|
|||
|
||||
void CCProgressTimer::updateColor(void)
|
||||
{
|
||||
ccColor4F color = ccc4FFromccc3B(m_pSprite->getColor());
|
||||
GLbyte op = m_pSprite->getOpacity();
|
||||
ccColor3B c3b = m_pSprite->getColor();
|
||||
|
||||
ccColor4B color = {c3b.r, c3b.g, c3b.b, op};
|
||||
if (m_pSprite->getTexture()->getHasPremultipliedAlpha())
|
||||
{
|
||||
float op = m_pSprite->getOpacity() / 255.f;
|
||||
color.r *= op;
|
||||
color.g *= op;
|
||||
color.b *= op;
|
||||
color.a = op;
|
||||
}
|
||||
else
|
||||
{
|
||||
color.a = m_pSprite->getOpacity() / 255.f;
|
||||
color.r *= op / 255;
|
||||
color.g *= op / 255;
|
||||
color.b *= op / 255;
|
||||
}
|
||||
|
||||
if (m_pVertexData)
|
||||
|
@ -344,7 +329,7 @@ void CCProgressTimer::updateRadial(void)
|
|||
if (! m_pVertexData)
|
||||
{
|
||||
m_nVertexDataCount = index + 3;
|
||||
m_pVertexData = new ccV2F_C4F_T2F[m_nVertexDataCount];
|
||||
m_pVertexData = new ccV2F_C4B_T2F[m_nVertexDataCount];
|
||||
assert(m_pVertexData);
|
||||
|
||||
updateColor();
|
||||
|
@ -420,6 +405,7 @@ void CCProgressTimer::updateBar(void)
|
|||
CCPoint tMax = ccp(m_pSprite->getTexture()->getMaxS(), m_pSprite->getTexture()->getMaxT());
|
||||
|
||||
unsigned char vIndexes[2] = {0, 0};
|
||||
unsigned char index = 0;
|
||||
|
||||
// We know vertex data is always equal to the 4 corners
|
||||
// If we don't have vertex data then we create it here and populate
|
||||
|
@ -427,7 +413,7 @@ void CCProgressTimer::updateBar(void)
|
|||
if (! m_pVertexData)
|
||||
{
|
||||
m_nVertexDataCount = kProgressTextureCoordsCount;
|
||||
m_pVertexData = new ccV2F_C4F_T2F[m_nVertexDataCount];
|
||||
m_pVertexData = new ccV2F_C4B_T2F[m_nVertexDataCount];
|
||||
assert(m_pVertexData);
|
||||
|
||||
if (m_eType == kCCProgressTimerTypeHorizontalBarLR)
|
||||
|
@ -451,7 +437,7 @@ void CCProgressTimer::updateBar(void)
|
|||
m_pVertexData[vIndexes[1] = 2].texCoords = tex2(tMax.x, 0);
|
||||
}
|
||||
|
||||
unsigned char index = vIndexes[0];
|
||||
index = vIndexes[0];
|
||||
m_pVertexData[index].vertices = vertexFromTexCoord(ccp(m_pVertexData[index].texCoords.u,
|
||||
m_pVertexData[index].texCoords.v));
|
||||
|
||||
|
@ -463,7 +449,7 @@ void CCProgressTimer::updateBar(void)
|
|||
{
|
||||
if (m_pSprite->isFlipX())
|
||||
{
|
||||
unsigned char index = vIndexes[0];
|
||||
index = vIndexes[0];
|
||||
m_pVertexData[index].texCoords.u = tMax.x - m_pVertexData[index].texCoords.u;
|
||||
index = vIndexes[1];
|
||||
m_pVertexData[index].texCoords.u = tMax.x - m_pVertexData[index].texCoords.u;
|
||||
|
@ -471,7 +457,7 @@ void CCProgressTimer::updateBar(void)
|
|||
|
||||
if (m_pSprite->isFlipY())
|
||||
{
|
||||
unsigned char index = vIndexes[0];
|
||||
index = vIndexes[0];
|
||||
m_pVertexData[index].texCoords.v = tMax.y - m_pVertexData[index].texCoords.v;
|
||||
index = vIndexes[1];
|
||||
m_pVertexData[index].texCoords.v = tMax.y - m_pVertexData[index].texCoords.v;
|
||||
|
@ -502,7 +488,7 @@ void CCProgressTimer::updateBar(void)
|
|||
m_pVertexData[vIndexes[1] = 3].texCoords = tex2(tMax.x, tMax.y*alpha);
|
||||
}
|
||||
|
||||
unsigned char index = vIndexes[0];
|
||||
index = vIndexes[0];
|
||||
m_pVertexData[index].vertices = vertexFromTexCoord(ccp(m_pVertexData[index].texCoords.u,
|
||||
m_pVertexData[index].texCoords.v));
|
||||
index = vIndexes[1];
|
||||
|
@ -513,7 +499,7 @@ void CCProgressTimer::updateBar(void)
|
|||
{
|
||||
if (m_pSprite->isFlipX())
|
||||
{
|
||||
unsigned char index = vIndexes[0];
|
||||
index = vIndexes[0];
|
||||
m_pVertexData[index].texCoords.u = tMax.x - m_pVertexData[index].texCoords.u;
|
||||
index = vIndexes[1];
|
||||
m_pVertexData[index].texCoords.u = tMax.x - m_pVertexData[index].texCoords.u;
|
||||
|
@ -521,7 +507,7 @@ void CCProgressTimer::updateBar(void)
|
|||
|
||||
if (m_pSprite->isFlipY())
|
||||
{
|
||||
unsigned char index = vIndexes[0];
|
||||
index = vIndexes[0];
|
||||
m_pVertexData[index].texCoords.v = tMax.y - m_pVertexData[index].texCoords.v;
|
||||
index = vIndexes[1];
|
||||
m_pVertexData[index].texCoords.v = tMax.y - m_pVertexData[index].texCoords.v;
|
||||
|
@ -570,9 +556,9 @@ void CCProgressTimer::draw(void)
|
|||
// Replaced [texture_ drawAtPoint:CCPointZero] with my own vertexData
|
||||
// Everything above me and below me is copied from CCTextureNode's draw
|
||||
glBindTexture(GL_TEXTURE_2D, m_pSprite->getTexture()->getName());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(ccV2F_C4F_T2F), &m_pVertexData[0].vertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(ccV2F_C4F_T2F), &m_pVertexData[0].texCoords);
|
||||
glColorPointer(4, GL_FLOAT, sizeof(ccV2F_C4F_T2F), &m_pVertexData[0].colors);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(ccV2F_C4B_T2F), &m_pVertexData[0].vertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(ccV2F_C4B_T2F), &m_pVertexData[0].texCoords);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ccV2F_C4B_T2F), &m_pVertexData[0].colors);
|
||||
|
||||
if(m_eType == kCCProgressTimerTypeRadialCCW || m_eType == kCCProgressTimerTypeRadialCW)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,6 @@ CCRenderTexture::CCRenderTexture()
|
|||
, m_pTexture(0)
|
||||
, m_ePixelFormat(kCCPixelFormatRGBA8888)
|
||||
{
|
||||
memset(m_aClearColor, 0, sizeof(m_aClearColor));
|
||||
}
|
||||
|
||||
CCRenderTexture::~CCRenderTexture()
|
||||
|
@ -155,9 +154,6 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma
|
|||
|
||||
void CCRenderTexture::begin()
|
||||
{
|
||||
saveGLstate();
|
||||
|
||||
CC_DISABLE_DEFAULT_GL_STATES();
|
||||
// Save the current matrix
|
||||
glPushMatrix();
|
||||
|
||||
|
@ -176,36 +172,32 @@ void CCRenderTexture::begin()
|
|||
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
|
||||
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above
|
||||
|
||||
// Issue #1145
|
||||
// There is no need to enable the default GL states here
|
||||
// but since CCRenderTexture is mostly used outside the "render" loop
|
||||
// these states needs to be enabled.
|
||||
// Since this bug was discovered in API-freeze (very close of 1.0 release)
|
||||
// This bug won't be fixed to prevent incompatibilities with code.
|
||||
//
|
||||
// If you understand the above mentioned message, then you can comment the following line
|
||||
// and enable the gl states manually, in case you need them.
|
||||
|
||||
CC_ENABLE_DEFAULT_GL_STATES();
|
||||
}
|
||||
|
||||
void CCRenderTexture::beginWithClear(float r, float g, float b, float a)
|
||||
{
|
||||
this->saveGLstate();
|
||||
this->begin();
|
||||
|
||||
CC_DISABLE_DEFAULT_GL_STATES();
|
||||
// Save the current matrix
|
||||
glPushMatrix();
|
||||
// save clear color
|
||||
GLfloat clearColor[4];
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE,clearColor);
|
||||
|
||||
CCSize texSize = m_pTexture->getContentSizeInPixels();
|
||||
glClearColor(r, g, b, a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels();
|
||||
float widthRatio = size.width / texSize.width;
|
||||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
// Adjust the orthographic propjection and viewport
|
||||
ccglOrtho((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1);
|
||||
glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
|
||||
// CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, texSize.width, texSize.height);
|
||||
|
||||
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
|
||||
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above
|
||||
|
||||
glClearColor(r, g, b, a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
CC_ENABLE_DEFAULT_GL_STATES();
|
||||
// restore clear color
|
||||
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
|
||||
}
|
||||
|
||||
void CCRenderTexture::end()
|
||||
|
@ -216,28 +208,14 @@ void CCRenderTexture::end()
|
|||
CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels();
|
||||
// glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
|
||||
CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height);
|
||||
this->restoreGLstate();
|
||||
}
|
||||
|
||||
void CCRenderTexture::clear(float r, float g, float b, float a)
|
||||
{
|
||||
this->begin();
|
||||
glClearColor(r, g, b, a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
this->beginWithClear(r, g, b, a);
|
||||
this->end();
|
||||
}
|
||||
|
||||
void CCRenderTexture::saveGLstate()
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, m_aClearColor);
|
||||
}
|
||||
|
||||
void CCRenderTexture::restoreGLstate()
|
||||
{
|
||||
glClearColor(m_aClearColor[0], m_aClearColor[1], m_aClearColor[2], m_aClearColor[3]);
|
||||
}
|
||||
|
||||
|
||||
bool CCRenderTexture::saveBuffer(const char *name)
|
||||
{
|
||||
return this->saveBuffer(name, kCCImageFormatJPG);
|
||||
|
|
Loading…
Reference in New Issue