void ShaderShadowMapEngine::updateShadowTexImage(SSMEngineData *data) { Image *bufImg = data->getShadowTexImage(); TextureObjChunk *bufTex = data->getShadowTexChunk(); FASSERT((bufTex != NULL), false) if(bufImg == NULL) { ImageUnrecPtr newBufImg = Image::createLocal(); newBufImg->set(Image::OSG_L_PF, this->getWidth (), this->getHeight(), 1, 1, 1, 0., NULL, Image::OSG_UINT8_IMAGEDATA, false, 1); bufTex->setImage (newBufImg); data ->setShadowTexImage(newBufImg); bufImg = newBufImg; } if((bufImg->getWidth () != this->getWidth ()) || (bufImg->getHeight() != this->getHeight()) ) { bufImg->setWidth (this->getWidth ()); bufImg->setHeight(this->getHeight()); } }
void TextureBuffer::processPostDeactivate(DrawEnv *pEnv) { Window *win = pEnv->getWindow(); // If there are TextureBuffers with mipmap filters attached, // the mipmaps need to be regenerated TextureObjChunk *pTexObj = this->getTexture(); if(pTexObj == NULL) return; GLenum target = pTexObj->determineTextureTarget(win); if(target == GL_TEXTURE_2D && (pTexObj->getMinFilter() == GL_NEAREST_MIPMAP_NEAREST || pTexObj->getMinFilter() == GL_LINEAR_MIPMAP_NEAREST || pTexObj->getMinFilter() == GL_NEAREST_MIPMAP_LINEAR || pTexObj->getMinFilter() == GL_LINEAR_MIPMAP_LINEAR ) ) { OSGGETGLFUNC( OSGglGenerateMipmapProc, osgGlGenerateMipmapProc, _uiFuncGenerateMipmap ); glBindTexture(target, win->getGLObjectId(pTexObj->getGLId())); osgGlGenerateMipmapProc(target); } }
void ColorDisplayFilter::deactivate(DisplayFilterStageData *pData) { SimpleSHLChunk *pShader = pData->getColorFilterShader (); TextureObjChunk *pTex = pData->getColorFilterTexture(); if(pShader != NULL) pShader->setIgnore(true); if(pTex != NULL) pTex->setIgnore(true); }
void DeferredShadingStage::updateGBuffer( TextureBuffer *buf, UInt32 index, Int32 width, Int32 height) { TextureObjChunk *bufTex = buf ->getTexture(); Image *bufImg = bufTex->getImage (); if((_changeCache & (PixelFormatsFieldMask | PixelTypesFieldMask )) != 0) { bufImg->setPixelFormat(_mfPixelFormats[index]); bufImg->setDataType (_mfPixelTypes [index]); } if(_targetSizeChanged == true) { bufImg->setWidth (width ); bufImg->setHeight(height); } }
void DisplayFilterStage::resizeStageData(DisplayFilterStageData *pData, Int32 iPixelWidth, Int32 iPixelHeight) { FrameBufferObject *pFBO = pData->getTarget(); if(pFBO == NULL) return; TextureBuffer *pTexBuffer = dynamic_cast<TextureBuffer *>(pFBO->getColorAttachments(0)); if(pTexBuffer == NULL) return; TextureObjChunk *pTex = pTexBuffer->getTexture(); if(pTex == NULL) return; Image *pImg = pTex->getImage(); if(pImg == NULL) return; pImg->set(Image::OSG_RGB_PF, iPixelWidth, iPixelHeight, 1, 1, 1, 0.0, 0, Image::OSG_UINT8_IMAGEDATA, false); pFBO->setSize(iPixelWidth, iPixelHeight); pData->setWidth (iPixelWidth ); pData->setHeight(iPixelHeight); commitChanges(); }
void ColorDisplayFilter::process(DisplayFilterStageData *pData) { SimpleSHLChunk *pShader = pData->getColorFilterShader(); if(pShader == NULL || this->getFilterShader() != pShader) { pShader = this->getFilterShader(); OSG_ASSERT(pShader != NULL); ChunkMaterial *pCMat = pData->getBaseMaterial(); OSG_ASSERT(pCMat != NULL); pCMat->addChunk(pShader); commitChanges(); pData->setColorFilterShader(pShader); } TextureObjChunk *pColTex = pData->getColorFilterTexture(); if(pData->getInitColTableFrom() != this) { if(pColTex == NULL) { TextureObjChunkUnrecPtr pTex = TextureObjChunk::createLocal(); pTex->setMinFilter(GL_LINEAR ); pTex->setMagFilter(GL_LINEAR ); pTex->setWrapS (GL_CLAMP_TO_EDGE ); pTex->setWrapT (GL_CLAMP_TO_EDGE ); pTex->setWrapR (GL_CLAMP_TO_EDGE ); pData->setColorFilterTexture(pTex); ChunkMaterial *pCMat = pData->getBaseMaterial(); OSG_ASSERT(pCMat != NULL); pCMat->addChunk(pTex, 1); pColTex = pTex; } pData->setInitColTableFrom(this); pColTex->setImage(this->getTableImage()); commitChanges(); } OSG_ASSERT(pShader != NULL); OSG_ASSERT(pColTex != NULL); pShader->setIgnore(false); pColTex->setIgnore(false); }
void DepthPeelingStage::setupRenderScene(RenderAction* a, Int32 iVPWidth, Int32 iVPHeight, bool isInitial, bool isPing ) { this->pushPartition(a); { RenderPartition *pPart = a->getActivePartition(); FrameBufferObject *pTarget = NULL; Viewarea *pArea = a->getViewarea (); Camera *pCam = a->getCamera (); Background *pBack = NULL; DepthPeelingStageDataUnrecPtr pData = a->getData<DepthPeelingStageData *>(_iDataSlotId); if(!pData) { this->initData(a, iVPWidth, iVPHeight); } else { this->updateData(a, iVPWidth, iVPHeight); } pData = a->getData<DepthPeelingStageData *>(_iDataSlotId); if (isInitial) { pTarget = pData->getBlendFBO(); pBack = a->getBackground (); } else { if (isPing) pTarget = pData->getPeelPingFBO(); else pTarget = pData->getPeelPongFBO(); pBack = pData->getBackground(); } pPart->setRenderTarget(pTarget); if(pArea != NULL) { pPart->setWindow (a->getWindow()); if(pTarget != NULL) { pPart->calcViewportDimension(pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), pTarget->getWidth (), pTarget->getHeight ()); } else { pPart->calcViewportDimension(pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), a->getWindow()->getWidth (), a->getWindow()->getHeight()); } if(pCam != NULL) { Matrix m, t; // set the projection pCam->getProjection (m, pPart->getViewportWidth (), pPart->getViewportHeight()); pCam->getProjectionTranslation(t, pPart->getViewportWidth (), pPart->getViewportHeight()); pPart->setupProjection(m, t); pCam->getViewing(m, pPart->getViewportWidth (), pPart->getViewportHeight()); pPart->setupViewing(m); pPart->setNear (pCam->getNear()); pPart->setFar (pCam->getFar ()); pPart->calcFrustum(); } pPart->setBackground(pBack); } pPart->addSetupModeBit(RenderPartition::BackgroundSetup); pPart->pushState(); if (!isInitial) { FrameBufferObject* fbo = isPing ? pData->getPeelPongFBO() : pData->getPeelPingFBO(); TextureBuffer* texbuf = static_cast<TextureBuffer *>(fbo->getDepthAttachment()); TextureObjChunk* depthTexChunk = texbuf->getTexture(); pPart->addOverride(depthTexChunk->getClassId() + getDepthTexUnit(), depthTexChunk ); pPart->addOverride(pData->getSpvIsPeelChunk()->getClassId(), pData->getSpvIsPeelChunk() ); } else { pPart->addOverride(pData->getSpvIsInitialChunk()->getClassId(), pData->getSpvIsInitialChunk() ); } pPart->addOverride(pData->getDepthChunk()->getClassId(), pData->getDepthChunk() ); this->recurseFromThis(a); a->useNodeList(false); pPart->popState(); } this->popPartition(a); }
void StagedViewport::stretchTargetToFrameBuffer(RenderActionBase *action, FrameBufferObject *target) { Window *pWin = action->getWindow(); if((pWin->getDrawMode() & Window::PartitionDrawMask) == Window::SequentialPartitionDraw) { DrawEnv oEnv; oEnv.setWindow(action->getWindow()); //oEnv.setTileFullSize(getCamera()->tileGetFullSize()); //oEnv.setTileRegion (getCamera()->tileGetRegion ()); // THINKABOUTME KS: //oEnv.setDrawerId (action->getDrawerId ()); //oEnv.setDrawableId(action->getDrawableId()); glClearColor(0.0, 1.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); FrameBufferAttachment* fba = target->getColorAttachments(0); TextureObjChunk* texObj = dynamic_cast<TextureBuffer*>(fba)->getTexture(); if( texObj ) { texObj->activate(&oEnv,0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, 1, 0, 1, -1, 1 ); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); float u = 0.0f; float v = 0.0f; // glColor3f(1,1,1); glBegin(GL_QUADS); #if 0 RTsize w,h; buffer->getSize(w,h); float view[4]; view[0] = _optixViewport._viewport.x/(float)w; view[1] = _optixViewport._viewport.y/(float)h; view[2] = view[0] + _optixViewport._viewport.z/(float)w; view[3] = view[1] + _optixViewport._viewport.w/(float)h; glTexCoord2f(view[0], view[1]); glVertex2f(0.0f, 0.0f); glTexCoord2f(view[2], view[1]); glVertex2f(1.0f, 0.0f); glTexCoord2f(view[2], view[3]); glVertex2f(1.0f, 1.0f); glTexCoord2f(view[0], view[3]); glVertex2f(0.0f, 1.0f); #else glTexCoord2f(u, v); glVertex2f(0.1f, 0.1f); glTexCoord2f(1.0f, v); glVertex2f(.9f, 0.1f); glTexCoord2f(1.0f - u, 1.0f - v); glVertex2f(.9f, .9f); glTexCoord2f(u, 1.0f - v); glVertex2f(0.1f, .9f); #endif glEnd(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); texObj->deactivate(&oEnv,0); } } else { // TODO: ??? OSG_ASSERT(false); } }
static Action::ResultE modifyMaterial(Node * const node) { MaterialGroup *mg = dynamic_cast<MaterialGroup *>(node->getCore()); if(mg == NULL) return Action::Continue; ChunkMaterial *cmat = dynamic_cast<ChunkMaterial *>(mg->getMaterial()); if(cmat == NULL) return Action::Continue; TextureObjChunk *texc = dynamic_cast<TextureObjChunk *>( cmat->find(TextureObjChunk::getClassType())); if(texc == NULL) return Action::Continue; MaterialChunk *matc = dynamic_cast<MaterialChunk *>( cmat->find(MaterialChunk::getClassType())); TextureEnvChunkUnrecPtr texe = dynamic_cast<TextureEnvChunk *>( cmat->find(TextureEnvChunk::getClassType())); if(texe == NULL) { texe = TextureEnvChunk::create(); cmat->addChunk(texe); } if(matc == NULL) { // no material chunk so we use the replace mode. texe->setEnvMode(GL_REPLACE); return Action::Continue; } if(matc != NULL) { Image *img = texc->getImage(); texe->setEnvMode(GL_MODULATE); if(img != NULL && img->getBpp() > 2) { // for color textures the texture replaces only the diffuse part. matc->setDiffuse(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); } // check for textures with alpha if(!matc->isTransparent() && img != NULL && img->getBpp() == 4 ) { BlendChunkUnrecPtr blendc = dynamic_cast<BlendChunk *>( cmat->find(BlendChunk::getClassType())); if(blendc == NULL) { blendc = OSG::BlendChunk::create(); blendc->setSrcFactor (GL_SRC_ALPHA); blendc->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); cmat->addChunk(blendc); } } } return Action::Continue; }
void TextureBuffer::processPreDeactivate(DrawEnv *pEnv, UInt32 index) { if(_sfReadBack.getValue() == true) { TextureObjChunk *pTexObj = this->getTexture(); if(pTexObj == NULL) return; Image *pTexImg = pTexObj->getImage(); if(pTexImg->getData() == NULL) { SINFO << "TextureBuffer::render: (Re)Allocating image " << "for read-back." << endLog; pTexImg->set(pTexImg->getPixelFormat(), pTexImg->getWidth (), pTexImg->getHeight (), pTexImg->getDepth (), pTexImg->getMipMapCount(), pTexImg->getFrameCount (), pTexImg->getFrameDelay (), NULL, pTexImg->getDataType (), true, pTexImg->getSideCount () ); } UInt32 mipMapLevel = _sfLevel.getValue(); UInt32 frame = 0; UInt32 side = 0; GLenum target; Window *pWindow = pEnv->getWindow(); if(_sfTexTarget.getValue() != GL_NONE) { target = _sfTexTarget.getValue(); } else { target = _sfTexture.getValue()->determineTextureTarget(pWindow); } switch(target) { case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: side = 0; break; case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: side = 1; break; case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: side = 2; break; case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: side = 3; break; case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: side = 4; break; case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: side = 5; break; } // select GL_COLORATTACHMENTn and read data into image glReadBuffer(index); glReadPixels(0, 0, pTexImg->getWidth (), pTexImg->getHeight (), pTexImg->getPixelFormat(), pTexImg->getDataType (), pTexImg->editData (mipMapLevel, frame, side)); glReadBuffer(GL_NONE); } }