Re: [osg-users] SubloadCallback on iOS: missing texture.
Hi Alessandro subload-callbacks work fine on IOS, I modified your example and this works on my end (tested only simulator) I do not attach the image to the texture to prevent any automatic handling from osg, I store the image as property in the callback and use it from there. cheers, Stephan // my SubloadCallback: class ITexture2DSubloadCallback : public osg::Texture2D::SubloadCallback { public: ITexture2DSubloadCallback(osg::Texture2D* tex, osg::Image* img); virtual void load (const osg::Texture2D texture, osg::State state) const; virtual void subload (const osg::Texture2D texture, osg::State state) const; private: unsigned int m_POT_width, m_POT_height; osg::ref_ptrosg::Image _image; }; ITexture2DSubloadCallback::ITexture2DSubloadCallback(osg::Texture2D* texture, osg::Image* img) : osg::Texture2D::SubloadCallback(), _image(img) { // m_POT_width, m_POT_height are members of the subload callback m_POT_width = 128; m_POT_height = 128; // set the texture to beleive it is of power of two size texture-setTextureSize(m_POT_width, m_POT_height); // set to linear to disable mipmap generation texture-setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture-setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); } void ITexture2DSubloadCallback::load(const osg::Texture2D texture, osg::State state) const { //extern void glTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); glTexImage2D( GL_TEXTURE_2D, 0, _image-getInternalTextureFormat(), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), 0 ); state.checkGLErrors(ITexture2DSubloadCallback::load); std::cout load std::endl; } void ITexture2DSubloadCallback::subload(const osg::Texture2D texture, osg::State state) const { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _image-s(), _image-t(), _image-getPixelFormat(), _image-getDataType(), _image-data() ); state.checkGLErrors(ITexture2DSubloadCallback::subload); std::cout subload std::endl; } // and here's how I create the textured quad that is attached to the scene'sroot... void Sketch::setup() { // set window size float width = 200; float height = 200; osg::ref_ptrosg::Geode geode; osg::ref_ptrosg::Geometry geom; // create geometry... geode = new osg::Geode; geom = new osg::Geometry; osg::Vec3 top_left(0, height, 0); osg::Vec3 bottom_left(0, 0, 0); osg::Vec3 bottom_right(width, 0, 0); osg::Vec3 top_right(width, height, 0); // vertices... osg::ref_ptrosg::Vec3Array vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom-setVertexArray(vertices.get()); // texcoords... osg::ref_ptrosg::Vec2Array texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); (*texcoords)[2].set(1.0f,0.0f); (*texcoords)[3].set(1.0f,1.0f); geom-setTexCoordArray(0, texcoords.get()); // normals... osg::ref_ptrosg::Vec3Array normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f, 0.0f, 1.0f); geom-setNormalArray(normals.get()); geom-setNormalBinding(osg::Geometry::BIND_OVERALL); // colors... osg::ref_ptrosg::Vec4Array colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f); // this is the color that will be displayed if the texture won't be displayed geom-setColorArray(colors.get()); geom-setColorBinding(osg::Geometry::BIND_OVERALL); geom-addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); geode-addDrawable(geom.get()); // texture... osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP ); texture-setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP ); texture-setDataVariance(osg::Object::DYNAMIC); texture-setResizeNonPowerOfTwoHint(false);
Re: [osg-users] SubloadCallback on iOS: missing texture.
Hi Stephan and Thomas, what do you think about the sample code I've sent? Is there something wrong with it? Actually, since it works on a PC but not on iOS, maybe there is something wrong with the options used to build OSG for iOS (or maybe with CMake options)...I'm just guessing. Thanks. Alessandro On Sat, Apr 23, 2011 at 10:06 PM, Alessandro Terenzi a.tere...@gmail.comwrote: Hi again, here's the code I'm using: // my SubloadCallback: ITexture2DSubloadCallback::ITexture2DSubloadCallback(osg::Texture2D* texture) { const osg::Image* _image = texture-getImage(); // m_POT_width, m_POT_height are members of the subload callback m_POT_width = (double)mathNextPowerOf2((unsigned int)_image-s()), m_POT_height = (double)mathNextPowerOf2((unsigned int)_image-t()), // set the texture to beleive it is of power of two size texture-setTextureSize(m_POT_width, m_POT_height); // set to linear to disable mipmap generation texture-setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture-setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); } void ITexture2DSubloadCallback::load(const osg::Texture2D texture, osg::State state) const { const osg::Image* _image = texture.getImage(); glTexImage2D(GL_TEXTURE_2D, 0, osg::Image::computeNumComponents(_image-getInternalTextureFormat()), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), 0 ); state.checkGLErrors(ITexture2DSubloadCallback::load); } void ITexture2DSubloadCallback::subload(const osg::Texture2D texture, osg::State state) const { const osg::Image* _image = texture.getImage(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _image-s(), _image-t(), _image-getPixelFormat(), _image-getDataType(), _image-data() ); state.checkGLErrors(ITexture2DSubloadCallback::subload); } // and here's how I create the textured quad that is attached to the scene's root... float width = 200; float height = 200; osg::ref_ptrosg::Geode geode; osg::ref_ptrosg::Geometry geom; // create geometry... geode = new osg::Geode; geom = new osg::Geometry; osg::Vec3 top_left(0, height, 0); osg::Vec3 bottom_left(0, 0, 0); osg::Vec3 bottom_right(width, 0, 0); osg::Vec3 top_right(width, height, 0); // vertices... osg::ref_ptrosg::Vec3Array vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom-setVertexArray(vertices.get()); // texcoords... osg::ref_ptrosg::Vec2Array texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); (*texcoords)[2].set(1.0f,0.0f); (*texcoords)[3].set(1.0f,1.0f); geom-setTexCoordArray(0, texcoords.get()); // normals... osg::ref_ptrosg::Vec3Array normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f, 0.0f, 1.0f); geom-setNormalArray(normals.get()); geom-setNormalBinding(osg::Geometry::BIND_OVERALL); // colors... osg::ref_ptrosg::Vec4Array colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f); // this is the color that will be displayed if the texture won't be displayed geom-setColorArray(colors.get()); geom-setColorBinding(osg::Geometry::BIND_OVERALL); geom-addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); geode-addDrawable(geom.get()); // texture... osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP ); texture-setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP ); texture-setDataVariance(osg::Object::DYNAMIC); osg::ref_ptrosg::Image image = osgDB::readImageFile(Icon.png); // 57x57 image (NPOT)... if(image.valid()) texture-setImage(image.get()); *osg::ref_ptrITexture2DSubloadCallback t2dscb = new ITexture2DSubloadCallback(texture); texture-setSubloadCallback(t2dscb.get()); * // stateset... osg::StateSet* stateset = geom-getOrCreateStateSet(); stateset-setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); stateset-setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON); m_root-addChild(geode.get()); That's all. Hope you can help. Thanks! Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] SubloadCallback on iOS: missing texture.
Hi, Am 27.04.11 09:36, schrieb Alessandro Terenzi: what do you think about the sample code I've sent? Is there something wrong with it? Your example failed to work on my mac with a recent osg-version. Unfortunately I hadn't more time to investige the issue further. I had to change glTexImage2D(GL_TEXTURE_2D, 0, osg::Image::computeNumComponents(_image-getInternalTextureFormat()), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), 0 ); to glTexImage2D( GL_TEXTURE_2D, 0, _image-getInternalTextureFormat(), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), _image-data() ); to get rid of the opengl-warning. But the subload-callback is never called on my end. Perhaps i find some time this weekend to do some more tests. cheers, Stephan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] SubloadCallback on iOS: missing texture.
Thank you very much Stephan, I tried to modify my code as suggested: the warning disappeared and my subload callback is called. Tomorrow I'll try with the latest tagged release (2.9.13) and let you know. Alessandro On Wed, Apr 27, 2011 at 9:34 PM, Stephan Huber ratzf...@digitalmind.dewrote: Hi, Am 27.04.11 09:36, schrieb Alessandro Terenzi: what do you think about the sample code I've sent? Is there something wrong with it? Your example failed to work on my mac with a recent osg-version. Unfortunately I hadn't more time to investige the issue further. I had to change glTexImage2D(GL_TEXTURE_2D, 0, osg::Image::computeNumComponents(_image-getInternalTextureFormat()), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), 0 ); to glTexImage2D( GL_TEXTURE_2D, 0, _image-getInternalTextureFormat(), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), _image-data() ); to get rid of the opengl-warning. But the subload-callback is never called on my end. Perhaps i find some time this weekend to do some more tests. cheers, Stephan ___ 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] SubloadCallback on iOS: missing texture.
Hi, it's hard to tell what's going wrong on your end without seeing the code. Texture-subloading works on IOS in general, if you are using an osg::Image which is attached to an osg::Texture and set it's dirty-flag. As a general note: TextureRectangle is not supported on OpenGL ES, there's an extension to use NPOT Texture2Ds on IOS, which is supported and used by osg. HTH, Stephan Am 22.04.11 22:54, schrieb Alessandro Terenzi: I'm trying to use a SubloadCallback to update a NPOT texture in an app for iOS. Actually the very same logic seems to work fine on a PC but on iOS it is not working: I always get a flat-white color on the plane supposed to be textured (I'm referring to the examples about SubloadCallbacks that can be found in the forum and I'm using the latest tagged version of OSG 2.9.12). When I execute the app, I notice that the load method generates this warning: *Warning: detected OpenGL error 'invalid operation' at After Renderer::compile * and the subload method: *Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)* (repeated forever...) Is there something that must be done for iOS in order to successfully use SubloadCallbacks? By the way, I also tried to override the textureObjectValid(.) method so that it always returns true (as suggested in another thread), this makes it to work on a PC but not yet on iOS devices. Thank you for your help. Alessandro ___ 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] SubloadCallback on iOS: missing texture.
Thank you Stephan, I'll try to simplify my code and post it here later. Alessandro On Sat, Apr 23, 2011 at 11:00 AM, Stephan Huber ratzf...@digitalmind.dewrote: Hi, it's hard to tell what's going wrong on your end without seeing the code. Texture-subloading works on IOS in general, if you are using an osg::Image which is attached to an osg::Texture and set it's dirty-flag. As a general note: TextureRectangle is not supported on OpenGL ES, there's an extension to use NPOT Texture2Ds on IOS, which is supported and used by osg. HTH, Stephan Am 22.04.11 22:54, schrieb Alessandro Terenzi: I'm trying to use a SubloadCallback to update a NPOT texture in an app for iOS. Actually the very same logic seems to work fine on a PC but on iOS it is not working: I always get a flat-white color on the plane supposed to be textured (I'm referring to the examples about SubloadCallbacks that can be found in the forum and I'm using the latest tagged version of OSG 2.9.12). When I execute the app, I notice that the load method generates this warning: *Warning: detected OpenGL error 'invalid operation' at After Renderer::compile * and the subload method: *Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)* (repeated forever...) Is there something that must be done for iOS in order to successfully use SubloadCallbacks? By the way, I also tried to override the textureObjectValid(.) method so that it always returns true (as suggested in another thread), this makes it to work on a PC but not yet on iOS devices. Thank you for your help. Alessandro ___ 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 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] SubloadCallback on iOS: missing texture.
Hi again, here's the code I'm using: // my SubloadCallback: ITexture2DSubloadCallback::ITexture2DSubloadCallback(osg::Texture2D* texture) { const osg::Image* _image = texture-getImage(); // m_POT_width, m_POT_height are members of the subload callback m_POT_width = (double)mathNextPowerOf2((unsigned int)_image-s()), m_POT_height = (double)mathNextPowerOf2((unsigned int)_image-t()), // set the texture to beleive it is of power of two size texture-setTextureSize(m_POT_width, m_POT_height); // set to linear to disable mipmap generation texture-setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture-setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); } void ITexture2DSubloadCallback::load(const osg::Texture2D texture, osg::State state) const { const osg::Image* _image = texture.getImage(); glTexImage2D(GL_TEXTURE_2D, 0, osg::Image::computeNumComponents(_image-getInternalTextureFormat()), (int)m_POT_width, (int)m_POT_height, 0, _image-getPixelFormat(), _image-getDataType(), 0 ); state.checkGLErrors(ITexture2DSubloadCallback::load); } void ITexture2DSubloadCallback::subload(const osg::Texture2D texture, osg::State state) const { const osg::Image* _image = texture.getImage(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _image-s(), _image-t(), _image-getPixelFormat(), _image-getDataType(), _image-data() ); state.checkGLErrors(ITexture2DSubloadCallback::subload); } // and here's how I create the textured quad that is attached to the scene's root... float width = 200; float height = 200; osg::ref_ptrosg::Geode geode; osg::ref_ptrosg::Geometry geom; // create geometry... geode = new osg::Geode; geom = new osg::Geometry; osg::Vec3 top_left(0, height, 0); osg::Vec3 bottom_left(0, 0, 0); osg::Vec3 bottom_right(width, 0, 0); osg::Vec3 top_right(width, height, 0); // vertices... osg::ref_ptrosg::Vec3Array vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom-setVertexArray(vertices.get()); // texcoords... osg::ref_ptrosg::Vec2Array texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); (*texcoords)[2].set(1.0f,0.0f); (*texcoords)[3].set(1.0f,1.0f); geom-setTexCoordArray(0, texcoords.get()); // normals... osg::ref_ptrosg::Vec3Array normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f, 0.0f, 1.0f); geom-setNormalArray(normals.get()); geom-setNormalBinding(osg::Geometry::BIND_OVERALL); // colors... osg::ref_ptrosg::Vec4Array colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f); // this is the color that will be displayed if the texture won't be displayed geom-setColorArray(colors.get()); geom-setColorBinding(osg::Geometry::BIND_OVERALL); geom-addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); geode-addDrawable(geom.get()); // texture... osg::ref_ptrosg::Texture2D texture = new osg::Texture2D; texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP ); texture-setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP ); texture-setDataVariance(osg::Object::DYNAMIC); osg::ref_ptrosg::Image image = osgDB::readImageFile(Icon.png); // 57x57 image (NPOT)... if(image.valid()) texture-setImage(image.get()); *osg::ref_ptrITexture2DSubloadCallback t2dscb = new ITexture2DSubloadCallback(texture); texture-setSubloadCallback(t2dscb.get()); * // stateset... osg::StateSet* stateset = geom-getOrCreateStateSet(); stateset-setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); stateset-setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON); m_root-addChild(geode.get()); That's all. Hope you can help. Thanks! Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] SubloadCallback on iOS: missing texture.
I'm trying to use a SubloadCallback to update a NPOT texture in an app for iOS. Actually the very same logic seems to work fine on a PC but on iOS it is not working: I always get a flat-white color on the plane supposed to be textured (I'm referring to the examples about SubloadCallbacks that can be found in the forum and I'm using the latest tagged version of OSG 2.9.12). When I execute the app, I notice that the load method generates this warning: *Warning: detected OpenGL error 'invalid operation' at After Renderer::compile * and the subload method: *Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)* (repeated forever...) Is there something that must be done for iOS in order to successfully use SubloadCallbacks? By the way, I also tried to override the textureObjectValid(.) method so that it always returns true (as suggested in another thread), this makes it to work on a PC but not yet on iOS devices. Thank you for your help. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org