void D3D11Device::DispatchCompute( const EffectTechnique* technique, uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCounZ ) { /** * No need frame buffer need for Compute Shader. * * From MSDN * If an overlapping resource view is already bound to an output slot, * such as a render target, then the method will fill the destination * shader resource slot with NULL. */ BindFrameBuffer(nullptr); static ID3D11UnorderedAccessView* NullUAVs[D3D11_PS_CS_UAV_REGISTER_COUNT] = { nullptr }; for (EffectPass* pass : technique->GetPasses()) { pass->BeginPass(); DeviceContextD3D11->Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCounZ); // Hack: bind all Compute UAVs to null, because it may use as SRV in next pass. DeviceContextD3D11->CSSetUnorderedAccessViews(0, D3D11_PS_CS_UAV_REGISTER_COUNT, NullUAVs, nullptr); pass->EndPass(); } }
void Fbo::Begin() { BindFrameBuffer(); // set viewport as FBO tex size glViewport( 0, 0, Width(), Height() ); }
void D3D11Device::CreateRenderWindow() { const ApplicationSettings& appSettings = Application::msApp->GetAppSettings(); shared_ptr<D3D11RenderWindow> d3d11RenderWindow = std::make_shared<D3D11RenderWindow>(appSettings.Width, appSettings.Height); HRESULT hr = S_OK; // Create a render target view ID3D11Texture2D* pBackBuffer = NULL; hr = d3d11RenderWindow->SwapChainD3D11->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer ); assert( SUCCEEDED(hr) ); ID3D11RenderTargetView* pRenderTargetView = NULL; hr = gD3D11Device->DeviceD3D11->CreateRenderTargetView( pBackBuffer, NULL, &pRenderTargetView ); pBackBuffer->Release(); assert( SUCCEEDED(hr) ); d3d11RenderWindow->AttachRTV(ATT_Color0, std::make_shared<D3D11RenderTargetView2D>(pRenderTargetView) ); if(PixelFormatUtils::IsDepth(appSettings.DepthStencilFormat)) { // Have depth buffer, attach it RenderFactory* factory = gD3D11Device->GetRenderFactory(); shared_ptr<Texture> depthStencilTexture( new D3D11Texture2D(appSettings.DepthStencilFormat, appSettings.Width, appSettings.Height, appSettings.SampleCount, appSettings.SampleQuality)); d3d11RenderWindow->AttachRTV(ATT_DepthStencil, factory->CreateDepthStencilView(depthStencilTexture, 0, 0)); } d3d11RenderWindow->SetViewport(Viewport(0.f, 0.f, float(appSettings.Width), float(appSettings.Height))); BindFrameBuffer(d3d11RenderWindow); mScreenFrameBuffer = d3d11RenderWindow; }
void Fbo::Begin(bool a_set_viewport) { BindFrameBuffer(); // set viewport as FBO tex size if (a_set_viewport) RenderState::Ref().SetViewport( 0, 0, Width(), Height() ); }
void opengl_state::PopFramebufferState() { Assertion(framebuffer_stack.size() > 0, "Tried to pop the framebuffer state stack while it was empty!"); auto restoreBuffer = framebuffer_stack.back(); framebuffer_stack.pop_back(); BindFrameBuffer(restoreBuffer); }
void Fbo::SetRenderTargetTex( StrongHandle<Texture2d> tex, int slot ) { CHECK( !m_bound_as_target, "Cannot bind texture. Fbo currently bound!"); BindFrameBuffer(); SetRenderTargetTexNoBind(tex, slot); UnbindFrameBuffer(); }
void TGBufferCanvas::Enable() { glEnable(GL_DEPTH_TEST); BindFrameBuffer(m_frameBuffer); glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); ClearBuffer(); GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT ,GL_COLOR_ATTACHMENT3_EXT}; glDrawBuffers(4, buffers); }
// Inheritance exigences void TGBufferCanvas::Init() { // Drawable data m_output.width = m_width; m_output.height = m_height; // Creating the main frame buffer m_frameBuffer = CreateFrameBuffer(); BindFrameBuffer(m_frameBuffer); // Creating the textures // Memory allocation m_output.buffers.resize(5); // The abledo buffer TTextureInfo& albedo = m_output.buffers[0]; albedo.name = "albedo"; albedo.type = TTextureNature::COLOR; albedo.offset = 0; CreateTexture(albedo, m_width, m_height); BindToFrameBuffer(albedo); // The normal buffer TTextureInfo& normal = m_output.buffers[1]; normal.name = "normal"; normal.type = TTextureNature::COLOR; normal.offset = 1; CreateTexture(normal, m_width, m_height); BindToFrameBuffer(normal); // The specular buffer TTextureInfo& specular = m_output.buffers[2]; specular.name = "specular"; specular.type = TTextureNature::COLOR; specular.offset = 2; CreateTexture(specular, m_width, m_height); BindToFrameBuffer(specular); // Position Buffer TTextureInfo& position = m_output.buffers[3]; position.name = "position"; position.type = TTextureNature::COLOR; position.offset = 3; CreateTexture(position, m_width, m_height); BindToFrameBuffer(position); // Depth buffer TTextureInfo& depth = m_output.buffers[4]; depth.name = "depth"; depth.type = TTextureNature::DEPTH; depth.offset = 4; CreateTexture(depth, m_width, m_height); BindToFrameBuffer(depth); // Making sure everything is OK CheckFrameBuffer(); UnBindFrameBuffer(); }
void cFrameBufferFBO::Bind() { if ( mFrameBuffer ) { cGlobalBatchRenderer::instance()->Draw(); BindFrameBuffer(); BindRenderBuffer(); SetBufferView(); } }
void Fbo::RemoveRenderTargetTex( int slot ) { ASSERT(slot >= 0 && slot < MAX_NUM_SLOTS); // unbind from fbo BindFrameBuffer(); unsigned int GLcolorAttachmentSlot = GL_COLOR_ATTACHMENT0_EXT + slot; glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GLcolorAttachmentSlot, GL_TEXTURE_2D, 0, 0); UnbindFrameBuffer(); m_rtTextures[slot] = StrongHandle<Texture>(); }
void Fbo::RemoveRenderTargetTex( int slot ) { ASSERT(slot >= 0 && slot < MAX_NUM_SLOTS); // unbind from fbo BindFrameBuffer(); unsigned int GLcolorAttachmentSlot = GL_COLOR_ATTACHMENT0 + slot; glFramebufferTexture2D(GL_FRAMEBUFFER, GLcolorAttachmentSlot, GL_TEXTURE_2D, 0, 0); UnbindFrameBuffer(); m_rt_texs[slot] = nullptr; }
void Fbo::SetRenderTargetTex( StrongHandle<Texture> tex, int slot ) { CHECK( tex != NULL, "FBO trying to set NULL texure as color buffer!"); ASSERT(slot >= 0 && slot < MAX_NUM_SLOTS); CHECK( tex->Sizei() == Dimen(), "Texture dimensions must match FBO dimen" ); m_rtTextures[slot] = tex; CHECK( !m_boundAsTarget, "Cannot bind next texture. Fbo currently bound!"); unsigned int GLcolorAttachmentSlot = GL_COLOR_ATTACHMENT0_EXT + slot; BindFrameBuffer(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GLcolorAttachmentSlot, GL_TEXTURE_2D, tex->Id(), 0); UnbindFrameBuffer(); }
void D3D11Device::OnWindowResize( uint32_t width, uint32_t height ) { if (mScreenFrameBuffer) { const ApplicationSettings& appSettings = Application::msApp->GetAppSettings(); shared_ptr<D3D11RenderWindow> d3d11RenderWindow = static_pointer_cast_checked<D3D11RenderWindow>(mScreenFrameBuffer); d3d11RenderWindow->DetachAll(); DeviceContextD3D11->OMSetRenderTargets(0, 0, 0); HRESULT hr; // Preserve the existing buffer count and format. // Automatically choose the width and height to match the client rect for HWNDs. hr = d3d11RenderWindow->SwapChainD3D11->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0); ID3D11Texture2D* pBackBuffer; hr = d3d11RenderWindow->SwapChainD3D11->GetBuffer(0, __uuidof( ID3D11Texture2D), (void**) &pBackBuffer ); assert( SUCCEEDED(hr) ); ID3D11RenderTargetView* pRenderTargetView = NULL; hr = gD3D11Device->DeviceD3D11->CreateRenderTargetView( pBackBuffer, NULL, &pRenderTargetView ); pBackBuffer->Release(); assert( SUCCEEDED(hr) ); d3d11RenderWindow->AttachRTV(ATT_Color0, std::make_shared<D3D11RenderTargetView2D>(pRenderTargetView) ); if(PixelFormatUtils::IsDepth(appSettings.DepthStencilFormat)) { // Have depth buffer, attach it RenderFactory* factory = gD3D11Device->GetRenderFactory(); shared_ptr<Texture> depthStencilTexture( new D3D11Texture2D(appSettings.DepthStencilFormat, appSettings.Width, appSettings.Height, appSettings.SampleCount, appSettings.SampleQuality)); d3d11RenderWindow->AttachRTV(ATT_DepthStencil, factory->CreateDepthStencilView(depthStencilTexture, 0, 0)); } d3d11RenderWindow->Resize(width, height); d3d11RenderWindow->SetViewport(Viewport(0, 0, float(width), float(height))); BindFrameBuffer(d3d11RenderWindow); } }
bool cFrameBufferFBO::Create( const Uint32& Width, const Uint32& Height, bool DepthBuffer ) { if ( !IsSupported() ) return false; if ( NULL == mWindow ) { mWindow = cEngine::instance()->GetCurrentWindow(); } mWidth = Width; mHeight = Height; mHasDepthBuffer = DepthBuffer; GLuint frameBuffer = 0; glGenFramebuffersEXT( 1, &frameBuffer ); mFrameBuffer = static_cast<Int32>( frameBuffer ); if ( !mFrameBuffer) return false; BindFrameBuffer(); if ( DepthBuffer ) { GLuint depth = 0; glGenRenderbuffersEXT( 1, &depth ); mDepthBuffer = static_cast<unsigned int>(depth); if ( !mDepthBuffer ) return false; BindRenderBuffer(); glRenderbufferStorageEXT( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, Width, Height ); glFramebufferRenderbufferEXT( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthBuffer ); } if ( NULL == mTexture ) { Uint32 TexId = cTextureFactory::instance()->CreateEmptyTexture( Width, Height, 4, eeColorA(0,0,0,0) ); if ( cTextureFactory::instance()->TextureIdExists( TexId ) ) { mTexture = cTextureFactory::instance()->GetTexture( TexId ); } else { return false; } } glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture->Handle(), 0 ); if ( glCheckFramebufferStatusEXT( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE ) { glBindFramebufferEXT( GL_FRAMEBUFFER, mLastFB ); return false; } glBindFramebufferEXT( GL_FRAMEBUFFER, mLastFB ); return true; }