odd behavior in texbox

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

odd behavior in texbox

Post by Nickak2003 »

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!

Last edited by Nickak2003 on Fri May 06, 2022 10:16 pm, edited 1 time in total.
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: odd behavior in texbox

Post by Nickak2003 »

I figured it out, all those functions actually work, the problem was with my update function, the texture residency was wrong and it was throwing
This new function causes it to work

Code: Select all

void ManualTexture::update() {

try {

	bool canUseSynchronousUpload = mTexture->getNextResidencyStatus() == Ogre::GpuResidency::Resident && mTexture->isDataReady();

	if (!canUseSynchronousUpload) {
		mTexture->waitForData();
	}

	mImage.uploadTo(mTexture, 0, 0);
}
catch (...) {
	
}
}
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: odd behavior in texbox

Post by Nickak2003 »

aside from the erronious catch feature which lead to this bug, is this that the correct way to upload a texture once its generated?

Post Reply