외부 장치 비디오에서 프레임을 캡처하여 openSceneGraph 노드에서 렌더링해야하는 프로젝트 작업 중입니다. 나는 또한 GLSL 셰이더를 사용하고있다. 하지만 런타임에 텍스처를 업데이트하는 방법을 모르겠습니다. 다른 유니폼에 대해서는 콜백을해야하지만 glsl 및 openSceneGraph에서 샘플러에 대한 콜백을 수행해야합니까?OpenSceneGraph에서 런타임에 텍스처 업데이트하기
내 코드는 다음과 같습니다. 지금 내가 바라는 건 검은 창 뿐이야.
osg::ref_ptr<osg::Geometry> pictureQuad = osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),
osg::Vec3(_deviceNameToImageFrameMap[deviceName].frame->s(),0.0f,0.0f), osg::Vec3(0.0f,0.0f,_deviceNameToImageFrameMap[deviceName].frame->t()),
0.0f, 1.0f,_deviceNameToImageFrameMap[deviceName].frame->s(), _deviceNameToImageFrameMap[deviceName].frame->t());
//creating texture and setting up parameters for video frame
osg::ref_ptr<osg::TextureRectangle> myTex= new osg::TextureRectangle(_deviceNameToImageFrameMap[deviceName].frame.get());
myTex->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
myTex->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
myTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
myTex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
_videoSourceNameToNodeMap[sourceName].geode = new osg::Geode();
_videoSourceNameToNodeMap[sourceName].geode->setDataVariance(osg::Object::DYNAMIC);
_videoSourceNameToNodeMap[sourceName].geode->addDrawable(pictureQuad.get());
//apply texture to node
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, myTex.get(), osg::StateAttribute::ON);
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
_videoSourceNameToNodeMap[sourceName].geode->setDataVariance(osg::Object::DYNAMIC);
//Set uniform sampler
osg::Uniform* srcFrame = new osg::Uniform(osg::Uniform::SAMPLER_2D, "srcFrame");
srcFrame->set(0);
//Set Uniform Alpha
osg::Uniform* alpha = new osg::Uniform(osg::Uniform::FLOAT, "alpha");
alpha->set(.5f);
alpha->setUpdateCallback(new ExampleCallback());
//Enable blending
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
//Adding blend function to node
osg::BlendFunc *bf = new osg::BlendFunc();
bf->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->setAttributeAndModes(bf);
//apply shader to quad
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON);
//add Uniform to shader
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->addUniform(srcFrame);
_videoSourceNameToNodeMap[sourceName].geode->getOrCreateStateSet()->addUniform(alpha);