#include <texture.h>
Inheritance diagram for TiledTexture:


Public Member Functions | |
| virtual void | bind () |
| virtual const TextureTile | getTile (int lod, int u, int v) |
| virtual int | getUTileCount (int lod) const |
| virtual int | getVTileCount (int lod) const |
| virtual void | setBorderColor (Color) |
| TiledTexture (Image &img, int _uSplit, int _vSplit, MipMapMode) | |
| ~TiledTexture () | |
Private Attributes | |
| unsigned int * | glNames |
| int | uSplit |
| int | vSplit |
|
||||||||||||||||||||
|
Definition at line 500 of file texture.cpp. References CalcMipLevelCount(), components, getCompressedBlockSize(), Image::getFormat(), GetGLTexAddressMode(), Image::getHeight(), getInternalFormat(), Image::getMipLevel(), Image::getPixels(), Image::getWidth(), glNames, LoadMiplessTexture(), LoadMipmapSet(), max, min, uSplit, and vSplit. 00502 : 00503 Texture(img.getWidth(), img.getHeight()), 00504 uSplit(_uSplit), 00505 vSplit(_vSplit), 00506 glNames(NULL) 00507 { 00508 glNames = new uint[uSplit * vSplit]; 00509 { 00510 for (int i = 0; i < uSplit * vSplit; i++) 00511 glNames[i] = 0; 00512 } 00513 00514 alpha = img.hasAlpha(); 00515 00516 bool mipmap = mipMapMode == DefaultMipMaps; 00517 bool precomputedMipMaps = false; 00518 00519 // Require a complete set of mipmaps 00520 int mipLevelCount = img.getMipLevelCount(); 00521 int completeMipCount = CalcMipLevelCount(img.getWidth(), img.getHeight()); 00522 // Allow a bit of slack here--it turns out that some tools don't want to 00523 // calculate the 1x1 mip level. Rather than turn off mipmaps, we'll just 00524 // point the 1x1 mip to the 2x1. 00525 if (mipmap && mipLevelCount >= completeMipCount - 1) 00526 precomputedMipMaps = true; 00527 00528 // We can't automatically generate mipmaps for compressed textures. 00529 // If a precomputed mipmap set isn't provided, turn of mipmapping entirely. 00530 if (!precomputedMipMaps && img.isCompressed()) 00531 mipmap = false; 00532 00533 GLenum texAddress = GetGLTexAddressMode(EdgeClamp); 00534 int internalFormat = getInternalFormat(img.getFormat()); 00535 int components = img.getComponents(); 00536 00537 // Create a temporary image which we'll use for the tile texels 00538 int tileWidth = img.getWidth() / uSplit; 00539 int tileHeight = img.getHeight() / vSplit; 00540 int tileMipLevelCount = CalcMipLevelCount(tileWidth, tileHeight); 00541 Image* tile = new Image(img.getFormat(), 00542 tileWidth, tileHeight, 00543 tileMipLevelCount); 00544 if (tile == NULL) 00545 return; 00546 00547 for (int v = 0; v < vSplit; v++) 00548 { 00549 for (int u = 0; u < uSplit; u++) 00550 { 00551 // Create the texture and set up sampling and addressing 00552 glGenTextures(1, (GLuint*)&glNames[v * uSplit + u]); 00553 glBindTexture(GL_TEXTURE_2D, glNames[v * uSplit + u]); 00554 00555 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texAddress); 00556 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texAddress); 00557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 00559 mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); 00560 00561 // Copy texels from the subtexture area to the pixel buffer. This 00562 // is straightforward for normal textures, but an immense headache 00563 // for compressed textures with prebuilt mipmaps. 00564 if (precomputedMipMaps) 00565 { 00566 if (img.isCompressed()) 00567 { 00568 for (int mip = 0; mip < tileMipLevelCount; mip++) 00569 { 00570 int blockSize = getCompressedBlockSize(img.getFormat()); 00571 unsigned char* imgMip = 00572 img.getMipLevel(min(mip, mipLevelCount)); 00573 uint mipWidth = max((uint) img.getWidth() >> mip, 1u); 00574 unsigned char* tileMip = tile->getMipLevel(mip); 00575 uint tileMipWidth = max((uint) tile->getWidth() >> mip, 1u); 00576 uint tileMipHeight = max((uint) tile->getHeight() >> mip, 1u); 00577 int uBlocks = max(tileMipWidth / 4, 1u); 00578 int vBlocks = max(tileMipHeight / 4, 1u); 00579 int destBytesPerRow = uBlocks * blockSize; 00580 int srcBytesPerRow = max(mipWidth / 4, 1u) * blockSize; 00581 int srcU = u * tileMipWidth / 4; 00582 int srcV = v * tileMipHeight / 4; 00583 int tileOffset = srcV * srcBytesPerRow + 00584 srcU * blockSize; 00585 00586 for (int y = 0; y < vBlocks; y++) 00587 { 00588 memcpy(tileMip + y * destBytesPerRow, 00589 imgMip + tileOffset + y * srcBytesPerRow, 00590 destBytesPerRow); 00591 } 00592 } 00593 } 00594 else 00595 { 00596 // TODO: Handle uncompressed textures with prebuilt mipmaps 00597 } 00598 00599 LoadMipmapSet(*tile, GL_TEXTURE_2D); 00600 } 00601 else 00602 { 00603 if (img.isCompressed()) 00604 { 00605 int blockSize = getCompressedBlockSize(img.getFormat()); 00606 int uBlocks = max(tileWidth / 4, 1); 00607 int vBlocks = max(tileHeight / 4, 1); 00608 int destBytesPerRow = uBlocks * blockSize; 00609 int srcBytesPerRow = max(img.getWidth() / 4, 1) * blockSize; 00610 int srcU = u * tileWidth / 4; 00611 int srcV = v * tileHeight / 4; 00612 int tileOffset = srcV * srcBytesPerRow + 00613 srcU * blockSize; 00614 00615 for (int y = 0; y < vBlocks; y++) 00616 { 00617 memcpy(tile->getPixels() + y * destBytesPerRow, 00618 img.getPixels() + tileOffset + y * srcBytesPerRow, 00619 destBytesPerRow); 00620 } 00621 } 00622 else 00623 { 00624 unsigned char* tilePixels = img.getPixels() + 00625 (v * tileHeight * img.getWidth() + u * tileWidth) * components; 00626 for (int y = 0; y < tileHeight; y++) 00627 { 00628 memcpy(tile->getPixels() + y * tileWidth * components, 00629 tilePixels + y * img.getWidth() * components, 00630 tileWidth * components); 00631 } 00632 } 00633 00634 if (mipmap) 00635 { 00636 gluBuild2DMipmaps(GL_TEXTURE_2D, 00637 internalFormat, 00638 tileWidth, tileHeight, 00639 (GLenum) tile->getFormat(), 00640 GL_UNSIGNED_BYTE, 00641 tile->getPixels()); 00642 } 00643 else 00644 { 00645 LoadMiplessTexture(*tile, GL_TEXTURE_2D); 00646 } 00647 } 00648 } 00649 } 00650 00651 delete tile; 00652 }
|
|
|
Definition at line 655 of file texture.cpp. References glNames, uSplit, and vSplit. 00656 {
00657 if (glNames != NULL)
00658 {
00659 for (int i = 0; i < uSplit * vSplit; i++)
00660 {
00661 if (glNames[i] != 0)
00662 glDeleteTextures(1, (const GLuint*) &glNames[i]);
00663 }
00664 delete[] glNames;
00665 }
00666 }
|
|
|
Implements Texture. Definition at line 669 of file texture.cpp. 00670 {
00671 }
|
|
||||||||||||||||
|
Implements Texture. Definition at line 699 of file texture.cpp. References glNames, uSplit, and vSplit. 00700 {
00701 if (lod != 0 || u >= uSplit || u < 0 || v >= vSplit || v < 0)
00702 return TextureTile(0);
00703 else
00704 {
00705 return TextureTile(glNames[v * uSplit + u]);
00706 }
00707 }
|
|
|
Reimplemented from Texture. Definition at line 687 of file texture.cpp. References uSplit. 00688 {
00689 return uSplit;
00690 }
|
|
|
Reimplemented from Texture. Definition at line 693 of file texture.cpp. References vSplit. 00694 {
00695 return vSplit;
00696 }
|
|
|
Reimplemented from Texture. Definition at line 674 of file texture.cpp. References glNames, SetBorderColor(), uSplit, and vSplit. 00675 {
00676 for (int i = 0; i < vSplit; i++)
00677 {
00678 for (int j = 0; j < uSplit; j++)
00679 {
00680 glBindTexture(GL_TEXTURE_2D, glNames[i * uSplit + j]);
00681 SetBorderColor(borderColor, GL_TEXTURE_2D);
00682 }
00683 }
00684 }
|
|
|
Definition at line 132 of file texture.h. Referenced by getTile(), setBorderColor(), TiledTexture(), and ~TiledTexture(). |
|
|
Definition at line 130 of file texture.h. Referenced by getTile(), getUTileCount(), setBorderColor(), TiledTexture(), and ~TiledTexture(). |
|
|
Definition at line 131 of file texture.h. Referenced by getTile(), getVTileCount(), setBorderColor(), TiledTexture(), and ~TiledTexture(). |
1.4.1