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_ptr<osg::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_ptr<osg::Geode> geode;
osg::ref_ptr<osg::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_ptr<osg::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_ptr<osg::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_ptr<osg::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_ptr<osg::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_ptr<osg::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);
osg::ref_ptr<osg::Image> image = osgDB::readImageFile("Icon.png"); //
57x57
osg::ref_ptr<ITexture2DSubloadCallback> t2dscb = new
ITexture2DSubloadCallback(texture, image.get());
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);
getWorld()->addChild(geode.get());
// allow osg-event handler:
allowOsgHandler(true);
getMainWindow()->setCameraManipulator(new
osgGA::MultiTouchTrackballManipulator());
}
Am 27.04.11 22:57, schrieb Alessandro Terenzi:
> 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 <[email protected]>wrote:
>
>> 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
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org