So I am trying to work with custom textures for terra detail_map and diffuse_map, I create a texture like so:
Code: Select all
Ogre::TextureGpuManager* textureMgr = graphics.getRoot()->getRenderSystem()->getTextureGpuManager();
mTexture = textureMgr->createOrRetrieveTexture(
mName,
Ogre::GpuPageOutStrategy::AlwaysKeepSystemRamCopy,
Ogre::TextureFlags::AutomaticBatching,
Ogre::TextureTypes::Type2D, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mTexture->setNumMipmaps(1);
mTexture->setResolution(width, height);
mTexture->setPixelFormat(format);
size_t sizeBytes = Ogre::PixelFormatGpuUtils::calculateSizeBytes(
width, height, 1u, 1u, format, 1u, 4u);
Ogre::uint8* data = reinterpret_cast<Ogre::uint8*>(
OGRE_MALLOC_SIMD(sizeBytes, Ogre::MEMCATEGORY_GENERAL));
mImage.loadDynamicImage(data, width, height, 1u,
Ogre::TextureTypes::Type2D, format,
true, 1u);
//mSize = mImage.getBytesPerImage(0);
bool canUseSynchronousUpload = mTexture->getNextResidencyStatus() == Ogre::GpuResidency::Resident && mTexture->isDataReady();
if (!canUseSynchronousUpload) {
mTexture->waitForData();
}
mTexture->scheduleTransitionTo(Ogre::GpuResidency::Resident, &mImage, false);
with format = Ogre::PixelFormatGpu::PFG_RGBA8_UNORM_SRGB
now, in my fill function, this seems to work:
Code: Select all
void ManualTexture::fill( Ogre::uint8 r, Ogre::uint8 g, Ogre::uint8 b, Ogre::uint8 a) {
std::size_t width = mImage.getWidth(),
height = mImage.getHeight();
Ogre::uint32* data = static_cast<Ogre::uint32*>(mImage.getData(0).data);
for (std::size_t y = 0; y < height; y++) {
for (std::size_t x = 0; x < width; x++) {
std::size_t p = (width * y) + x;
((char*)&data[p])[0] = r;
((char*)&data[p])[1] = g;
((char*)&data[p])[2] = b;
((char*)&data[p])[3] = a;
}
}
}
however, this does not:
Code: Select all
std::size_t width = mImage.getWidth(),
height = mImage.getHeight();
auto texBox = mImage.getData(0);
for (std::size_t y = 0; y < height; y++) {
for (std::size_t x = 0; x < width; x++) {
Ogre::ColourValue color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
texBox.setColourAt(color, x, y, 0, Ogre::PixelFormatGpu::PFG_RGBA8_UNORM_SRGB);
}
}
and even more confusing, neither does this:
Code: Select all
for (std::size_t y = 0; y < height; y++) {
for (std::size_t x = 0; x < width; x++) {
std::size_t p = (width * y) + x;
Ogre::uint32* data = static_cast<Ogre::uint32*>(mImage.getData(0).data);
((char*)&data[p])[0] = r;
((char*)&data[p])[1] = g;
((char*)&data[p])[2] = b;
((char*)&data[p])[3] = a;
}
}
All I changed was the position of the getData line, and it stopped working?
Please help, my friends!