/** Add the texture and use it for a single non-animated sprite. */ s32 STKModifiedSpriteBank::addTextureAsSprite(video::ITexture* texture) { assert( m_magic_number == 0xCAFEC001 ); if ( !texture ) return -1; addTexture(texture); u32 textureIndex = getTextureCount() - 1; u32 rectangleIndex = Rectangles.size(); Rectangles.push_back( core::rect<s32>(0,0, texture->getOriginalSize().Width, texture->getOriginalSize().Height) ); SGUISprite sprite; sprite.frameTime = 0; SGUISpriteFrame frame; frame.textureNumber = textureIndex; frame.rectNumber = rectangleIndex; sprite.Frames.push_back( frame ); Sprites.push_back( sprite ); return Sprites.size() - 1; } // addTextureAsSprite
void CC3MeshNode::addTexture( CC3Texture* aTexture ) { getMaterial()->addTexture( aTexture ); GLuint texCount = getTextureCount(); if (texCount > 0) alignTextureUnit( texCount - 1 ); super::addTexture( aTexture ); }
void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, const core::array<core::position2di>& pos, const core::rect<s32>* clip, const video::SColor& color, u32 starttime, u32 currenttime, bool loop, bool center) { const irr::u32 drawCount = core::min_<u32>(indices.size(), pos.size()); if (!getTextureCount()) return; core::array<SDrawBatch> drawBatches(getTextureCount()); for (u32 i=0; i < Textures.size(); ++i) { drawBatches.push_back(SDrawBatch()); drawBatches[i].positions.reallocate(drawCount); drawBatches[i].sourceRects.reallocate(drawCount); } for (u32 i = 0; i < drawCount; ++i) { const u32 index = indices[i]; if (index >= Sprites.size() || Sprites[index].Frames.empty() ) continue; // work out frame number u32 frame = 0; if (Sprites[index].frameTime) { u32 f = ((currenttime - starttime) / Sprites[index].frameTime); if (loop) frame = f % Sprites[index].Frames.size(); else frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; } const u32 texNum = Sprites[index].Frames[frame].textureNumber; SDrawBatch& currentBatch = drawBatches[texNum]; const u32 rn = Sprites[index].Frames[frame].rectNumber; if (rn >= Rectangles.size()) return; const core::rect<s32>& r = Rectangles[rn]; if (center) { core::position2di p = pos[i]; p -= r.getSize() / 2; currentBatch.positions.push_back(p); currentBatch.sourceRects.push_back(r); } else { currentBatch.positions.push_back(pos[i]); currentBatch.sourceRects.push_back(r); } } for(u32 i = 0;i < drawBatches.size();i++) { if(!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty()) Driver->draw2DImageBatch(getTexture(i), drawBatches[i].positions, drawBatches[i].sourceRects, clip, color, true); } }
bool ompfMeshChunk::write(ofstream& file, const ompfSettings& settings) { if (!ompfBaseChunk::write(file, settings)) { return false; } con_assert((4 * _indexCount) == _indexDataSize, "inconsistend index data"); con_assert((calcVertexSize() * _vertexCount) == _vertexDataSize, "inconsistend vertex data"); con_debug_endl("---------------------------------------------------"); con_debug_endl("write ompfMeshChunk " << this->getName()); if (!iaSerializable::writeUInt32(file, _materialChunkID)) { return false; } con_debug_endl("materialChunkID " << _materialChunkID); if (!iaSerializable::write(file, _ambient)) { return false; } con_debug_endl("ambient " << _ambient); if (!iaSerializable::write(file, _diffuse)) { return false; } con_debug_endl("diffuse " << _diffuse); if (!iaSerializable::write(file, _specular)) { return false; } con_debug_endl("specular " << _specular); if (!iaSerializable::write(file, _emissive)) { return false; } con_debug_endl("emissive " << _emissive); if (!iaSerializable::writeFloat32(file, _shininess)) { return false; } con_debug_endl("shininess " << _shininess); if (!iaSerializable::writeUInt8(file, _normalsPerVertex)) { return false; } con_debug_endl("normalsPerVertex " << _normalsPerVertex); if (!iaSerializable::writeUInt8(file, _colorsPerVertex)) { return false; } con_debug_endl("colorsPerVertex " << _colorsPerVertex); if (!iaSerializable::writeUInt8(file, _texCoordPerVertex)) { return false; } con_debug_endl("texCoordPerVertex " << _texCoordPerVertex); uint8 meshType = static_cast<uint8>(_meshType); iaSerializable::writeUInt8(file, meshType); con_debug_endl("meshType " << static_cast<uint8>(_meshType)); iaSerializable::write(file, _boundingSpherePos); iaSerializable::writeFloat32(file, _boundingSphereRadius); con_debug_endl("bounding sphere " << _boundingSpherePos << " radius " << _boundingSphereRadius); iaSerializable::writeUInt8(file, static_cast<uint8>(getTextureCount())); con_debug_endl("textureCount " << getTextureCount()); int i = 0; auto iterTex = _textures.begin(); while (iterTex != _textures.end()) { con_assert((*iterTex).first == i, "inconsistent texture units"); iaSerializable::writeUTF8(file, (*iterTex).second); con_debug_endl("texture " << i << " " << (*iterTex).second); iterTex++; i++; } iaSerializable::writeUInt32(file, _vertexCount); iaSerializable::write(file, static_cast<char*>(_vertexData), _vertexDataSize); con_debug_endl("vertexCount " << _vertexCount << " vertexDataSize " << _vertexDataSize); iaSerializable::writeUInt32(file, _indexCount); iaSerializable::write(file, static_cast<char*>(_indexData), _indexDataSize); con_debug_endl("indexCount " << _indexCount << " indexDataSize " << _indexDataSize); return true; }
void CC3MeshNode::alignTextureUnits() { GLuint texCount = getTextureCount(); for (GLuint texUnit = 0; texUnit < texCount; texUnit++) alignTextureUnit( texUnit ); }
bool CC3MeshNode::isDrawingPointSprites() { return (getDrawingMode() == GL_POINTS) && (getTextureCount() > 0); }