timscaffidi/ofxVolumetrics

error when updating 3dTexture

Closed this issue · 6 comments

Hi Tim,

I'm experiencing a really strange error when I try to update a volume.
It toke me really long to track down what was it and now i think I'm very close..
I guess it might be related to the power of two issue..

The strange thing is that the error only appears if I use the ofDrawBitmapString() before updating the volume. Also this error does not appear in your volume, probably because it is a pow2 texture..

I have set a branch starting from your code with few modifications to demonstrate the error.
https://github.com/wasawi/ofxVolumetrics/tree/error_demo

To see the example run the app and hit 'a' to update te volume. Everything will work fine.
But if you hit 'h' to show the bitmapstring and then 'a' you will see the volume broken.

Please let me know if you have any ideas on what is going on.
Thank you so much!

Just to let you know..
If I update a pow2 3d texture the error does not happen. So this error happens only if the volume is not power of 2.

I can reproduce this error. It looks like a pixel alignment issue with the uploaded data, but the fact that drawing a bitmap string triggers it is very odd. It is even more strange that I've never seen this error before, because I have done several projects using NPOT volumes and drawing bitmap strings for a UI. I will look into it.

looks like the issue is that something else is setting the glPixelStore
https://www.opengl.org/sdk/docs/man3/xhtml/glPixelStore.xml

Why this only affects the volume for NPOT textures is a mystery.

I have a fix, I will push it up later tonight. In the mean time you can add the following line:

ofSetPixelStorei(w, 1, ofGetNumChannelsFromGLFormat(glFormat));

to ofxTexture3d::loadData, just before the glEnable call, around line 94

Hey thank you so much for looking at this!
How did you find out about the glPixelStore?
some OpenGL errors are very hard to debug for me since there are no errors thrown... I feel clueless when i try to fix them.. what was your process to find that?

I'm writing some classes to manage voxels.. something like ofPixels and ofImage but for voxels.. maybe soon i can share it. Now it is still a bit messy.. It would be nice if you could have a look at it when it is ready. I will look forward for your comments!

Thank you again for the fix.. I would probably spend ages before finding it!

Hi, here is the addon.. is not completed but mostly there..
https://github.com/wasawi/ofxVolume

Please let me know your thoughts if you have time to check it out.
I would really appreciate comments even if they are to point out things i haven't done well.

Cheers!

Hey when I get some time I'll check out your code, sounds useful. I finally got around to pushing that change to add the set the pixel store. Closing this issue.