bool GLES2Video::BeginTargetScene(const Color& dwBGColor, const bool clear) { // explicit static cast for better performance TexturePtr texturePtr = m_currentTarget.lock(); if (texturePtr) { Texture *pTexture = texturePtr.get(); // safety compile-time error checking GLES2Texture *pGLES2Texture = static_cast<GLES2Texture*>(pTexture); // safer direct cast const GLuint target = pGLES2Texture->GetFrameBufferID(); glBindFramebuffer(GL_FRAMEBUFFER, target); CheckFrameBufferStatus(m_logger, target, pGLES2Texture->GetTextureID(), false); if (clear) { Vector4 color; color.SetColor(dwBGColor); glClearColor(color.x, color.y, color.z, color.w); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); } const Texture::PROFILE& profile = pGLES2Texture->GetProfile(); Enable2D(static_cast<int>(profile.width), static_cast<int>(profile.height), true); m_shaderContext->ResetViewConstants(m_orthoMatrix, GetCurrentTargetSize()); } else { Message(GS_L("There's no render target"), GSMT_ERROR); } m_rendering = true; return true; }
void Material::bindShaderData() { m_gpuProgram->bind(); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialAmbient, m_ambient); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialDiffuse, m_diffuse); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialSpecular, m_specular); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialShininess, m_shininess); // pack the parallax scale and bias in a single 2d vector Vec2f scaleBias(m_parallaxScale, m_parallaxBias); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialParallaxScaleBias, scaleBias); if (m_transparent) { m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialOpacity, m_opacity); } else { float opacity = 1.0f; m_gpuProgram->setUniform(ShaderConstants::UNIFORM_MaterialOpacity, opacity); } uint numTextures = this->getActiveTextures(); for (uint i = 0; i < numTextures; i++) { TexturePtr tex = m_texStack->textures[i]; // std::cout << "binding texture " << tex->m_filename << " to unit " << (int)i << "\n"; glActiveTexture(GL_TEXTURE0 + i); glClientActiveTexture(GL_TEXTURE0 + i); tex->bind(); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_Samplers[i], i); m_gpuProgram->setUniform(ShaderConstants::UNIFORM_TexEnvColors[i], tex->getEnvColour()); } m_gpuProgram->setUniform(ShaderConstants::UNIFORM_NumTextures, numTextures); }
bool SurveyMapTextureCreator::init() { TexturePtr texture = TextureManager::getSingleton().createManual(getTextureName(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 2048, 2048, TU_RENDERTARGET, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); if ( texture.isNull() ) return false;; mRttTex = texture->getBuffer()->getRenderTarget(); if ( !mRttTex ) return false; mRttTex->setAutoUpdated(false); mCamera = gEnv->sceneManager->createCamera(getCameraName()); mViewport = mRttTex->addViewport(mCamera); mViewport->setBackgroundColour(ColourValue::Black); mViewport->setOverlaysEnabled(false); mViewport->setShadowsEnabled(false); mViewport->setSkiesEnabled(false); mMaterial = MaterialManager::getSingleton().create(getMaterialName(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if ( mMaterial.isNull() ) return false; mTextureUnitState = mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(getTextureName()); mRttTex->addListener(this); mCamera->setFixedYawAxis(false); mCamera->setProjectionType(PT_ORTHOGRAPHIC); mCamera->setNearClipDistance(1.0f); return true; }
TexturePtr NullHWBufferManager::LoadTexture(const String & filename, float priority, int mipmaps, eUsage usage) { Hash2 hash(filename.c_str()); TexturePtr p = _find(hash, filename); if (p == NULL) { NullTexture * pTexture = new NullTexture(filename, filename); pTexture->mWidth = 0; pTexture->mHeight = 0; pTexture->mMipmaps = 1; pTexture->mUsage = usage; pTexture->mFormat = ePixelFormat::UNKNOWN; pTexture->mPriority = priority; p = pTexture; mTextureMap.Insert(hash, p.c_ptr()); } if (priority < 0) { p->EnsureLoad(); } else { p->Load(); } return p; }
void SSGILayer::GBuffer(TexturePtr const & rt0_tex, TexturePtr const & rt1_tex, TexturePtr const & depth_tex) { RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderEngine& re = rf.RenderEngineInstance(); RenderDeviceCaps const & caps = re.DeviceCaps(); g_buffer_texs_[0] = rt0_tex; g_buffer_texs_[1] = rt1_tex; g_buffer_depth_tex_ = depth_tex; uint32_t const width = rt0_tex->Width(0); uint32_t const height = rt0_tex->Height(0); ElementFormat fmt; if (caps.rendertarget_format_support(EF_B10G11R11F, 1, 0)) { fmt = EF_B10G11R11F; } else { BOOST_ASSERT(caps.rendertarget_format_support(EF_ABGR16F, 1, 0)); fmt = EF_ABGR16F; } small_ssgi_tex_ = rf.MakeTexture2D(width / 4, height / 4, 1, 1, fmt, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); indirect_lighting_tex_ = rf.MakeTexture2D(width / 2, height / 2, 1, 1, EF_ABGR16F, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); }
void SDSMCascadedShadowLayer::DepthTexture(TexturePtr const & depth_tex) { depth_tex_ = depth_tex; if (!cs_support_) { RenderFactory& rf = Context::Instance().RenderFactoryInstance(); uint32_t const width = depth_tex->Width(0); uint32_t const height = depth_tex->Height(0); depth_deriative_tex_ = rf.MakeTexture2D(width / 2, height / 2, 0, 1, EF_GR16F, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); depth_deriative_small_tex_ = rf.MakeTexture2D(width / 4, height / 4, 0, 1, EF_GR16F, 1, 0, EAH_GPU_Write, nullptr); float delta_x = 1.0f / depth_tex_->Width(0); float delta_y = 1.0f / depth_tex_->Height(0); reduce_z_bounds_from_depth_pp_->SetParam(0, float4(delta_x, delta_y, -delta_x / 2, -delta_y / 2)); reduce_z_bounds_from_depth_pp_->InputPin(0, depth_tex_); reduce_z_bounds_from_depth_pp_->OutputPin(0, depth_deriative_tex_); reduce_z_bounds_from_depth_mip_map_pp_->InputPin(0, depth_deriative_tex_); compute_log_cascades_from_z_bounds_pp_->SetParam(0, static_cast<float>(depth_deriative_tex_->NumMipMaps() - 1)); compute_log_cascades_from_z_bounds_pp_->InputPin(0, depth_deriative_tex_); compute_log_cascades_from_z_bounds_pp_->OutputPin(0, interval_tex_); } }
TexturePtr RandomTools::generateRandomVelocityTexture() { // PPP: Temp workaround for DX 11 which does not seem to like usage dynamic // TextureUsage usage = (Root::getSingletonPtr()->getRenderSystem()->getName()=="Direct3D11 Rendering Subsystem") ? // TU_DEFAULT : TU_DYNAMIC; TexturePtr texPtr = TextureManager::getSingleton().createManual( "RandomVelocityTexture", // ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "General", TEX_TYPE_1D, 1024, 1, 1, 0, PF_FLOAT32_RGBA);//, //usage); HardwarePixelBufferSharedPtr pixelBuf = texPtr->getBuffer(); // Lock the buffer so we can write to it. pixelBuf->lock(HardwareBuffer::HBL_DISCARD); const PixelBox &pb = pixelBuf->getCurrentLock(); float *randomData = static_cast<float*>(pb.data); // float randomData[NUM_RAND_VALUES * 4]; for(int i = 0; i < NUM_RAND_VALUES * 4; i++) { randomData[i] = float( (rand() % 10000) - 5000 ); } // PixelBox pixelBox(1024, 1, 1, PF_FLOAT32_RGBA, &randomData[0]); // pixelBuf->blitFromMemory(pixelBox); pixelBuf->unlock(); return texPtr; }
HeatHaze::HeatHaze(SceneManager *sceneMgr, RenderWindow *mWindow, Ogre::Camera *cam) : mSceneMgr(sceneMgr), rttTex(0), listener(0) { TexturePtr rttTexPtr = TextureManager::getSingleton().createManual("heathaze_rtt", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, cam->getViewport()->getWidth(), cam->getViewport()->getHeight(), 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); rttTex = rttTexPtr->getBuffer()->getRenderTarget(); { /* // we use the main camera now mHazeCam = mSceneMgr->createCamera("Hazecam"); mHazeCam->setNearClipDistance(1.0); mHazeCam->setFarClipDistance(1000.0); mHazeCam->setPosition(Vector3(0, 0, 0)); */ //mHazeCam->setAspectRatio(2.0); // setup viewport Viewport *v = rttTex->addViewport(cam); //v->setClearEveryFrame(true); //v->setBackgroundColour(ColourValue::Black); v->setOverlaysEnabled(false); // setup projected material MaterialPtr mat = MaterialManager::getSingleton().getByName("tracks/HeatHazeMat"); tex = mat->getTechnique(0)->getPass(0)->getTextureUnitState(1); tex->setTextureName("heathaze_rtt"); tex->setProjectiveTexturing(true, cam); listener = new HeatHazeListener(mSceneMgr); rttTex->addListener(listener); rttTex->setAutoUpdated(false); } }
// ----------------------------------------------------------------------------------------- void CDemoGlassApplication::createScene() { m_pSceneManager->createSkyBox(_T("snow.jpg"), 500); CPepeEngineEntity* pVase = new CPepeEngineEntity(_T("Vase"), _T("Teapot.3ds")); CPepeEngineSceneNode* pRootNode = m_pSceneManager->getRootSceneNode(); pRootNode->attachObject(pVase); pRootNode->setPosition(0.0f, 0.0f, -15.0f); pRootNode->setScale(0.1f, 0.1f, 0.1f); pVase->setVertexShader(_T("glass.vs")); pVase->setPixelShader(_T("glass.ps")); pVase->setCullingMode(CULL_CLOCKWISE); GPUProgramPtr pVasePS = IPepeEngineGPUProgramManager::getSingleton().getByName(_T("glass.ps")); TexturePtr pRainbowTexture = IPepeEngineTextureManager::getSingleton().create(_T("Rainbow.tga")); pRainbowTexture->load(); pVasePS->getParameters()->bindTexture(_T("Rainbow"), pRainbowTexture); pVasePS->getParameters()->setNamedConstant(_T("indexOfRefractionRatio"), 1.14f); pVasePS->getParameters()->setNamedConstant(_T("rainbowSpread"), 0.18f); pVasePS->getParameters()->setNamedConstant(_T("rainbowScale"), 0.2f); pVasePS->getParameters()->setNamedConstant(_T("reflectionScale"), 1.0f); pVasePS->getParameters()->setNamedConstant(_T("refractionScale"), 1.0f); pVasePS->getParameters()->setNamedConstant(_T("ambient"), 0.2f); pVasePS->getParameters()->setNamedConstant(_T("baseColor"), CPepeEngineVector4(0.78f, 0.78f, 0.78f, 1.0f)); }
void D3D9VideoBufferManager::BitBlt(TexturePtr texDest, ImagePtr imageSrc, const Rect * pDest, const Rect * pSrc) { IDirect3DTexture9 * pD3DDestTexture = NULL; IDirect3DTexture9 * pD3DSrcTexture = NULL; if (texDest->GetTextureType() == TEXTYPE_2D) { pD3DDestTexture = static_cast<D3D9Texture*>(texDest.c_ptr())->mD3D9Texture; } D3D9Image * img = (D3D9Image*)imageSrc.c_ptr(); pD3DSrcTexture = img->_MyTexture(); assert(pD3DDestTexture && pD3DSrcTexture); IDirect3DSurface9 * pDestSurface; IDirect3DSurface9 * pSrcSurface; const RECT * pDestRect = reinterpret_cast<const RECT *>(pDest); const RECT * pSrcRect = reinterpret_cast<const RECT *>(pSrc); pD3DDestTexture->GetSurfaceLevel(0, &pDestSurface); pD3DSrcTexture->GetSurfaceLevel(0, &pSrcSurface); D3DXLoadSurfaceFromSurface(pDestSurface, NULL, pDestRect, pSrcSurface, NULL, pSrcRect, D3DX_DEFAULT, 0); }
CPixelBufferView::TexturePtr CPixelBufferView::CreateTextureFromBitmap(const Framework::CBitmap& bitmap) { TexturePtr texture; if(!bitmap.IsEmpty()) { HRESULT result = S_OK; result = m_device->CreateTexture(bitmap.GetWidth(), bitmap.GetHeight(), 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, nullptr); assert(SUCCEEDED(result)); D3DLOCKED_RECT lockedRect = {}; result = texture->LockRect(0, &lockedRect, nullptr, 0); assert(SUCCEEDED(result)); uint32* dstPtr = reinterpret_cast<uint32*>(lockedRect.pBits); uint32* srcPtr = reinterpret_cast<uint32*>(bitmap.GetPixels()); for(unsigned int y = 0; y < bitmap.GetHeight(); y++) { memcpy(dstPtr, srcPtr, bitmap.GetWidth() * sizeof(uint32)); dstPtr += lockedRect.Pitch / sizeof(uint32); srcPtr += bitmap.GetPitch() / sizeof(uint32); } result = texture->UnlockRect(0); assert(SUCCEEDED(result)); } return texture; }
RenderTargetPtr D3D9VideoBufferManager::CreateRenderTarget(TexturePtr rtTex) { int rWidth = rtTex->GetWidth(), rHeight = rtTex->GetHeight(); if (rWidth == -1 || rHeight == -1) { rWidth = Engine::Instance()->GetDeviceProperty()->Width; rHeight = Engine::Instance()->GetDeviceProperty()->Height; } IDirect3DSurface9 * pD3D9RenderTarget = NULL; D3D9RenderTarget * pTexture = new D3D9RenderTarget(mD3D9Device); pTexture->mName = rtTex->GetName(); pTexture->mWidth = rWidth; pTexture->mHeight = rHeight; pTexture->mFormat = rtTex->GetFormat(); pTexture->mMSAA = MSAA_NONE; pTexture->mTexture = rtTex; D3D9Texture * d3dTex = (D3D9Texture *)rtTex.c_ptr(); d3dTex->GetD3DTexture()->GetSurfaceLevel(0, &pTexture->mRenderTarget); mRenderTargets.Insert(pTexture->GetName(), pTexture); return RenderTargetPtr(pTexture); }
NxScreen * NxScreenManager::CreateExternalWindow( int MonitorID, bool FullScreen, unsigned int Width, unsigned int Height ) { //Viewport * mainviewport = NxEngine::getSingleton().GetNxViewport(); //Log("Enabling Output Compositor..."); //Ogre::CompositorManager::getSingleton().setCompositorEnabled( mainviewport , "NxCompositorOutput" , true ); //Log("Enabling Output Compositor:Done"); static bool Initialized = false; if( !Initialized ) { TexturePtr tester = TextureManager::getSingleton().createManual( "RTT_Texture_100", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 32, 32, 0, Ogre::PF_BYTE_BGR, TU_RENDERTARGET ); mRenderTexture = tester->getBuffer(0,0)->getRenderTarget(); mRenderTexture->setAutoUpdated( false ); //Ogre::Viewport * NxViewport = mRenderTexture->addViewport( NxEngine::getSingleton().GetNxCamera() ); // view from main scene Ogre::Viewport * NxViewport = mRenderTexture->addViewport( NxEngine::getSingleton().GetNxWindow()->GetViewport(0)->GetViewport()->getCamera( ) ); Initialized = true; } NxScreen * Output = new NxScreen( MonitorID, FullScreen, Width, Height ); MonitorListActive.push_back( Output ); return Output ; }
Dashboard::Dashboard() : mDashCam(0) , mDashboardListener(0) , rttTex(0) { TexturePtr rttTexPtr = TextureManager::getSingleton().createManual("dashtexture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 1024, 512, 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); rttTex = rttTexPtr->getBuffer()->getRenderTarget(); mDashCam = gEnv->sceneManager->createCamera("DashCam"); mDashCam->setNearClipDistance(1.0); mDashCam->setFarClipDistance(10.0); mDashCam->setPosition(Vector3(0.0, -10000.0, 0.0)); mDashCam->setAspectRatio(2.0); Viewport *v = rttTex->addViewport(mDashCam); v->setClearEveryFrame(true); v->setBackgroundColour(ColourValue::Black); //v->setOverlaysEnabled(false); MaterialPtr mat = MaterialManager::getSingleton().getByName("renderdash"); mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("dashtexture"); mDashboardListener = new DashboardListener(); rttTex->addListener(mDashboardListener); mDashboardListener->dashOverlay = OverlayManager::getSingleton().getByName("tracks/3D_DashboardOverlay"); mDashboardListener->needlesOverlay = OverlayManager::getSingleton().getByName("tracks/3D_NeedlesOverlay"); mDashboardListener->blendOverlay = OverlayManager::getSingleton().getByName("tracks/3D_BlendOverlay"); mDashboardListener->truckHUDOverlay = OverlayManager::getSingleton().getByName("tracks/TruckInfoBox"); // mDashboardListener->dbdebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); // mDashboardListener->dbeditorOverlay = OverlayManager::getSingleton().getByName("tracks/EditorOverlay"); }
void TextureToolWindow::saveTexture(String texName, bool usePNG) { try { TexturePtr tex = TextureManager::getSingleton().getByName(texName); if (tex.isNull()) return; Image img; tex->convertToImage(img); // Save to disk! String outname = std::string(App::sys_user_dir.GetActive()) + RoR::PATH_SLASH + texName; if (usePNG) outname += ".png"; img.save(outname); UTFString msg = _L("saved texture as ") + outname; RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, msg, "information.png"); } catch (Exception& e) { UTFString str = "Exception while saving image: " + e.getFullDescription(); RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, str, "error.png"); } }
TexturePtr LightView::generateLightBubble(float centerFactor) { int bubbleRadius = 256; int centerRadius = bubbleRadius * centerFactor; int bubbleDiameter = bubbleRadius * 2; ImagePtr lightImage = ImagePtr(new Image(Size(bubbleDiameter, bubbleDiameter))); for(int x = 0; x < bubbleDiameter; x++) { for(int y = 0; y < bubbleDiameter; y++) { float radius = std::sqrt((bubbleRadius - x)*(bubbleRadius - x) + (bubbleRadius - y)*(bubbleRadius - y)); float intensity = stdext::clamp<float>((bubbleRadius - radius) / (float)(bubbleRadius - centerRadius), 0.0f, 1.0f); // light intensity varies inversely with the square of the distance intensity = intensity * intensity; uint8_t colorByte = intensity * 0xff; uint8_t pixel[4] = {colorByte,colorByte,colorByte,0xff}; lightImage->setPixel(x, y, pixel); } } TexturePtr tex = TexturePtr(new Texture(lightImage, true)); tex->setSmooth(true); return tex; }
Error operator()(CommandBufferImpl* cmdb) { ANKI_ASSERT(cmdb); m_tex.get().create(m_init); GlObject::State oldState = m_tex.get().setStateAtomically( GlObject::State::CREATED); ANKI_ASSERT(oldState == GlObject::State::TO_BE_CREATED); (void)oldState; if(m_cleanup) { for(U layer = 0; layer < MAX_TEXTURE_LAYERS; ++layer) { for(U level = 0; level < MAX_MIPMAPS; ++level) { SurfaceData& surf = m_init.m_data[level][layer]; if(surf.m_ptr) { cmdb->getInternalAllocator().deallocate( const_cast<void*>(surf.m_ptr), 1); } } } } return ErrorCode::NONE; }
void SurveyMapEntity::updateIcon() { // check if static only icon String imageFile = "icon_" + mType + "_" + entityStates[mState] + ".dds"; if (mIsStatic) { imageFile = "icon_" + mType + ".dds"; } // set image texture to load it into memory, so TextureManager::getByName will have it loaded if files exist mIcon->setImageTexture(imageFile); TexturePtr texture = (TexturePtr)(TextureManager::getSingleton().getByName(imageFile)); if (texture.isNull()) { imageFile = "icon_missing.dds"; texture = (TexturePtr)(TextureManager::getSingleton().getByName(imageFile)); } if (!texture.isNull()) { mIconSize.width = (int)texture->getWidth(); mIconSize.height = (int)texture->getHeight(); mIcon->setSize(mIconSize); } if (mIconRotating) { mIconRotating->setCenter(MyGUI::IntPoint(mIcon->getWidth()/2, mIcon->getHeight()/2)); mIconRotating->setAngle(mRotation); } }
void WaterRTT::create() { if (!mSceneMgr) return; mCamera = mSceneMgr->createCamera("PlaneReflectionRefraction"); if (mViewerCamera) { mCamera->setFarClipDistance(mViewerCamera->getFarClipDistance()); mCamera->setNearClipDistance(mViewerCamera->getNearClipDistance()); mCamera->setAspectRatio(mViewerCamera->getAspectRatio()); } for (unsigned int i = 0; i < 2; ++i) { if (i==0 && !mReflect) continue; if (i==1 && !mRefract) continue; TexturePtr tex = TextureManager::getSingleton().createManual(i == 0 ? "PlaneReflection" : "PlaneRefraction", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, mRTTSize, mRTTSize, 0, PF_R8G8B8, TU_RENDERTARGET); RenderTarget* rtt = tex->getBuffer()->getRenderTarget(); Viewport* vp = rtt->addViewport(mCamera); vp->setOverlaysEnabled(false); vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f)); vp->setShadowsEnabled(false); vp->setMaterialScheme ("reflection"); vp->setVisibilityMask( i == 0 ? RV_WaterReflect : RV_WaterRefract); rtt->addListener(this); if (i == 0) mReflectionTarget = rtt; else mRefractionTarget = rtt; } sh::Factory::getInstance ().setTextureAlias ("WaterReflection", "PlaneReflection"); sh::Factory::getInstance ().setTextureAlias ("WaterRefraction", "PlaneRefraction"); }
bool GLVideo::BeginTargetScene(const Color& dwBGColor, const bool clear) { // explicit static cast for better performance TexturePtr texturePtr = m_currentTarget.lock(); if (!texturePtr) { Message(GS_L("There's no render target"), GSMT_ERROR); } Texture *pTexture = texturePtr.get(); // safety compile-time error checking GLTexture *pGLTexture = static_cast<GLTexture*>(pTexture); // safer direct cast const GLuint target = pGLTexture->GetTextureInfo().m_frameBuffer; glBindFramebuffer(GL_FRAMEBUFFER, target); CheckFrameBufferStatus(target, pGLTexture->GetTextureInfo().m_texture, false); if (clear) { math::Vector4 color; color.SetColor(dwBGColor); glClearColor(color.x, color.y, color.z, color.w); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } UpdateInternalShadersViewData(GetScreenSizeF(), true); m_rendering = true; return true; }
bool Filter::unlinkFrom(std::shared_ptr<BaseObject> obj) { if (dynamic_pointer_cast<Texture>(obj).get() != nullptr) { if (_inTexture.expired()) return false; auto inTex = _inTexture.lock(); TexturePtr tex = dynamic_pointer_cast<Texture>(obj); _screen->removeTexture(tex); if (tex->getName() == inTex->getName()) _inTexture.reset(); return true; } else if (dynamic_pointer_cast<Image>(obj).get() != nullptr) { auto textureName = getName() + "_" + obj->getName() + "_tex"; auto tex = _root.lock()->unregisterObject(textureName); if (!tex) return false; tex->unlinkFrom(obj); return unlinkFrom(tex); } return Texture::unlinkFrom(obj); }
//--------------------------------------------------------------------- TexturePtr ShadowTextureManager::getNullShadowTexture(PixelFormat format) { for (ShadowTextureList::iterator t = mNullTextureList.begin(); t != mNullTextureList.end(); ++t) { const TexturePtr& tex = *t; if (format == tex->getFormat()) { // Ok, a match return tex; } } // not found, create a new one // A 1x1 texture of the correct format, not a render target static const String baseName = "Ogre/ShadowTextureNull"; String targName = baseName + StringConverter::toString(mCount++); TexturePtr shadowTex = TextureManager::getSingleton().createManual( targName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 1, 1, 0, format, TU_STATIC_WRITE_ONLY); mNullTextureList.push_back(shadowTex); // lock & populate the texture based on format shadowTex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD); const PixelBox& box = shadowTex->getBuffer()->getCurrentLock(); // set high-values across all bytes of the format PixelUtil::packColour( 1.0f, 1.0f, 1.0f, 1.0f, format, box.data ); shadowTex->getBuffer()->unlock(); return shadowTex; }
void ForwardRenderer::DrawScreenQuad() { float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; XMMATRIX view = XMLoadFloat4x4( RendererCore::Instance()->GetView() ); XMMATRIX proj = XMLoadFloat4x4( RendererCore::Instance()->GetProj() ); int iCount = m_vDrawScreenElements.size(); for ( int i = 0; i < iCount; ++i ) { DrawElement* pElem = m_vDrawScreenElements[i]; if ( !pElem ) continue; UINT stride = pElem->stride; UINT offset = pElem->offset; ID3D11Buffer* pVB = pElem->m_spVB->GetVB(); GetD3D11DeviceImmContext()->IASetInputLayout( pElem->m_pInputLayout ); GetD3D11DeviceImmContext()->IASetPrimitiveTopology( pElem->ePrimitiveTopology ); GetD3D11DeviceImmContext()->IASetVertexBuffers( 0, 1, &pVB, &stride, &offset ); GetD3D11DeviceImmContext()->IASetIndexBuffer( pElem->m_spIB->GetIB(), DXGI_FORMAT_R32_UINT, 0 ); if ( pElem->m_pRasterS ) GetD3D11DeviceImmContext()->RSSetState( pElem->m_pRasterS ); if ( pElem->m_pBlendS ) GetD3D11DeviceImmContext()->OMSetBlendState( pElem->m_pBlendS, blendFactor, 0xffffffff ); if ( pElem->m_pDepthStencilS ) GetD3D11DeviceImmContext()->OMSetDepthStencilState( pElem->m_pDepthStencilS, pElem->m_uiStencilRef ); for ( auto itor = pElem->m_vecSubElement.begin(); itor != pElem->m_vecSubElement.end(); ++itor ) { ID3DX11EffectTechnique* pTech = pElem->m_spShader->GetTech( (*itor).m_iTechIndex ); if ( !pTech ) continue; D3DX11_TECHNIQUE_DESC techDesc; pTech->GetDesc( &techDesc ); TexturePtr spDiffuseMap = (*itor).m_spDiffuseMap; for ( UINT p = 0; p < techDesc.Passes; ++p ) { XMMATRIX worldViewProj = XMLoadFloat4x4( &(*itor).m_World ); pElem->m_spShader->SetWorldViewProj( worldViewProj ); pElem->m_spShader->SetDiffuseMap( spDiffuseMap->GetSRV() ); pTech->GetPassByIndex( p )->Apply( 0, GetD3D11DeviceImmContext() ); GetD3D11DeviceImmContext()->DrawIndexed( 6, 0, 0 ); } } } }
Error operator()(GlState&) { TextureImpl::copy(m_src->getImplementation(), m_srcSurf, m_dest->getImplementation(), m_destSurf); return ErrorCode::NONE; }
TexturePtr ResourceStorage::getTexture(const std::wstring& path) { TexturePtr texture = getResource<Texture>(path); if (texture.isNull()) { texture = loadTexture(path); } return texture; }
bool gkOgreCompositorHelper::createHalftoneTexture() { using namespace Ogre; try { if (TextureManager::getSingleton().resourceExists(COMP_HALFTONE_TEX_NAME)) return true; //already created TexturePtr tex = TextureManager::getSingleton().createManual( COMP_HALFTONE_TEX_NAME, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_3D, 64,64,64, 0, PF_A8 ); HardwarePixelBufferSharedPtr ptr = tex->getBuffer(0,0); ptr->lock(HardwareBuffer::HBL_DISCARD); const PixelBox &pb = ptr->getCurrentLock(); uint8 *data = static_cast<uint8*>(pb.data); size_t height = pb.getHeight(); size_t width = pb.getWidth(); size_t depth = pb.getDepth(); size_t rowPitch = pb.rowPitch; size_t slicePitch = pb.slicePitch; for (size_t z = 0; z < depth; ++z) { for (size_t y = 0; y < height; ++y) { for(size_t x = 0; x < width; ++x) { float fx = 32-(float)x+0.5f; float fy = 32-(float)y+0.5f; float fz = 32-((float)z)/3+0.5f; float distanceSquare = fx*fx+fy*fy+fz*fz; data[slicePitch*z + rowPitch*y + x] = 0x00; if (distanceSquare < 1024.0f) data[slicePitch*z + rowPitch*y + x] += 0xFF; } } } ptr->unlock(); } catch (Exception &e) { gkPrintf("[CMP] FAILED - Halftone Texture Creation. %s", e.getFullDescription().c_str()); return false; } return true; }
void WebView::createMaterial() { if(opacity > 1) opacity = 1; else if(opacity < 0) opacity = 0; if(!Bitwise::isPO2(viewWidth) || !Bitwise::isPO2(viewHeight)) { if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_NON_POWER_OF_2_TEXTURES)) { if(Root::getSingleton().getRenderSystem()->getCapabilities()->getNonPOW2TexturesLimited()) compensateNPOT = true; } else compensateNPOT = true; #ifdef __APPLE__ //cus those fools always report #t when I ask if they support this or that //and then fall back to their buggy and terrible software driver which has never once in my life rendered a single correct frame. compensateNPOT=true; #endif if(compensateNPOT) { texWidth = Bitwise::firstPO2From(viewWidth); texHeight = Bitwise::firstPO2From(viewHeight); } } // Create the texture #if defined(HAVE_AWESOMIUM) || !defined(__APPLE__) TexturePtr texture = TextureManager::getSingleton().createManual( viewName + "Texture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, texWidth, texHeight, 0, PF_BYTE_BGRA, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE, this); HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(); pixelBuffer->lock(HardwareBuffer::HBL_DISCARD); const PixelBox& pixelBox = pixelBuffer->getCurrentLock(); texDepth = Ogre::PixelUtil::getNumElemBytes(pixelBox.format); texPitch = (pixelBox.rowPitch*texDepth); uint8* pDest = static_cast<uint8*>(pixelBox.data); memset(pDest, 128, texHeight*texPitch); pixelBuffer->unlock(); #endif MaterialPtr material = MaterialManager::getSingleton().create(viewName + "Material", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); matPass = material->getTechnique(0)->getPass(0); matPass->setSceneBlending(SBT_TRANSPARENT_ALPHA); matPass->setDepthWriteEnabled(false); baseTexUnit = matPass->createTextureUnitState(viewName + "Texture"); baseTexUnit->setTextureFiltering(texFiltering, texFiltering, FO_NONE); if(texFiltering == FO_ANISOTROPIC) baseTexUnit->setTextureAnisotropy(4); }
//----------------------------------------------------------------------- TexturePtr TextureManager::load(const String &name, const String& group, TextureType texType, int numMipmaps, Real gamma, bool isAlpha, PixelFormat desiredFormat, bool hwGamma) { ResourceCreateOrRetrieveResult res = createOrRetrieve(name,group,false,0,0,texType,numMipmaps,gamma,isAlpha,desiredFormat,hwGamma); TexturePtr tex = res.first; tex->load(); return tex; }
GlTexture getGlTexture(const TexturePtr& outputTexture) { GlTexture glTexture; glTexture.width = outputTexture->getWidth(); glTexture.height = outputTexture->getHeight(); glTexture.depth = outputTexture->getDepth(); glTexture.target = toGlTargetType(outputTexture->getType()); glTexture.textureId = outputTexture->_getGlTextureId(); return glTexture; }
//----------------------------------------------------------------------- std::pair< size_t, size_t > TextureUnitState::getTextureDimensions( unsigned int frame ) const { TexturePtr tex = _getTexturePtr(frame); if (tex.isNull()) OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find texture " + mFrames[ frame ], "TextureUnitState::getTextureDimensions" ); return std::pair< size_t, size_t >( tex->getWidth(), tex->getHeight() ); }