Re: [osg-users] Texture Buffer Objects status?
Juan Hernando wrote: I'll be very busy until next Friday so I can't answer to you properly. A quick answer is that I just replicated what I saw inside the OSG code for other textures. If you're sure that the binding is not needed, removte it. I'll try to come back to this issue later and check whether it works for me or not. Cheers, Juan No worries. Things work fine without the additional binding so far. I'm going to leave this commented out. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=37985#37985 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Fred, The call to glTextureBufferEXT, during the rendering, is not needed. It is only needed when you prepare the Texture Buffer, but not during the display. Does it make sense to you if I comment out the following line of code below (see // COMMENTED OUT, below): I'll be very busy until next Friday so I can't answer to you properly. A quick answer is that I just replicated what I saw inside the OSG code for other textures. If you're sure that the binding is not needed, removte it. I'll try to come back to this issue later and check whether it works for me or not. Cheers, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Juan, I finally managed to make it work. Can't understand exactly what was wrong, I got mangled into several issues at the same time (signed/unsigned sampler1D vs buffer, ATI (bogus) compiler vs nvidia, texture originally too large, incorrect pixel formats...). I just ended up checking every line of code and things actually finally run fine. Your code is fine, thanks for submitting it here. I don't know if this is the best way to implement this, especially w.r.t the buffer object base classes in OSG (osg/BufferObject). Questions like that would be raised on submission for possible inclusion in the OSG code, I guess. Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35913#35913 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Fred, Good to know that you could make it. For sure, I don't think my implementation is the best posible. I just wanted to get something working quickly. My idea is that someone else can take it as a starting point for a future OSG implementation. Cheers, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi, My simple fragment shader with textureSize() seem to work fine when dealing with a usampler1D uniform (the problem I had at one point was that I was giving a texture that was too big for the driver, hence the size ended up being actually 1, and my test was always failing). tex-setInternalFormat(GL_RGBA8); image-allocateImage((128*128), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1); In my fragment shader: uniform usampler1D tex; My (textureSize(tex, 0) == 16384) test actually does work. When I change my code so that your TextureBuffer is used, somehow, things don't work. - I change the uniform type from UNSIGNED_INT_SAMPLER_1D to UNSIGNED_INT_SAMPLER_BUFFER. - usampler1D becomes usamplerBuffer, textureSize() becomes textureSizeBuffer(). - and of course I create a TextureBuffer and not a Texture1D object. In my GL tracer, I don't see any OpenGL error. I am trying hard to see what is wrong, but so far, I have no idea. And yet, things don't work. Cheers, Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35866#35866 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Fred, If you can provide a minimal code example I can test it on my machine and see what's the problem. Otherwise, for me it's impossible to know what's going on and I can only guess. By the way, did you try using GL_LUMINANCE instead of GL_RGBA? Cheers, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Juan, Thanks for your reply. I'm still having problems trying to make use of texelFetchBuffer with your code. Why texture pixel format are you using? I'm using an integer texture format. Not sure if OSG's allocateImage method behaves ok in this case. I am creating the texture the following way: Code: bbp::RTNeuron::TextureBuffer *tb = new bbp::RTNeuron::TextureBuffer(); tb-setInternalFormat(GL_RGBA8UI); // 4 bytes per pixel, R-G-B-A format as per EXT_texture_integer formats specification osg::Image *image = new osg::Image(); image-allocateImage(128*128, 1, 1, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 1); // note: width=(128*128), height=1 tb-setImage(0, image); In my fragment shader, right now, here is what I'm doing for a quick test: Code: #version 150 compatibility #extension GL_EXT_gpu_shader4 : enable uniform samplerBuffer tex; void main(void) { if (textureSizeBuffer(tex) == (128*128)) // size in pixels gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // red (as I am expecting) else gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green } The result is always green here, not red as I am expecting. Is there anything I am doing wrong with your code? Regards Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35795#35795 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
fred_em wrote: Code: [...] tb-setInternalFormat(GL_RGBA8UI); // 4 bytes per pixel, R-G-B-A format as per EXT_texture_integer formats specification osg::Image *image = new osg::Image(); image-allocateImage(128*128, 1, 1, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 1); // note: width=(128*128), height=1 tb-setImage(0, image); I am getting the same bogus result with the following standard pixel format (eg. not using EXT_texture_integer): Code: [...] tb-setInternalFormat(GL_RGBA8); // 4 bytes per pixel, regular RGBA normalized pixel format osg::Image *image = new osg::Image(); image-allocateImage(128*128, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1); tb-setImage(0, image); -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35798#35798 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Fred What texture pixel format are you using? I'm using an integer texture format. Not sure if OSG's allocateImage method behaves ok in this case. I've only used setup code of this style: image-setImage(size, 1, 1, GL_LUMINANCE32F_ARB, GL_LUMINANCE, GL_FLOAT, data, osg::Image::NO_DELETE); I don't know whether for other formats it may fail. I am creating the texture the following way: Code: bbp::RTNeuron::TextureBuffer *tb = new bbp::RTNeuron::TextureBuffer(); tb-setInternalFormat(GL_RGBA8UI); // 4 bytes per pixel, R-G-B-A format as per EXT_texture_integer formats specification osg::Image *image = new osg::Image(); image-allocateImage(128*128, 1, 1, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 1); // note: width=(128*128), height=1 tb-setImage(0, image); If you use GL_RGBA_INTEGER then you must use isamplerBuffer or uisamplerBuffer otherwise the results are undefined. For a normalized value I don't know what were you expecting but it can't be the same as with floating point or true integer formats. The main differences between your code and mine are that I'm setting the internal texture format explicitly and I'm using a plain array of data instead RGB/RGBA formats. Code: #version 150 compatibility #extension GL_EXT_gpu_shader4 : enable uniform samplerBuffer tex; void main(void) { if (textureSizeBuffer(tex) == (128*128)) // size in pixels gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // red (as I am expecting) else gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green } The result is always green here, not red as I am expecting. I haven't used textureSizeBuffer before but from the docs I've read your code should pretty much work. Is this wrong also with a normalized texture format or a floating point format? Cheers, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi, When I compile your code I get the following errors: Code: error C2065: 'GL_TEXTURE_BUFFER_EXT' : undeclared identifier error C2039: 'Extensions' : is not a member of 'osg::BufferObject' error C2039: 'getExtensions' : is not a member of 'osg::BufferObject' [...] I don't see any osg::BufferObject::Extensions class in OSG's source code. Do you? Didn't you mean osg::Texture::Extensions instead? Regarding GL_TEXTURE_BUFFER_EXT, I'm usually working with and plan to include GLEW, so I should be fine. Regards Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35728#35728 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi, OK, I temporarily replaced Extensions with GLEW, things moved forward, but I'm stuck with the following compilation error now: Code: } else if (_image.valid() _image-data()) { /* Temporary copy */ osg::ref_ptrosg::Image image = _image; /* Creating the texture object */ _textureObjectBuffer[contextID] = to = generateTextureObject(contextID, GL_TEXTURE_BUFFER_EXT); // compilation error here: error C2661: 'osg::Texture::generateTextureObject' : no overloaded function takes 2 arguments Cheers, Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35730#35730 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi, Sorry for not answering before but I've been away from the computer. Regarding osg::BufferObject, in my OSG version (2.8.3) there is an Extensions class declared inside osg::BufferObject. Of course you can replace it with GLEW, but probably the other compile error is also related to the use of a different version. Regards, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Juan, I managed to make some progress. - I replaced osg::BufferObject::Extensions with GLEW - I changed the other offending expression: generateTextureObject(contextID, GL_TEXTURE_BUFFER_EXT); to generateTextureObject(this, contextID, GL_TEXTURE_BUFFER_EXT); Things compile fine. I have never used TBOs before. How do you use your new class? Is the following correct? Code: // Creation osg::TextureBuffer *tb = new osg::TextureBuffer(); // This will create a buffer of 300 * 4 bytes = 1200 bytes osg::Image *image = new osg::Image(); image-allocateImage(300 /*width*/, 1 /*height is ALWAYS 1, right?*/, 1, GL_RGBA, GL_FLOAT, 1); // GL_RGBA + GL_FLOAT = 4 floating point components for my color // here, feed buffer with data tb-setImage(image); Fragment shader: Code: #version 150 compatibility #extension GL_EXT_gpu_shader4 : enable uniform sampler1D tex; // shall I use sampler1D here, or sampler2D? void main(void) { vec4 color = texelFetch(tex, 0); // I get a compile error here, texelFetch is not a recognized function name (?!). I use a Fermi card with the latest drivers. Confused with the different function names I found on the web (texelFetch, texelFetch1D/2D, texelFetchBuffer which, I understand, are deprecated). [...] } Cheers, Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35742#35742 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
I figured out why texelFetch wasn't being compiled successfully. 1) I forgot the last argument 2) I last tried on AMD/ATI hardware, and the GLSL compiler on this platform doesn't seem to actually recognize 'texelFetch'... Now moving on with my tests. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35746#35746 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Fred, I have never used TBOs before. How do you use your new class? Is the following correct? Code: // Creation osg::TextureBuffer *tb = new osg::TextureBuffer(); // This will create a buffer of 300 * 4 bytes = 1200 bytes osg::Image *image = new osg::Image(); image-allocateImage(300 /*width*/, 1 /*height is ALWAYS 1, right?*/, 1, GL_RGBA, GL_FLOAT, 1); // GL_RGBA + GL_FLOAT = 4 floating point components for my color // here, feed buffer with data tb-setImage(image); I don't see anything wrong here. Code: #version 150 compatibility #extension GL_EXT_gpu_shader4 : enable For me (NVIDIA 280GTX graphics card in linux), it works just to declare: #version 130 uniform sampler1D tex; // shall I use sampler1D here, or sampler2D? This has to be: uniform samplerBuffer tex; void main(void) { vec4 color = texelFetch(tex, 0); // I get a compile error here, texelFetch is not a recognized function name (?!). I use a Fermi card with the latest drivers. Confused with the different function names I found on the web (texelFetch, texelFetch1D/2D, texelFetchBuffer which, I understand, are deprecated). [...] } I use texelFetchBuffer but if you solved it I guess you use the same. Cheers, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Fred, As far as I know, they are not planeed to be part of OSG's API for 3.0. I wrote a class for dealing with these textures based on the code for other texture objects. The implementation can be improved to resuse Texture::TextureObject instead or redeclaring its own TextureBuffer::TextureBufferObject class. Nevertheless it worked for me. I can contribute the code for others to use and review for future inclusion. Regards, Juan On 17/01/11 14:55, Fred Smith wrote: Hi everyone, Are Texture Buffer Objects supported in OSG? From what I can see, I have to create and manage them myself. Cheers, Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35695#35695 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Juan Hernando wrote: Hi Fred, As far as I know, they are not planeed to be part of OSG's API for 3.0. I wrote a class for dealing with these textures based on the code for other texture objects. The implementation can be improved to resuse Texture::TextureObject instead or redeclaring its own TextureBuffer::TextureBufferObject class. Nevertheless it worked for me. I can contribute the code for others to use and review for future inclusion. Regards, Juan On 17/01/11 14:55, Fred Smith wrote: Hi everyone, Are Texture Buffer Objects supported in OSG? From what I can see, I have to create and manage them myself. Cheers, Fred Hi Juan, Sounds great. Your forum settings are not configured to accept private messages. I'm interested in your work, if you're willing to share some code with me drop me an email at fclXYZ.gvs at gmail.com (replace 'XYZ' with 'aux') Regards Fred -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35697#35697 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Texture Buffer Objects status?
Hi Juan, Sounds great. Your forum settings are not configured to accept private messages. I'm interested in your work, if you're willing to share some code with me drop me an email at fclXYZ.gvsat gmail.com (replace 'XYZ' with 'aux') I prefer sending them to everybody so they can be improved and maybe include in trunk in the future. Regards, Juan /* * -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) Juan Hernando Vieites 2011 * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include iostream #define GL_GLEXT_PROTOTYPES #include GL/glu.h #include TextureBuffer.h namespace bbp { namespace RTNeuron { //static void checkGLErrors(const std::string message) //{ //GLenum error = glGetError(); //if (error != GL_NO_ERROR) //std::cout OpenGL error detected: gluErrorString(error) // , message std::endl; //} /* Helper classes */ void TextureBuffer::TextureBufferObject::bindBuffer(unsigned int contextID) { osg::BufferObject::Extensions* extensions = osg::BufferObject::getExtensions(contextID, true); if (_id == 0) { extensions-glGenBuffers(1, _id); } extensions-glBindBuffer(GL_TEXTURE_BUFFER_EXT, _id); } void TextureBuffer::TextureBufferObject::bindTextureBuffer (osg::State state, GLenum internalFormat) { glTexBufferEXT(GL_TEXTURE_BUFFER_EXT, internalFormat, _id); } /* Member functions */ void TextureBuffer::apply(osg::State state) const { const unsigned int contextID = state.getContextID(); TextureObject* to = getTextureObject(contextID); TextureBufferObject *tbo = _textureBufferObjectsBuffer[contextID].get(); if (to != 0) { if (_image.valid() _modifiedCount[contextID] != _image-getModifiedCount()) { /* Update the texture buffer */ tbo-bindBuffer(contextID); glBufferSubData(GL_TEXTURE_BUFFER_EXT, 0, _bufferSize, _image-data()); glBindBuffer(GL_TEXTURE_BUFFER_EXT, 0); /* Update the modified tag to show that it is up to date. */ _modifiedCount[contextID] = _image-getModifiedCount(); } else if (_readPBuffer.valid()) { std::cerr Unsupported operation std::endl; } /* Binding the texture and its texture buffer object as texture storage. */ to-bind(); tbo-bindTextureBuffer(state, _internalFormat); } else if (_image.valid() _image-data()) { /* Temporary copy */ osg::ref_ptrosg::Image image = _image; /* Creating the texture object */ _textureObjectBuffer[contextID] = to = generateTextureObject(contextID, GL_TEXTURE_BUFFER_EXT); /* Creating the texture buffer object */ tbo = new TextureBufferObject(); _textureBufferObjectsBuffer[contextID] = tbo; /* Compute the internal texture format, this set the _internalFormat to an appropriate value. */ computeInternalFormat(); /* Computing the dimensions of the texture buffer */ _textureWidth = image-s(); _bufferSize = image-getImageSizeInBytes(); /* Binding TBO and copying data */ tbo-bindBuffer(contextID); glBufferData(GL_TEXTURE_BUFFER_EXT, _bufferSize, _image-data(), tbo-_usageHint); to-setAllocated(true); glBindBuffer(GL_TEXTURE_BUFFER_EXT, 0); to-bind(); tbo-bindTextureBuffer(state, _internalFormat); /* Update the modified tag to show that it is upto date. */ _modifiedCount[contextID] = image-getModifiedCount(); /* To consider */ //if (_unrefImageDataAfterApply areAllTextureObjectsLoaded() //image-getDataVariance() == STATIC) //{ //Texture2D* non_const_this = const_castTexture2D*(this); //non_const_this-_image = 0; //} } else { /* This texture type is input only (as far as I'm concerned), so it doesn't work without an attached image. */ glBindBuffer(GL_TEXTURE_BUFFER_EXT, 0); glBindTexture(GL_TEXTURE_BUFFER_EXT, 0); } } void TextureBuffer::computeInternalFormat() const { if (_internalFormatMode != USE_USER_DEFINED_FORMAT) { if (_internalFormatMode == USE_IMAGE_DATA_FORMAT) { if (_image.valid()) _internalFormat = _image-getInternalTextureFormat(); }