setTexParams() is passed as a const reference

All structs (PODs), should be passed as const reference.
eg: Size, Point, ccTexParams, etc... should be passed as const reference.
This commit is contained in:
Ricardo Quesada 2013-07-03 17:59:22 -07:00
parent 216c6eada5
commit 1d011510af
5 changed files with 26 additions and 26 deletions

View File

@ -776,17 +776,17 @@ bool Texture2D::hasMipmaps() const
return _hasMipmaps;
}
void Texture2D::setTexParameters(ccTexParams *texParams)
void Texture2D::setTexParameters(const ccTexParams &texParams)
{
CCAssert( (_pixelsWide == ccNextPOT(_pixelsWide) || texParams->wrapS == GL_CLAMP_TO_EDGE) &&
(_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams->wrapT == GL_CLAMP_TO_EDGE),
CCAssert( (_pixelsWide == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
(_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
"GL_CLAMP_TO_EDGE should be used in NPOT dimensions");
ccGLBindTexture2D( _name );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams->minFilter );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams.minFilter );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams.magFilter );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams.wrapS );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams.wrapT );
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTexture::setTexParameters(this, texParams);
@ -809,7 +809,7 @@ void Texture2D::setAliasTexParameters()
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
#if CC_ENABLE_CACHE_TEXTURE_DATA
ccTexParams texParams = {(GLuint)(_hasMipmaps?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST),GL_NEAREST,GL_NONE,GL_NONE};
VolatileTexture::setTexParameters(this, &texParams);
VolatileTexture::setTexParameters(this, texParams);
#endif
}
@ -829,7 +829,7 @@ void Texture2D::setAntiAliasTexParameters()
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
#if CC_ENABLE_CACHE_TEXTURE_DATA
ccTexParams texParams = {(GLuint)(_hasMipmaps?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR),GL_LINEAR,GL_NONE,GL_NONE};
VolatileTexture::setTexParameters(this, &texParams);
VolatileTexture::setTexParameters(this, texParams);
#endif
}

View File

@ -151,7 +151,7 @@ public:
@since v0.8
*/
void setTexParameters(ccTexParams* texParams);
void setTexParameters(const ccTexParams& texParams);
/** sets antialias texture parameters:
- GL_TEXTURE_MIN_FILTER = GL_LINEAR

View File

@ -746,18 +746,18 @@ void VolatileTexture::addStringTexture(Texture2D *tt, const char* text, const Si
vt->_text = text;
}
void VolatileTexture::setTexParameters(Texture2D *t, ccTexParams *texParams)
void VolatileTexture::setTexParameters(Texture2D *t, const ccTexParams &texParams)
{
VolatileTexture *vt = findVolotileTexture(t);
if (texParams->minFilter != GL_NONE)
vt->_texParams.minFilter = texParams->minFilter;
if (texParams->magFilter != GL_NONE)
vt->_texParams.magFilter = texParams->magFilter;
if (texParams->wrapS != GL_NONE)
vt->_texParams.wrapS = texParams->wrapS;
if (texParams->wrapT != GL_NONE)
vt->_texParams.wrapT = texParams->wrapT;
if (texParams.minFilter != GL_NONE)
vt->_texParams.minFilter = texParams.minFilter;
if (texParams.magFilter != GL_NONE)
vt->_texParams.magFilter = texParams.magFilter;
if (texParams.wrapS != GL_NONE)
vt->_texParams.wrapS = texParams.wrapS;
if (texParams.wrapT != GL_NONE)
vt->_texParams.wrapT = texParams.wrapT;
}
void VolatileTexture::removeTexture(Texture2D *t)
@ -851,7 +851,7 @@ void VolatileTexture::reloadAllTextures()
default:
break;
}
vt->texture->setTexParameters(&vt->_texParams);
vt->texture->setTexParameters(vt->_texParams);
}
isReloading = false;

View File

@ -218,7 +218,7 @@ public:
static void addDataTexture(Texture2D *tt, void* data, Texture2DPixelFormat pixelFormat, const Size& contentSize);
static void addImage(Texture2D *tt, Image *image);
static void setTexParameters(Texture2D *t, ccTexParams *texParams);
static void setTexParameters(Texture2D *t, const ccTexParams &texParams);
static void removeTexture(Texture2D *t);
static void reloadAllTextures();

View File

@ -261,7 +261,7 @@ void TextureMipMap::onEnter()
Texture2D *texture0 = TextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png");
texture0->generateMipmap();
ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
texture0->setTexParameters(&texParams);
texture0->setTexParameters(texParams);
Texture2D *texture1 = TextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas_nomipmap.png");
@ -317,7 +317,7 @@ void TexturePVRMipMap::onEnter()
// support mipmap filtering
ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
imgMipMap->getTexture()->setTexParameters(&texParams);
imgMipMap->getTexture()->setTexParameters(texParams);
}
Sprite *img = Sprite::create("Images/logo-nomipmap.pvr");
@ -363,7 +363,7 @@ void TexturePVRMipMap2::onEnter()
// support mipmap filtering
ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
imgMipMap->getTexture()->setTexParameters(&texParams);
imgMipMap->getTexture()->setTexParameters(texParams);
Sprite *img = Sprite::create("Images/test_image.png");
img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
@ -1545,7 +1545,7 @@ void TextureGlClamp::onEnter()
addChild(sprite, -1, kTagSprite1);
sprite->setPosition(ccp(size.width/2,size.height/2));
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE};
sprite->getTexture()->setTexParameters(&params);
sprite->getTexture()->setTexParameters(params);
auto rotate = RotateBy::create(4, 360);
sprite->runAction(rotate);
@ -1582,7 +1582,7 @@ void TextureGlRepeat::onEnter()
addChild(sprite, -1, kTagSprite1);
sprite->setPosition(ccp(size.width/2,size.height/2));
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
sprite->getTexture()->setTexParameters(&params);
sprite->getTexture()->setTexParameters(params);
auto rotate = RotateBy::create(4, 360);
sprite->runAction(rotate);