why shaderGenerator not support stencil?

classic Classic list List threaded Threaded
1 message Options
ldj ldj
Reply | Threaded
Open this post in threaded view
|

why shaderGenerator not support stencil?

please examine the following code    how to solve?
osg::Matrix  matrix;
    osgEarth::GeoPoint gpt(geoSRS, 116.396434261667835130538151133806,39.913401709322123167567042401060, 100, ALTMODE_ABSOLUTE);
    gpt.createLocalToWorld(matrix);
        //gpt.toWorld(pt);
        osg::MatrixTransform* mmt=new osg::MatrixTransform();
        mmt->setMatrix(matrix);
        osg::Geode* gd=new osg::Geode();
        osg::Geometry* geo=new osg::Geometry();
        osg::Vec3Array* verts = new osg::Vec3Array();
        osg::Vec3Array* normls = new osg::Vec3Array();
        osg::Vec4Array* colors = new osg::Vec4Array();
        osg::Vec2Array* texs = new osg::Vec2Array();
        verts->push_back(osg::Vec3d(-1000,-1000,0));
        verts->push_back(osg::Vec3d(1000,-1000,0));
        verts->push_back(osg::Vec3d(1000,1000,0));
        verts->push_back(osg::Vec3d(-1000,1000,0));
        normls->push_back(osg::Vec3d(0,0,1));
        colors->push_back(osg::Vec4f(1,1,1,1));
         texs->push_back(osg::Vec2d(0,0));
          texs->push_back(osg::Vec2d(1,0)); texs->push_back(osg::Vec2d(1,1)); texs->push_back(osg::Vec2d(0,1));
          geo->setUseDisplayList(false);
            geo->setUseVertexBufferObjects(true);
                geo->setVertexArray(verts);
                    geo->setNormalArray(normls);
                        geo->setNormalBinding(osg::Geometry::BIND_OVERALL);
                        geo->setColorArray(colors);
                        geo->setColorBinding(osg::Geometry::BIND_OVERALL);
                        geo->setTexCoordArray(0,texs);geo->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,verts->size()));
                       
                        osg::Image* image=osgDB::readImageFile("images/19JZ0102T24.jpg");
                         osg::Texture2D* tex2D=new osg::Texture2D();
                         tex2D->setImage(image);
                         tex2D->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
                         tex2D->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
                         tex2D->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE);
                         tex2D->setUnRefImageDataAfterApply(true);
                         tex2D->setResizeNonPowerOfTwoHint(false);

                         geo->getOrCreateStateSet()->setAttributeAndModes(tex2D,osg::StateAttribute::ON);
                         geo->getOrCreateStateSet()->setRenderBinDetails(0,"Render");
                         geo->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF| osg::StateAttribute::OVERRIDE);
                         gd->addDrawable(geo);
                         //gd->getOrCreateStateSet()->setMode(GL_NORMALIZE,osg::StateAttribute::ON);
                       
                       
                         mmt->addChild(gd);osgEarth::Registry::shaderGenerator().run(gd);
    sky->setDataVariance(osg::Object::DYNAMIC );
    sky->addChild(mmt);
          osg::Geometry* geo1=new osg::Geometry();
        osg::Vec3Array* verts1 = new osg::Vec3Array();
 
        verts1->push_back(osg::Vec3d(-100,-100,0));
        verts1->push_back(osg::Vec3d(100,-100,0));
        verts1->push_back(osg::Vec3d(100,100,0));
        verts1->push_back(osg::Vec3d(-100,100,0));
         
        geo1->setUseDisplayList(false);
    geo1->setUseVertexBufferObjects(true);
    geo1->setVertexArray(verts1);
    geo1->setNormalArray(normls);
        geo1->setNormalBinding(osg::Geometry::BIND_OVERALL);
        geo1->setColorArray(colors);
        geo1->setColorBinding(osg::Geometry::BIND_OVERALL);
        geo1->setTexCoordArray(0,texs);geo1->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,verts1->size()));
       
         
         geo1->getOrCreateStateSet()->setAttributeAndModes(tex2D,osg::StateAttribute::ON);
         osg::Stencil *stencil = new osg::Stencil;
        stencil->setFunction(osg::Stencil::ALWAYS, 1, ~0u);
        stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE);
    geo1->getOrCreateStateSet()->setAttributeAndModes(stencil,
                                        osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
     geo1->getOrCreateStateSet()->setRenderBinDetails(2,"Render");
       
         
         geo1->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF| osg::StateAttribute::OVERRIDE);
         //geo1->getOrCreateStateSet()->setMode(GL_NORMALIZE,osg::StateAttribute::ON);
         gd->addDrawable(geo1);
         
         //mmt->setDataVariance(osg::Object::DYNAMIC );
       
         osgEarth::Registry::shaderGenerator().run(gd);