本文整理汇总了C++中TextureCache类的典型用法代码示例。如果您正苦于以下问题:C++ TextureCache类的具体用法?C++ TextureCache怎么用?C++ TextureCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextureCache类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadSpriteSheet
void TextureSprite::loadSpriteSheet(const char *filename)
{
TextureCache * textureCache = TextureCache::getInstance();
sheet.textureID = textureCache->loadTexture((char*)filename);//ilutGLLoadImage((char*)filename);
sheet.width = textureCache->getWidth(sheet.textureID);//ilGetInteger(IL_IMAGE_WIDTH);
sheet.height = textureCache->getHeight(sheet.textureID);//ilGetInteger(IL_IMAGE_HEIGHT);
}
示例2: AliceParticle2DSystem_SetTexture
int AliceParticle2DSystem_SetTexture(lua_State*L)
{
Alice::Particle2DSystem * ptr = (Alice::Particle2DSystem*)lua_touserdata(L, 1);
std::string fileName = lua_tostring(L,2);
TextureCache * pTextureCache = Director::getInstance()->getTextureCache();
Texture2D* texture=pTextureCache->addImage(fileName);
((ParticleSystemQuad*)ptr->node)->setTexture(texture);
return 0;
}
示例3:
/*!
@brief デストラクタ
画像とテクスチャを解放する。
*/
AKGauge::~AKGauge()
{
// 画像を解放する
m_emptyImage->removeFromParentAndCleanup(true);
m_fullImage->removeFromParentAndCleanup(true);
// テクスチャを解放する
TextureCache *cache = Director::getInstance()->getTextureCache();
cache->removeTextureForKey(m_emptyFileName);
cache->removeTextureForKey(m_fullFileName);
}
示例4: it
void LWFResourceCache::unloadLWFDataInternal(const shared_ptr<LWFData> &data)
{
map<string, bool>::iterator
it(data->resourceCache.begin()), itend(data->resourceCache.end());
TextureCache *cache = Director::getInstance()->getTextureCache();
for (; it != itend; ++it) {
Texture2D *texture = cache->getTextureForKey(it->first.c_str());
if (texture && texture->getReferenceCount() == 1)
cache->removeTexture(texture);
}
}
示例5: onFinish
void TextureManager::onFinish()
{
TextureCache disposing;
disposing.swap(_cached);
for (TextureCache::iterator itr = disposing.begin(), end = disposing.end(); itr != end; ++itr)
{
(*itr)->dispose();
}
disposing.clear();
g_Contents->Unregister(this);
}
示例6: getTexture
namespace ResourceManager {
TextureCache _textureCache;
GLTexture getTexture(std::string texturePath) {
return _textureCache.getTexture(texturePath);
}
}
示例7: assert
//
// only call this function immediately after GetOverlayList()
// which will ensure the list of texture id's are valid
//
int gstTextureManager::prepareTexture(TexTile& tile,
const gstTextureGuard &tex) {
// if no secondary textures have been loaded, return immediately
if (getCurrTexID() == 0)
return -1;
tile.src = tex->id();
// determine what is the best tile that exists in our db
TileExistance* te = tile_existance_cache_->fetch(tile.addr());
assert(te != NULL);
// no texture available
if (te->bestAvailable == 0)
return -1;
// now try to get this best one, but take anything less as long
// as we can get something immediately
// this will fill our read queue with everything from this tile
// all the way up the stack until we've found a tile
requested_level_ = LEVFROMADDR(te->bestAvailable);
while (tile.lev > requested_level_)
tile.upLevel();
uint texid;
TextureCache* textureCache = tile.alpha() == 0 ? overlay_RGB_texture_cache_ :
overlay_alpha_texture_cache_;
while ((texid = textureCache->fetchAndPin(tile.addr())) == 0) {
if (tile.upLevel() == -1)
return -1;
}
// we found one, so let's load it up!
glBindTexture(GL_TEXTURE_2D, texid);
return tile.lev;
}
示例8: preloadImages
void LoadingScene::preloadImages()
{
TextureCache* textureCache = Director::getInstance()->getTextureCache();
textureCache->addImageAsync(BACKGROUND_IMAGE_GAME, CC_CALLBACK_1(LoadingScene::onAssetPreloaded, this));
textureCache->addImageAsync(BACKGROUND_IMAGE_MAIN_MENU, CC_CALLBACK_1(LoadingScene::onAssetPreloaded, this));
textureCache->addImageAsync(SPRITE_ENEMY_SPACESHIP, CC_CALLBACK_1(LoadingScene::onAssetPreloaded, this));
textureCache->addImageAsync(SPRITE_PLAYER_SPACESHIP, CC_CALLBACK_1(LoadingScene::onAssetPreloaded, this));
textureCache->addImageAsync(PLANET_TEXTURE_MARS, CC_CALLBACK_1(LoadingScene::onAssetPreloaded, this));
}
示例9:
void TextureSource::get_texels_2x2(
TextureCache& texture_cache,
const int ix,
const int iy,
Color4f& t00,
Color4f& t10,
Color4f& t01,
Color4f& t11) const
{
const Vector<size_t, 2> p00 =
constrain_to_canvas(
m_texture_instance.get_addressing_mode(),
m_texture_props.m_canvas_width,
m_texture_props.m_canvas_height,
ix + 0,
iy + 0);
const Vector<size_t, 2> p11 =
constrain_to_canvas(
m_texture_instance.get_addressing_mode(),
m_texture_props.m_canvas_width,
m_texture_props.m_canvas_height,
ix + 1,
iy + 1);
const Vector<size_t, 2> p10(p11.x, p00.y);
const Vector<size_t, 2> p01(p00.x, p11.y);
// Compute the coordinates of the tile containing each texel.
const size_t tile_x_00 = truncate<size_t>(p00.x * m_texture_props.m_rcp_tile_width);
const size_t tile_y_00 = truncate<size_t>(p00.y * m_texture_props.m_rcp_tile_height);
const size_t tile_x_11 = truncate<size_t>(p11.x * m_texture_props.m_rcp_tile_width);
const size_t tile_y_11 = truncate<size_t>(p11.y * m_texture_props.m_rcp_tile_height);
// Check whether all four texels are part of the same tile.
const size_t tile_x_mask = tile_x_00 ^ tile_x_11;
const size_t tile_y_mask = tile_y_00 ^ tile_y_11;
if (tile_x_mask | tile_y_mask)
{
// Compute the tile space coordinates of each texel.
const size_t pixel_x_00 = p00.x - tile_x_00 * m_texture_props.m_tile_width;
const size_t pixel_y_00 = p00.y - tile_y_00 * m_texture_props.m_tile_height;
const size_t pixel_x_11 = p11.x - tile_x_11 * m_texture_props.m_tile_width;
const size_t pixel_y_11 = p11.y - tile_y_11 * m_texture_props.m_tile_height;
// Sample the tile.
sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_00, tile_y_00, pixel_x_00, pixel_y_00, t00);
sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_11, tile_y_00, pixel_x_11, pixel_y_00, t10);
sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_00, tile_y_11, pixel_x_00, pixel_y_11, t01);
sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_11, tile_y_11, pixel_x_11, pixel_y_11, t11);
}
else
{
// Compute the tile space coordinates of each texel.
const size_t org_x = tile_x_00 * m_texture_props.m_tile_width;
const size_t org_y = tile_y_00 * m_texture_props.m_tile_height;
const size_t pixel_x_00 = p00.x - org_x;
const size_t pixel_y_00 = p00.y - org_y;
const size_t pixel_x_11 = p11.x - org_x;
const size_t pixel_y_11 = p11.y - org_y;
// Retrieve the tile.
const Tile& tile =
texture_cache.get(
m_assembly_uid,
m_texture_uid,
tile_x_00,
tile_y_00);
// Sample the tile.
if (tile.get_channel_count() == 3)
{
Color3f rgb;
tile.get_pixel(pixel_x_00, pixel_y_00, rgb);
t00[0] = rgb[0];
t00[1] = rgb[1];
t00[2] = rgb[2];
t00[3] = 1.0f;
tile.get_pixel(pixel_x_11, pixel_y_00, rgb);
t10[0] = rgb[0];
t10[1] = rgb[1];
t10[2] = rgb[2];
t10[3] = 1.0f;
tile.get_pixel(pixel_x_00, pixel_y_11, rgb);
t01[0] = rgb[0];
t01[1] = rgb[1];
t01[2] = rgb[2];
t01[3] = 1.0f;
tile.get_pixel(pixel_x_11, pixel_y_11, rgb);
t11[0] = rgb[0];
t11[1] = rgb[1];
t11[2] = rgb[2];
t11[3] = 1.0f;
}
else
//.........这里部分代码省略.........
示例10: createStatsLabel
void Director::createStatsLabel()
{
Texture2D *texture = NULL;
TextureCache *textureCache = TextureCache::getInstance();
if( _FPSLabel && _SPFLabel )
{
CC_SAFE_RELEASE_NULL(_FPSLabel);
CC_SAFE_RELEASE_NULL(_SPFLabel);
CC_SAFE_RELEASE_NULL(_drawsLabel);
textureCache->removeTextureForKey("cc_fps_images");
FileUtils::getInstance()->purgeCachedEntries();
}
Texture2DPixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat();
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA4444);
unsigned char *data = NULL;
unsigned int data_len = 0;
getFPSImageData(&data, &data_len);
Image* image = new Image();
bool isOK = image->initWithImageData(data, data_len);
if (!isOK) {
CCLOGERROR("%s", "Fails: init fps_images");
return;
}
texture = textureCache->addUIImage(image, "cc_fps_images");
CC_SAFE_RELEASE(image);
/*
We want to use an image which is stored in the file named ccFPSImage.c
for any design resolutions and all resource resolutions.
To achieve this,
Firstly, we need to ignore 'contentScaleFactor' in 'AtlasNode' and 'LabelAtlas'.
So I added a new method called 'setIgnoreContentScaleFactor' for 'AtlasNode',
this is not exposed to game developers, it's only used for displaying FPS now.
Secondly, the size of this image is 480*320, to display the FPS label with correct size,
a factor of design resolution ratio of 480x320 is also needed.
*/
float factor = EGLView::getInstance()->getDesignResolutionSize().height / 320.0f;
_FPSLabel = new LabelAtlas();
_FPSLabel->setIgnoreContentScaleFactor(true);
_FPSLabel->initWithString("00.0", texture, 12, 32 , '.');
_FPSLabel->setScale(factor);
_SPFLabel = new LabelAtlas();
_SPFLabel->setIgnoreContentScaleFactor(true);
_SPFLabel->initWithString("0.000", texture, 12, 32, '.');
_SPFLabel->setScale(factor);
_drawsLabel = new LabelAtlas();
_drawsLabel->setIgnoreContentScaleFactor(true);
_drawsLabel->initWithString("000", texture, 12, 32, '.');
_drawsLabel->setScale(factor);
Texture2D::setDefaultAlphaPixelFormat(currentFormat);
_drawsLabel->setPosition(Point(0, 34*factor) + CC_DIRECTOR_STATS_POSITION);
_SPFLabel->setPosition(Point(0, 17*factor) + CC_DIRECTOR_STATS_POSITION);
_FPSLabel->setPosition(CC_DIRECTOR_STATS_POSITION);
}
示例11: createSpriteWithTag
Sprite* SubTest::createSpriteWithTag(int tag)
{
TextureCache *cache = Director::getInstance()->getTextureCache();
Sprite* sprite = NULL;
switch (subtestNumber)
{
///
case 1:
case 2:
{
sprite = Sprite::create("Images/grossinis_sister1.png");
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 3:
case 4:
{
Texture2D *texture = cache->addImage("Images/grossinis_sister1.png");
sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 5:
{
int idx = (CCRANDOM_0_1() * 1400 / 100) + 1;
char str[32] = {0};
sprintf(str, "Images/grossini_dance_%02d.png", idx);
sprite = Sprite::create(str);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 6:
case 7:
case 8:
{
int y,x;
int r = (CCRANDOM_0_1() * 1400 / 100);
y = r / 5;
x = r % 5;
x *= 85;
y *= 121;
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 9:
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
char str[40] = {0};
sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y);
sprite = Sprite::create(str);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 10:
case 11:
case 12:
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
x *= 32;
y *= 32;
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 13:
{
int test = (CCRANDOM_0_1() * 3);
if(test==0) {
// Switch case 1
sprite = Sprite::create("Images/grossinis_sister1.png");
_parentNode->addChild(sprite, 0, tag+100);
}
else if(test==1)
{
// Switch case 6
int y,x;
int r = (CCRANDOM_0_1() * 1400 / 100);
//.........这里部分代码省略.........
示例12: perfTimer
QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
PerformanceTimer perfTimer("glowEffect");
TextureCache* textureCache = DependencyManager::get<TextureCache>();
QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject();
primaryFBO->release();
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
QOpenGLFramebufferObject* destFBO = toTexture ?
textureCache->getSecondaryFramebufferObject() : NULL;
if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) {
// copy the primary to the screen
if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) {
QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO);
} else {
maybeBind(destFBO);
if (!destFBO) {
glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(),
Application::getInstance()->getGLWidget()->getDeviceHeight());
}
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor3f(1.0f, 1.0f, 1.0f);
renderFullscreenQuad();
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
maybeRelease(destFBO);
}
} else {
// diffuse into the secondary/tertiary (alternating between frames)
QOpenGLFramebufferObject* oldDiffusedFBO =
textureCache->getSecondaryFramebufferObject();
QOpenGLFramebufferObject* newDiffusedFBO =
textureCache->getTertiaryFramebufferObject();
if (_isOddFrame) {
qSwap(oldDiffusedFBO, newDiffusedFBO);
}
newDiffusedFBO->bind();
if (_isFirstFrame) {
glClear(GL_COLOR_BUFFER_BIT);
} else {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, oldDiffusedFBO->texture());
_diffuseProgram->bind();
QSize size = primaryFBO->size();
_diffuseProgram->setUniformValue(_diffusionScaleLocation, 1.0f / size.width(), 1.0f / size.height());
renderFullscreenQuad();
_diffuseProgram->release();
}
newDiffusedFBO->release();
// add diffused texture to the primary
glBindTexture(GL_TEXTURE_2D, newDiffusedFBO->texture());
if (toTexture) {
destFBO = oldDiffusedFBO;
}
maybeBind(destFBO);
if (!destFBO) {
glViewport(0, 0,
Application::getInstance()->getGLWidget()->getDeviceWidth(),
Application::getInstance()->getGLWidget()->getDeviceHeight());
}
_addSeparateProgram->bind();
renderFullscreenQuad();
_addSeparateProgram->release();
maybeRelease(destFBO);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
}
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glBindTexture(GL_TEXTURE_2D, 0);
//.........这里部分代码省略.........
示例13: build_from_mqo
//
// MQO
// 面倒なので四角ポリゴンはないものと仮定
//
void build_from_mqo(
mqo_reader::document_type& doc, float scale, DWORD color,
TextureCache& tc )
{
clear();
// マテリアル
for( mqo_reader::materials_type::const_iterator i =
doc.materials.begin() ;
i != doc.materials.end() ;
++i ) {
SubModel m;
m.vb = NULL;
m.ib = NULL;
m.texture = NULL;
if( (*i).texture != "" ) {
m.texture = tc.get_texture( (*i).texture );
}
submodels_.push_back( m );
}
{
// default material
SubModel m;
m.vb = NULL;
m.ib = NULL;
submodels_.push_back( m );
}
// 頂点, 面
for( mqo_reader::objdic_type::const_iterator i =
doc.objects.begin() ;
i != doc.objects.end() ;
++i ) {
const mqo_reader::object_type& obj = (*i).second;
// dictionary:
// ( source vertex index, uv ) => destination vertex index
struct VertexKey {
int index;
D3DXVECTOR2 uv;
VertexKey(){}
VertexKey( int aindex, const D3DXVECTOR2& auv )
: index( aindex ), uv( auv ) { }
bool operator<( const VertexKey& a ) const
{
if( index < a.index ) { return true; }
if( a.index < index ) { return false; }
if( uv.x < a.uv.x ) { return true; }
if( a.uv.x < uv.x ) { return false; }
return uv.y < a.uv.y;
}
};
std::vector< std::map< VertexKey, int > > used_vertices;
used_vertices.resize( submodels_.size() );
// マテリアルごとに使用頂点を分類
for( mqo_reader::faces_type::const_iterator j =
obj.faces.begin() ;
j != obj.faces.end() ;
++j ) {
const mqo_reader::face_type& face = *j;
int material_index = face.material_index;
if( material_index == -1 ) {
material_index =
int( submodels_.size() - 1 );
}
int i0 = face.vertex_indices[0];
int i1 = face.vertex_indices[1];
int i2 = face.vertex_indices[2];
D3DXVECTOR2 uv0( face.uv[0].u, face.uv[0].v );
D3DXVECTOR2 uv1( face.uv[1].u, face.uv[1].v );
D3DXVECTOR2 uv2( face.uv[2].u, face.uv[2].v );
std::map< VertexKey, int >& c =
used_vertices[material_index];
c[ VertexKey( i0, uv0 ) ] = -1 ;
c[ VertexKey( i1, uv1 ) ] = -1 ;
c[ VertexKey( i2, uv2 ) ] = -1 ;
}
// マテリアルごとに使われている頂点を追加
size_t n = submodels_.size();
for( size_t i = 0 ; i < n ; i++ ) {
SubModel& m = submodels_[i];
std::map< VertexKey, int >& c = used_vertices[i];
int no = int( m.vertex_source.size() );
for( std::map< VertexKey, int >::iterator j = c.begin();
j != c.end() ;
++j ) {
const mqo_reader::vertex_type& src =
obj.vertices[(*j).first.index];
//.........这里部分代码省略.........
示例14: initWithSubTest
void SubTest::initWithSubTest(int nSubTest, Node* p)
{
subtestNumber = nSubTest;
parent = p;
batchNode = NULL;
/*
* Tests:
* 1: 1 (32-bit) PNG sprite of 52 x 139
* 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
* 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
* 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139
* 5: 14 (32-bit) PNG sprites of 85 x 121 each
* 6: 14 (32-bit) PNG Batch Node of 85 x 121 each
* 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
* 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each
* 9: 64 (32-bit) sprites of 32 x 32 each
*10: 64 (32-bit) PNG Batch Node of 32 x 32 each
*11: 64 (16-bit) PNG Batch Node of 32 x 32 each
*12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
*/
// purge textures
TextureCache *mgr = TextureCache::sharedTextureCache();
// [mgr removeAllTextures];
mgr->removeTexture(mgr->addImage("Images/grossinis_sister1.png"));
mgr->removeTexture(mgr->addImage("Images/grossini_dance_atlas.png"));
mgr->removeTexture(mgr->addImage("Images/spritesheet1.png"));
switch ( subtestNumber)
{
case 1:
case 4:
case 7:
break;
///
case 2:
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA8888);
batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
p->addChild(batchNode, 0);
break;
case 3:
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA4444);
batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
p->addChild(batchNode, 0);
break;
///
case 5:
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA8888);
batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
p->addChild(batchNode, 0);
break;
case 6:
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA4444);
batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
p->addChild(batchNode, 0);
break;
///
case 8:
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA8888);
batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
p->addChild(batchNode, 0);
break;
case 9:
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA4444);
batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
p->addChild(batchNode, 0);
break;
default:
break;
}
if (batchNode)
{
batchNode->retain();
}
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_Default);
}