Art,

Thanks a lot, I've made the change you suggested.  Also, as it turns out, I had 
a number of 
other things preventing my sample program from working.  I needed to add 

textureArray->setFilter(osg::Texture2DArray::MIN_FILTER, 
osg::Texture2DArray::NEAREST);
textureArray->setFilter(osg::Texture2DArray::MAG_FILTER, 
osg::Texture2DArray::NEAREST);

otherwise I was getting a warning:

'Warning: Texture2DArray::applyTexImage2DArray_subload(..) automagic mipmap 
generation
is currently not implemented.'

which resulted in nothing but black.  Furthermore, I guess it is a requirement 
that you have at 
least two layers (of course you wouldn't be using a texture array unless you 
had more than one 
layer).  By adding a second image to the Texture2DArray, it showed up (even 
though I'm still 
only reading from the first layer in my shader).  I'm not sure if this is the 
intended behavior, but 
it seems to be the case.

Thank you again.  I've attached my sample program just in case someone else is 
having trouble
getting Texture2DArray to work.

-Sean



> Date: Mon, 25 Feb 2008 20:08:17 +0100
> From: [EMAIL PROTECTED]
> To: [email protected]
> Subject: Re: [osg-users] Texture2DArray shows up black
> 
> Hi Sean,
> 
> as far as I see you have an error in your setup. This
> line:
> 
> ref_ptr<Uniform> texturesUniform = new
> Uniform(Uniform::FLOAT,
>  'textures', 1);
> 
> 
> 
> must be replaced with something like this:
> 
> ref_ptr<Uniform> texturesUniform = new
> Uniform(Uniform::SAMPLER_2D_ARRAY,
>  'textures', 0);
> 
> 
> Try this out.
> 
> Cheers,
> Art
> 
> 
> --- Sean Carmody <[EMAIL PROTECTED]> schrieb:
> 
> > 
> > Hi Art,
> > 
> > Thanks for the idea.  I do have a Geforce 8800, and
> > the extensions are reported as being supported.
> > I've attached a very simple program (shaders inlined
> > in the code) which shows my setup, if anyone
> > is interested.  Thanks.
> > 
> > -Sean
> > 
> > 
> > > Date: Mon, 25 Feb 2008 13:27:55 +0100
> > > From: [EMAIL PROTECTED]
> > > To: [email protected]
> > > Subject: Re: [osg-users] Texture2DArray shows up
> > black
> > > 
> > > Hi Sean,
> > > 
> > > which graphic card do you have? Texture2DArray do
> > only
> > > work fine with G80 chips. I have never tested it
> > on
> > > current ATI chips.
> > > 
> > > Best,
> > > Art
> > > 
> > > 
> > > --- Sean Carmody <[EMAIL PROTECTED]> schrieb:
> > > 
> > > > 
> > > > Hi All,
> > > > 
> > > > I'm trying to get Texture2DArrays working, but
> > am
> > > > having some trouble.  My textures always show up
> > > > black.  I'm setting up the texture array as
> > follows
> > > > 
> > > >     ref_ptr<Texture2DArray> textureArray = new
> > > > Texture2DArray;
> > > >     textureArray->setTextureDepth(1);
> > > >     Image* image =
> > > > osgDB::readImageFile('media/skymap.tga');
> > > >     textureArray->setImage(0, image);
> > > >     stateSet->setTextureAttribute(0,
> > > > textureArray.get(), osg::StateAttribute::ON);
> > > > 
> > > > and trying to read it in the shader.
> > > > 
> > > >     #version 120 
> > > >     #extension GL_EXT_gpu_shader4 : enable
> > > >     
> > > >     uniform sampler2DArray rainTextures;
> > > > 
> > > >     void main()
> > > >     {
> > > >         gl_FragColor =
> > texture2DArray(rainTextures,
> > > > vec3(gl_TexCoord[0].st, 0));
> > > >     }
> > > > 
> > > > Now, if I switch out the Texture2DArray with a
> > > > normal Texture2D (and update the shader
> > accordingly)
> > > > it shows up fine, which leads me to believe the
> > rest
> > > > of the app is working.  I'm pretty new to OSG
> > and so
> > > > am wondering if I missed something obvious with
> > the
> > > > setup of the Texture2DArray.  Thanks!
> > > > 
> > > > -Sean
> > > > 
> > > >
> > >
> >
> _________________________________________________________________
> > > > Shed those extra pounds with MSN and The Biggest
> > > > Loser!
> > > > http://biggestloser.msn.com/>
> > > _______________________________________________
> > > > osg-users mailing list
> > > > [email protected]
> > > >
> > >
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > > 
> > > 
> > > 
> > > 
> > >       Lesen Sie Ihre E-Mails jetzt einfach von
> > unterwegs.
> > > www.yahoo.de/go
> > > _______________________________________________
> > > osg-users mailing list
> > > [email protected]
> > >
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> >
> _________________________________________________________________
> > Need to know the score, the latest news, or you need
> > your HotmailĀ®-get your 'fix'.
> > http://www.msnmobilefix.com/Default.aspx> #include
> <osg/Group>
> > #include <osg/Geode>
> > #include <osg/ShapeDrawable>
> > #include <osg/Node>
> > #include <osgViewer/Viewer>
> > #include <osg/Texture2DArray>
> > #include <osgDB/ReadFile>
> > #include <string>
> > 
> > using namespace osg;
> > 
> > void applyShader(Geode* geode)
> > {
> >     ref_ptr<Program> program = new Program;
> >     program->setName('TexturesTest');
> >     ref_ptr<Shader> vertObj = new
> > Shader(Shader::VERTEX);
> >     ref_ptr<Shader> fragObj = new
> > Shader(Shader::FRAGMENT);
> > 
> >     program->addShader(vertObj.get());
> >     program->addShader(fragObj.get());
> > 
> >     ref_ptr<StateSet> stateSet = new osg::StateSet;
> >     ref_ptr<Uniform> texturesUniform = new
> > Uniform(Uniform::FLOAT, 'textures', 1);
> >     stateSet->addUniform(texturesUniform.get());
> >     stateSet->setAttributeAndModes(program.get(),
> > StateAttribute::ON);
> > 
> >     ref_ptr<Texture2DArray> textureArray = new
> > Texture2DArray;
> >     textureArray->setTextureDepth(1);
> >     Image* image =
> > osgDB::readImageFile('Images/Brick-Std-Orange.TGA');
> >     textureArray->setImage(0, image);
> >     stateSet->setTextureAttribute(0,
> > textureArray.get(), osg::StateAttribute::ON);
> > 
> >     std::string vertSource = 
> >             'void main()'
> >             '{'
> >                     'gl_TexCoord[0].st = gl_MultiTexCoord0.st;'
> >                     'gl_Position = ftransform();'
> >             '}';
> >     vertObj->setShaderSource(vertSource);
> > 
> >     std::string fragSource = 
> >             '#version 120\n'
> >             '#extension GL_EXT_gpu_shader4 : enable\n'
> >             ''
> >             'uniform sampler2DArray textures;'
> >             ''
> >             'void main()'
> >             '{'
> >                     'gl_FragColor = texture2DArray(textures,
> > vec3(gl_TexCoord[0].xy, 0));'
> >             '}';
> >     fragObj->setShaderSource(fragSource);
> >     
> >     geode->setStateSet(stateSet.get());
> > }
> > 
> > int main(int argc, char** argv)
> > {
> >     setNotifyLevel(osg::DEBUG_INFO);
> > 
> >     // Create a cube
> >     ref_ptr<Group> rootNode = new Group;
> >     Box* cube = new Box(Vec3(0,0,0), 1.0f);
> >     ShapeDrawable* drawable = new ShapeDrawable(cube);
> >     Geode* geode = new Geode();
> >     geode->addDrawable(drawable);
> >     rootNode->addChild(geode);
> > 
> >     // Apply our shader to this cube
> >     applyShader(geode);
> > 
> >     osgViewer::Viewer viewer;
> >     viewer.setSceneData(rootNode.get());
> >     return viewer.run();
> > }
> > > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> 
> 
> 
>       Lesen Sie Ihre E-Mails auf dem Handy.
> www.yahoo.de/go
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_________________________________________________________________
Connect and share in new ways with Windows Live.
http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008
#include <osg/Group>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Node>
#include <osgViewer/Viewer>
#include <osg/Texture2DArray>
#include <osgDB/ReadFile>
#include <string>

using namespace osg;

void applyShader(Geode* geode)
{
        ref_ptr<Program> program = new Program;
        program->setName("TexturesTest");
        ref_ptr<Shader> vertObj = new Shader(Shader::VERTEX);
        ref_ptr<Shader> fragObj = new Shader(Shader::FRAGMENT);

        program->addShader(vertObj.get());
        program->addShader(fragObj.get());

        ref_ptr<StateSet> stateSet = new osg::StateSet;
        ref_ptr<Uniform> texturesUniform = new 
Uniform(Uniform::SAMPLER_2D_ARRAY, "textures", 0);
        stateSet->addUniform(texturesUniform.get());
        stateSet->setAttributeAndModes(program.get(), StateAttribute::ON);

        ref_ptr<Texture2DArray> textureArray = new Texture2DArray;
        textureArray->setFilter(osg::Texture2DArray::MIN_FILTER, 
osg::Texture2DArray::NEAREST);
    textureArray->setFilter(osg::Texture2DArray::MAG_FILTER, 
osg::Texture2DArray::NEAREST);
        textureArray->setTextureDepth(2);
        Image* image = osgDB::readImageFile("Images/Brick-Std-Orange.TGA");
        textureArray->setImage(0, image);
        textureArray->setImage(1, image);
        stateSet->setTextureAttribute(0, textureArray.get(), 
osg::StateAttribute::ON);

        std::string vertSource = 
                "void main()"
                "{"
                        "gl_TexCoord[0].st = gl_MultiTexCoord0.st;"
                        "gl_Position = ftransform();"
                "}";
        vertObj->setShaderSource(vertSource);

        std::string fragSource = 
                "#version 120\n"
                "#extension GL_EXT_gpu_shader4 : enable\n"
                ""
                "uniform sampler2DArray textures;"
                ""
                "void main()"
                "{"
                        "gl_FragColor = texture2DArray(textures, 
vec3(gl_TexCoord[0].xy, 0));"
                "}";
        fragObj->setShaderSource(fragSource);
        
        geode->setStateSet(stateSet.get());
}

int main(int argc, char** argv)
{
        setNotifyLevel(osg::DEBUG_INFO);

        // Create a cube
        ref_ptr<Group> rootNode = new Group;
        Box* cube = new Box(Vec3(0,0,0), 1.0f);
        ShapeDrawable* drawable = new ShapeDrawable(cube);
        Geode* geode = new Geode();
        geode->addDrawable(drawable);
        rootNode->addChild(geode);

        // Apply our shader to this cube
        applyShader(geode);

        osgViewer::Viewer viewer;
        viewer.setSceneData(rootNode.get());
        return viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to