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; }
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; }
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 CompositorManager::isInputToOutputTarget(CompositorInstance* inst, TexturePtr tex) { CompositionTargetPass* tp = inst->getTechnique()->getOutputTargetPass(); CompositionTargetPass::PassIterator pit = tp->getPassIterator(); while(pit.hasMoreElements()) { CompositionPass* p = pit.getNext(); for (size_t i = 0; i < p->getNumInputs(); ++i) { TexturePtr t = inst->getTextureInstance(p->getInput(i).name, 0); if (!t.isNull() && t.get() == tex.get()) return true; } } return false; }
//--------------------------------------------------------------------- bool CompositorManager::isInputPreviousTarget(CompositorInstance* inst, TexturePtr tex) { CompositionTechnique::TargetPassIterator tpit = inst->getTechnique()->getTargetPassIterator(); while(tpit.hasMoreElements()) { CompositionTargetPass* tp = tpit.getNext(); if (tp->getInputMode() == CompositionTargetPass::IM_PREVIOUS) { // Don't have to worry about an MRT, because no MRT can be input previous TexturePtr t = inst->getTextureInstance(tp->getOutputName(), 0); if (!t.isNull() && t.get() == tex.get()) return true; } } return false; }
void D3D11EffectMaterial::SetTextureBySemantic(const char* szName, TexturePtr pTex) { ID3D11ShaderResourceView* pView = NULL; pView = ((D3D11Texture*)pTex.get())->GetShaderResourceView(); ID3DX11EffectVariable* pVal = m_pEffect->GetVariableBySemantic(szName); if(pVal) { pVal->AsShaderResource()->SetResource(pView); } }
void UINode::renderImage (const TexturePtr& texture, int x, int y, int w, int h, float alpha) const { if (!texture || !texture->isValid()) return; if (w == -1) w = texture->getWidth(); if (h == -1) h = texture->getHeight(); _frontend->renderImage(texture.get(), x, y, w, h, 0, alpha); }
Error operator()(CommandBufferImpl* cmd) { TextureImpl& tex = m_tex.get(); BufferImpl& buff = m_buff.get(); // Bind GLuint copyFbo = cmd->getManager().getImplementation(). getRenderingThread().getCopyFbo(); glBindFramebuffer(GL_FRAMEBUFFER, copyFbo); // Attach texture glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.getTarget(), tex.getGlName(), 0); // Set draw buffers GLuint drawBuff = GL_COLOR_ATTACHMENT0; glDrawBuffers(1, &drawBuff); // Bind buffer ANKI_ASSERT(m_buff.getTarget() == GL_PIXEL_PACK_BUFFER); buff.bind(); // Read pixels GLuint format = GL_NONE, type = GL_NONE; if(tex.getInternalFormat() == GL_RG32UI) { format = GL_RG_INTEGER; type = GL_UNSIGNED_INT; } else if(tex.getInternalFormat() == GL_RG32F) { format = GL_RG; type = GL_FLOAT; } else { ANKI_ASSERT(0 && "Not implemented"); } glReadPixels(0, 0, tex.getWidth(), tex.getHeight(), format, type, nullptr); // End buff.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); return ErrorCode::NONE; }
void OutdoorEnv::setSkyBoxTexture(const String& matname) { if (m_skyBoxMatName == matname) return; m_skyBoxMatName = matname; { MaterialPtr skymat = m_skybox12->getMaterial(); if (!skymat) { skymat = UniqueAsset_<Material>("_skybox"); } TexturePtr tex = FindAsset_<Texture>(matname + "_12"); AX_ASSERT(tex); skymat->setTexture(SamplerType::Diffuse, tex.get()); m_skybox12->setMaterial(skymat.get()); } { MaterialPtr skymat = m_skybox34->getMaterial(); if (!skymat) { skymat = UniqueAsset_<Material>("_skybox"); } TexturePtr tex = FindAsset_<Texture>(matname + "_34"); AX_ASSERT(tex); skymat->setTexture(SamplerType::Diffuse, tex); m_skybox34->setMaterial(skymat); } { MaterialPtr skymat = m_skybox5->getMaterial(); if (!skymat) { skymat = UniqueAsset_<Material>("_skybox"); } TexturePtr tex = FindAsset_<Texture>(matname + "_5"); AX_ASSERT(tex); skymat->setTexture(SamplerType::Diffuse, tex); m_skybox5->setMaterial(skymat); } }
//--------------------------------------------------------------------- TexturePtr CompositorManager::getPooledTexture(const String& name, const String& localName, size_t w, size_t h, PixelFormat f, uint aa, const String& aaHint, bool srgb, CompositorManager::UniqueTextureSet& texturesAssigned, CompositorInstance* inst, CompositionTechnique::TextureScope scope) { if (scope == CompositionTechnique::TS_GLOBAL) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Global scope texture can not be pooled.", "CompositorManager::getPooledTexture"); } TextureDef def(w, h, f, aa, aaHint, srgb); if (scope == CompositionTechnique::TS_CHAIN) { StringPair pair = std::make_pair(inst->getCompositor()->getName(), localName); TextureDefMap& defMap = mChainTexturesByDef[pair]; TextureDefMap::iterator it = defMap.find(def); if (it != defMap.end()) { return it->second; } // ok, we need to create a new one TexturePtr newTex = TextureManager::getSingleton().createManual( name, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (uint)w, (uint)h, 0, f, TU_RENDERTARGET, 0, srgb, aa, aaHint); defMap.insert(TextureDefMap::value_type(def, newTex)); return newTex; } TexturesByDef::iterator i = mTexturesByDef.find(def); if (i == mTexturesByDef.end()) { TextureList* texList = OGRE_NEW_T(TextureList, MEMCATEGORY_GENERAL); i = mTexturesByDef.insert(TexturesByDef::value_type(def, texList)).first; } CompositorInstance* previous = inst->getChain()->getPreviousInstance(inst); CompositorInstance* next = inst->getChain()->getNextInstance(inst); TexturePtr ret; TextureList* texList = i->second; // iterate over the existing textures and check if we can re-use for (TextureList::iterator t = texList->begin(); t != texList->end(); ++t) { TexturePtr& tex = *t; // check not already used if (texturesAssigned.find(tex.get()) == texturesAssigned.end()) { bool allowReuse = true; // ok, we didn't use this one already // however, there is an edge case where if we re-use a texture // which has an 'input previous' pass, and it is chained from another // compositor, we can end up trying to use the same texture for both // so, never allow a texture with an input previous pass to be // shared with its immediate predecessor in the chain if (isInputPreviousTarget(inst, localName)) { // Check whether this is also an input to the output target of previous // can't use CompositorInstance::mPreviousInstance, only set up // during compile if (previous && isInputToOutputTarget(previous, tex)) allowReuse = false; } // now check the other way around since we don't know what order they're bound in if (isInputToOutputTarget(inst, localName)) { if (next && isInputPreviousTarget(next, tex)) allowReuse = false; } if (allowReuse) { ret = tex; break; } } } if (ret.isNull()) { // ok, we need to create a new one ret = TextureManager::getSingleton().createManual( name, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (uint)w, (uint)h, 0, f, TU_RENDERTARGET, 0, srgb, aa, aaHint); texList->push_back(ret); } // record that we used this one in the requester's list texturesAssigned.insert(ret.get()); return ret; }
Error operator()(CommandBufferImpl*) { m_tex.get().generateMipmaps(); return ErrorCode::NONE; }
Error operator()(CommandBufferImpl*) { m_tex.get().bind(m_unit); return ErrorCode::NONE; }
void UGraphicsDevice::SetPSTexture(TexturePtr inTexture, int inSlot) { auto texture = inTexture.get(); mD3dDeviceCtx->PSSetShaderResources(inSlot, 1, &texture); }
void GraphicsDriver::SetPSTexture( TexturePtr inTexture, int inStartSlot ) { auto texture = inTexture.get(); g_pImmediateContext->PSSetShaderResources( inStartSlot, 1, &texture ); }