// CaptureRenderRequest // void plCaptureRenderRequest::Render(plPipeline* pipe, plPageTreeMgr* pageMgr) { // If we don't have a render target, something has gone horribly wrong. if( !GetRenderTarget() ) { hsAssert(false, "CaptureRenderRequest with no render target"); return; } // Set ourselves up like the current pipeline, except with our screen size. plViewTransform vt = pipe->GetViewTransform(); vt.SetViewPort(0, 0, fRenderTarget->GetWidth(), fRenderTarget->GetHeight()); SetViewTransform(vt); SetClearColor(pipe->GetClearColor()); SetClearDepth(pipe->GetClearDepth()); // Clear our render target // Render the scene pipe->PushRenderRequest(this); plVirtualCam1::Refresh(); pipe->ClearRenderTarget(); pageMgr->Render(pipe); pipe->PopRenderRequest(this); plVirtualCam1::Refresh(); // set up state so we can clear the z-buffer for every gui dialog (and therefore not have it // be obscured by other geometry) SetRenderState(GetRenderState() & ~plPipeline::kRenderClearColor); SetRenderState(GetRenderState() | plPipeline::kRenderClearDepth); SetClearDepth(1); // render all GUI items std::vector<plPostEffectMod*> guiRenderMods = pfGameGUIMgr::GetInstance()->GetDlgRenderMods(); for (int i = (int)guiRenderMods.size() - 1; i >= 0; i--) // render in reverse, so dialogs on the bottom get rendered first { plPageTreeMgr* dlgPageMgr = guiRenderMods[i]->GetPageMgr(); if (dlgPageMgr) { SetViewTransform(guiRenderMods[i]->GetViewTransform()); pipe->PushRenderRequest(this); pipe->ClearRenderTarget(); dlgPageMgr->Render(pipe); pipe->PopRenderRequest(this); } } // Callback on plCaptureRender to process the render target into a mipmap // and send it back to the requester. plCaptureRender::IProcess(pipe, GetAck(), GetRenderTarget()); delete fRenderTarget; fRenderTarget = nil; }
void Entity::Render( float ticks ) throw(std::exception) { DoUpdate(ticks); glPushMatrix(); glMultMatrixf( GetRenderState()->GetMatrix() ); uint32_t flags = GetRenderState()->GetFlags(); int gl_blend_src(0), gl_blend_dst(0); int alpha_enabled; glGetIntegerv(GL_ALPHA_TEST, &alpha_enabled); if (!alpha_enabled && (flags & RenderState::ALPHA_F) ) { glGetIntegerv(GL_BLEND_SRC, &gl_blend_src); glGetIntegerv(GL_BLEND_DST, &gl_blend_dst); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_ALPHA_TEST); } else if (alpha_enabled && (flags & RenderState::ALPHA_F) == 0 ) { glDisable(GL_ALPHA_TEST); } int blend_enabled; glGetIntegerv(GL_BLEND, &blend_enabled); if (!blend_enabled && (flags & RenderState::BLEND_F) ) { glEnable(GL_BLEND); } else if ( blend_enabled && (flags & RenderState::BLEND_F) == 0 ) { glDisable(GL_BLEND); } for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) { EntityPtr entity = *it; if ( entity->AreFlagsSet( Entity::F_ENABLE ) ) { entity->Render( ticks ); } if ( entity->AreFlagsSet( Entity::F_DELETE ) ) { it = m_RenderList.erase( it ); continue; } ++it; } DoRender(); if (!alpha_enabled && (flags & RenderState::ALPHA_F) ) { glBlendFunc( gl_blend_src, gl_blend_dst); } glPopMatrix(); }
void Entity::Render( int pass ) throw(std::exception) { glPushMatrix(); glMultMatrixf( GetRenderState()->GetMatrix() ); uint32_t flags = GetRenderState()->GetFlags(); int glBlendSrc(0), glBlendDst(0); int alphaEnabled; glGetIntegerv(GL_ALPHA_TEST, &alphaEnabled); if (!alphaEnabled && (flags & RenderState::ALPHA_F) ) { glGetIntegerv(GL_BLEND_SRC, &glBlendSrc); glGetIntegerv(GL_BLEND_DST, &glBlendDst); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_ALPHA_TEST); } else if (alphaEnabled && (flags & RenderState::ALPHA_F) == 0 ) { glDisable(GL_ALPHA_TEST); } int blendEnabled; glGetIntegerv(GL_BLEND, &blendEnabled); if (!blendEnabled && (flags & RenderState::BLEND_F) ) { glEnable(GL_BLEND); } else if ( blendEnabled && (flags & RenderState::BLEND_F) == 0 ) { glDisable(GL_BLEND); } // render all children for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) { EntityPtr entity = *it; if ( entity->IsFlagSet( Entity::F_ENABLE|Entity::F_VISIBLE ) && !entity->IsFlagSet( Entity::F_DELETE ) ) { // don't bother rendering if we are marked for deletion entity->Render( pass ); } ++it; } DoRender( pass ); if (!alphaEnabled && (flags & RenderState::ALPHA_F) ) { glBlendFunc( glBlendSrc, glBlendDst); } glPopMatrix(); }
bool Cube::DoInitialize( Renderer* renderer ) throw(std::exception) { bool hasVBO = glewGetExtension("GL_ARB_vertex_buffer_object"); ASSERT( hasVBO, "VBOs not supported!" ); if ( m_Assets.size() ) { for (auto& asset : m_Assets ) { TexturePtr texture( new Texture ); texture->Load( *asset.get() ); m_Textures.push_back( texture ); } GetRenderState()->ClearFlag( BLEND_COLOR_F ); } glGenBuffers(1, &m_VboID); glBindBuffer(GL_ARRAY_BUFFER, m_VboID); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices)+sizeof(normals)+sizeof(colors)+sizeof(texCoords), 0, GL_STATIC_DRAW_ARB); std::size_t offset(0); glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(vertices), vertices); // copy vertices starting from 0 offest offset += sizeof(vertices); glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(normals), normals); // copy normals after vertices offset += sizeof(normals); glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(colors), colors); // copy colors after normals if ( m_Textures.size() ) { offset += sizeof(texCoords); glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(texCoords), texCoords); // copy colors after normals } return true; }
void VkPostprocess::BlitSceneToPostprocess() { auto fb = GetVulkanFrameBuffer(); fb->GetRenderState()->EndRenderPass(); auto buffers = fb->GetBuffers(); auto cmdbuffer = fb->GetDrawCommands(); mCurrentPipelineImage = 0; VkImageTransition imageTransition; imageTransition.addImage(&buffers->SceneColor, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, false); imageTransition.addImage(&buffers->PipelineImage[mCurrentPipelineImage], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true); imageTransition.execute(fb->GetDrawCommands()); if (buffers->GetSceneSamples() != VK_SAMPLE_COUNT_1_BIT) { auto sceneColor = buffers->SceneColor.Image.get(); VkImageResolve resolve = {}; resolve.srcOffset = { 0, 0, 0 }; resolve.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; resolve.srcSubresource.mipLevel = 0; resolve.srcSubresource.baseArrayLayer = 0; resolve.srcSubresource.layerCount = 1; resolve.dstOffset = { 0, 0, 0 }; resolve.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; resolve.dstSubresource.mipLevel = 0; resolve.dstSubresource.baseArrayLayer = 0; resolve.dstSubresource.layerCount = 1; resolve.extent = { (uint32_t)sceneColor->width, (uint32_t)sceneColor->height, 1 }; cmdbuffer->resolveImage( sceneColor->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffers->PipelineImage[mCurrentPipelineImage].Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &resolve); } else { auto sceneColor = buffers->SceneColor.Image.get(); VkImageBlit blit = {}; blit.srcOffsets[0] = { 0, 0, 0 }; blit.srcOffsets[1] = { sceneColor->width, sceneColor->height, 1 }; blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; blit.srcSubresource.mipLevel = 0; blit.srcSubresource.baseArrayLayer = 0; blit.srcSubresource.layerCount = 1; blit.dstOffsets[0] = { 0, 0, 0 }; blit.dstOffsets[1] = { sceneColor->width, sceneColor->height, 1 }; blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; blit.dstSubresource.mipLevel = 0; blit.dstSubresource.baseArrayLayer = 0; blit.dstSubresource.layerCount = 1; cmdbuffer->blitImage( sceneColor->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffers->PipelineImage[mCurrentPipelineImage].Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); } }
void Skin::DrawRectElement(const RectElement &element, const Point &pos, const Point &size, Graphics::BlendMode blendMode) const { Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0); va.Add(vector3f(pos.x, pos.y, 0.0f), scaled(vector2f(element.pos.x, element.pos.y))); va.Add(vector3f(pos.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+element.size.y))); va.Add(vector3f(pos.x+size.x, pos.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y))); va.Add(vector3f(pos.x+size.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y))); m_renderer->DrawTriangles(&va, GetRenderState(blendMode), m_textureMaterial.Get(), Graphics::TRIANGLE_STRIP); }
void VkPostprocess::SetActiveRenderTarget() { auto fb = GetVulkanFrameBuffer(); auto buffers = fb->GetBuffers(); VkImageTransition imageTransition; imageTransition.addImage(&buffers->PipelineImage[mCurrentPipelineImage], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false); imageTransition.execute(fb->GetDrawCommands()); fb->GetRenderState()->SetRenderTarget(buffers->PipelineImage[mCurrentPipelineImage].View.get(), nullptr, buffers->GetWidth(), buffers->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, VK_SAMPLE_COUNT_1_BIT); }
// See method declaration for details. RenderTaskSequence::RenderTaskSequence(DrawPrimitivesTaskList& draw_primitives_tasks) { InsertSetIndexBufferTask(); RenderState current_render_state = GetInverseRenderState(*draw_primitives_tasks.Begin()); RenderState next_render_state; for(auto i = draw_primitives_tasks.Begin(); i != draw_primitives_tasks.End(); ++i) { next_render_state = GetRenderState(*i); GenerateTransitionTasksToNewRenderState(current_render_state, next_render_state); InsertDrawPrimitivesTask(*i); current_render_state = next_render_state; } }
/// <summary> /// <c>wSetRenderState</c> /// </summary> /// <remarks> /// </remarks> /// <param name="d3dDevice7"></param> /// <param name="dwRenderStateType"></param> /// <param name="dwRenderState"></param> /// <returns></returns> HRESULT __stdcall wSetRenderState( LPDIRECT3DDEVICE7 d3dDevice7, D3DRENDERSTATETYPE dwRenderStateType, ULONG dwRenderState) { PSTR pszRenderState; PSTR pszErrorMessage; HRESULT hResult; ++TotalRenderStateChanges; pszRenderState = GetRenderState(dwRenderStateType, dwRenderState); InternalFunctionSpew("GameOS_Direct3D", "SetRenderState(%s)", pszRenderState); hResult = d3dDevice7->SetRenderState(dwRenderStateType, dwRenderState); if (FAILED(hResult)) { pszRenderState = GetRenderState(dwRenderStateType, dwRenderState); pszErrorMessage = ErrorNumberToMessage(hResult); if ( InternalFunctionPause("FAILED (0x%x - %s) - SetRenderState(%s)", hResult, pszErrorMessage, pszRenderState) ) ENTER_DEBUGGER; } return hResult; }
void Light::SetupRender( int pass ) { // disable light for shadow pass if ( pass & PASS_SHADOW_MAP_F ) { glDisable(m_RenderStateProxy->m_Index); } // this we only do if we want to "draw" the light - we don't in shadow passes if ( pass & PASS_LIGHTING_F ) { // if regular mode do transform, if replay read & load projection matrix from render state glMatrixMode(GL_MODELVIEW); // not sure how much overhead this generates glPushMatrix(); glMultMatrixf( GetRenderState()->GetMatrix() ); } }
void VkPPRenderState::Draw() { auto fb = GetVulkanFrameBuffer(); auto pp = fb->GetPostprocess(); fb->GetRenderState()->EndRenderPass(); VkPPRenderPassKey key; key.BlendMode = BlendMode; key.InputTextures = Textures.Size(); key.Uniforms = Uniforms.Data.Size(); key.Shader = GetVkShader(Shader); key.SwapChain = (Output.Type == PPTextureType::SwapChain); key.ShadowMapBuffers = ShadowMapBuffers; if (Output.Type == PPTextureType::PPTexture) key.OutputFormat = GetVkTexture(Output.Texture)->Format; else if (Output.Type == PPTextureType::SwapChain) key.OutputFormat = GetVulkanFrameBuffer()->swapChain->swapChainFormat.format; else if (Output.Type == PPTextureType::ShadowMap) key.OutputFormat = VK_FORMAT_R32_SFLOAT; else key.OutputFormat = VK_FORMAT_R16G16B16A16_SFLOAT; if (Output.Type == PPTextureType::SceneColor) { key.StencilTest = 1; key.Samples = fb->GetBuffers()->GetSceneSamples(); } else { key.StencilTest = 0; key.Samples = VK_SAMPLE_COUNT_1_BIT; } auto &passSetup = pp->mRenderPassSetup[key]; if (!passSetup) passSetup.reset(new VkPPRenderPassSetup(key)); int framebufferWidth = 0, framebufferHeight = 0; VulkanDescriptorSet *input = GetInput(passSetup.get(), Textures, ShadowMapBuffers); VulkanFramebuffer *output = GetOutput(passSetup.get(), Output, key.StencilTest, framebufferWidth, framebufferHeight); RenderScreenQuad(passSetup.get(), input, output, framebufferWidth, framebufferHeight, Viewport.left, Viewport.top, Viewport.width, Viewport.height, Uniforms.Data.Data(), Uniforms.Data.Size(), key.StencilTest); // Advance to next PP texture if our output was sent there if (Output.Type == PPTextureType::NextPipelineTexture) { pp->mCurrentPipelineImage = (pp->mCurrentPipelineImage + 1) % VkRenderBuffers::NumPipelineImages; } }
void Buffered::Render( float ticks ) { // backup viewport GLint vp[4]; glGetIntegerv( GL_VIEWPORT, vp ); GLfloat depth[2]; glGetFloatv( GL_DEPTH_RANGE, depth ); // backup projection matrix for internal storage Matrix modelview; glGetFloatv( GL_MODELVIEW_MATRIX, (float*)modelview ); Matrix projection; glGetFloatv( GL_PROJECTION_MATRIX, (float*)projection ); m_FrameBuffer.Enable(); // background color glClearColor( 1,1,1,1 ); // clear buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) { EntityPtr entity = *it; if ( entity->AreFlagsSet( Entity::F_ENABLE ) ) { entity->Render(ticks); } if ( entity->AreFlagsSet( Entity::F_DELETE ) ) { it = m_RenderList.erase( it ); continue; } ++it; } m_FrameBuffer.Disable(); // restore view port glViewport( vp[0], vp[1], vp[2], vp[3]); glMatrixMode(GL_PROJECTION); glLoadMatrixf( projection ); glMatrixMode(GL_MODELVIEW); glLoadMatrixf( modelview ); DoUpdate( ticks ); // render local list into texture glPushMatrix(); glMultMatrixf(GetRenderState()->GetMatrix()); Cube::DoRender(); glPopMatrix(); }
void prefix::CRenderableVideo::Render( Moose::Graphics::COglRenderer & r ) { r.CommitRenderState(GetRenderState()); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(m_pCodecCtx->width, 0.0f); glVertex2f(1.0f, 0.0f); glTexCoord2f(m_pCodecCtx->width, m_pCodecCtx->height); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f, m_pCodecCtx->height); glVertex2f(0.0f, 1.0f); glEnd(); }
already_AddRefed<TexturedEffect> ImageHost::GenEffect(const gfx::Filter& aFilter) { if (!mFrontBuffer->BindTextureSource(mTextureSource)) { return nullptr; } bool isAlphaPremultiplied = true; if (mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED) isAlphaPremultiplied = false; return CreateTexturedEffect(mFrontBuffer->GetFormat(), mTextureSource, aFilter, isAlphaPremultiplied, GetRenderState()); }
void Terrain::DrawGeometry() { auto device = Device::GetInstance(); if (this->changed) { GenerateBuffers(); this->changed = false; } device->SetVertexFormat(this->vertexFormat); device->SetVertexBuffer(this->vb.Get(), sizeof(TerrainVertex), 0); device->SetIndexBuffer(this->ib.Get()); device->GetRenderState()->GetCurrentShader()->CommitChanges(); device->DrawIndexed(PrimitiveType::TRIANGLE_LIST, (this->xResolution - 1) * (this->yResolution - 1) * 6, 0, 0); }
void Skin::DrawBorderedRectElement(const BorderedRectElement &element, const Point &pos, const Point &size, Graphics::BlendMode blendMode) const { const float width = element.borderWidth; const float height = element.borderHeight; Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0); va.Add(vector3f(pos.x, pos.y, 0.0f), scaled(vector2f(element.pos.x, element.pos.y))); va.Add(vector3f(pos.x, pos.y+height, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+height))); va.Add(vector3f(pos.x+width, pos.y, 0.0f), scaled(vector2f(element.pos.x+width, element.pos.y))); va.Add(vector3f(pos.x+width, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+width, element.pos.y+height))); va.Add(vector3f(pos.x+size.x-width, pos.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x-width, element.pos.y))); va.Add(vector3f(pos.x+size.x-width, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+element.size.x-width, element.pos.y+height))); va.Add(vector3f(pos.x+size.x, pos.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y))); va.Add(vector3f(pos.x+size.x, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+height))); // degenerate triangles to join rows va.Add(vector3f(pos.x+size.x, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+height))); va.Add(vector3f(pos.x, pos.y+height, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+height))); va.Add(vector3f(pos.x, pos.y+height, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+height))); va.Add(vector3f(pos.x, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x+width, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+width, element.pos.y+height))); va.Add(vector3f(pos.x+width, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+width, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x+size.x-width, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+element.size.x-width, element.pos.y+height))); va.Add(vector3f(pos.x+size.x-width, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+element.size.x-width, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x+size.x, pos.y+height, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+height))); va.Add(vector3f(pos.x+size.x, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y-height))); // degenerate triangles to join rows va.Add(vector3f(pos.x+size.x, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x, element.pos.y+element.size.y))); va.Add(vector3f(pos.x+width, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+width, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x+width, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x+width, element.pos.y+element.size.y))); va.Add(vector3f(pos.x+size.x-width, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+element.size.x-width, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x+size.x-width, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x-width, element.pos.y+element.size.y))); va.Add(vector3f(pos.x+size.x, pos.y+size.y-height, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y-height))); va.Add(vector3f(pos.x+size.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y))); m_renderer->DrawTriangles(&va, GetRenderState(blendMode), m_textureMaterial.Get(), Graphics::TRIANGLE_STRIP); }
already_AddRefed<TexturedEffect> ContentHostTexture::GenEffect(const gfx::Filter& aFilter) { if (!mTextureHost) { return nullptr; } if (!mTextureHost->BindTextureSource(mTextureSource)) { return nullptr; } if (!mTextureHostOnWhite) { mTextureSourceOnWhite = nullptr; } if (mTextureHostOnWhite && !mTextureHostOnWhite->BindTextureSource(mTextureSourceOnWhite)) { return nullptr; } return CreateTexturedEffect(mTextureSource.get(), mTextureSourceOnWhite.get(), aFilter, true, GetRenderState()); }
already_AddRefed<TexturedEffect> ImageHost::GenEffect(const gfx::SamplingFilter aSamplingFilter) { TimedImage* img = ChooseImage(); if (!img) { return nullptr; } SetCurrentTextureHost(img->mTextureHost); if (!mCurrentTextureHost->BindTextureSource(mCurrentTextureSource)) { return nullptr; } bool isAlphaPremultiplied = true; if (mCurrentTextureHost->GetFlags() & TextureFlags::NON_PREMULTIPLIED) { isAlphaPremultiplied = false; } return CreateTexturedEffect(mCurrentTextureHost, mCurrentTextureSource, aSamplingFilter, isAlphaPremultiplied, GetRenderState()); }
void VkPostprocess::BlitCurrentToImage(VkTextureImage *dstimage, VkImageLayout finallayout) { auto fb = GetVulkanFrameBuffer(); fb->GetRenderState()->EndRenderPass(); auto srcimage = &fb->GetBuffers()->PipelineImage[mCurrentPipelineImage]; auto cmdbuffer = fb->GetDrawCommands(); VkImageTransition imageTransition0; imageTransition0.addImage(srcimage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, false); imageTransition0.addImage(dstimage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true); imageTransition0.execute(cmdbuffer); VkImageBlit blit = {}; blit.srcOffsets[0] = { 0, 0, 0 }; blit.srcOffsets[1] = { srcimage->Image->width, srcimage->Image->height, 1 }; blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; blit.srcSubresource.mipLevel = 0; blit.srcSubresource.baseArrayLayer = 0; blit.srcSubresource.layerCount = 1; blit.dstOffsets[0] = { 0, 0, 0 }; blit.dstOffsets[1] = { dstimage->Image->width, dstimage->Image->height, 1 }; blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; blit.dstSubresource.mipLevel = 0; blit.dstSubresource.baseArrayLayer = 0; blit.dstSubresource.layerCount = 1; cmdbuffer->blitImage( srcimage->Image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dstimage->Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); VkImageTransition imageTransition1; imageTransition1.addImage(dstimage, finallayout, false); imageTransition1.execute(cmdbuffer); }
void GameObject::Draw(){ //ゲームステージが無効ならリターン if (m_GameStgae.expired()){ return; } //デバイスの取得 auto Dev = App::GetApp()->GetDeviceResources(); auto pDx11Device = Dev->GetD3DDevice(); auto pID3D11DeviceContext = Dev->GetD3DDeviceContext(); //ステータスのポインタ auto RenderStatePtr = Dev->GetRenderState(); auto Stage = m_GameStgae.lock(); auto ViewPtr = Stage->GetView(); //ビューからカメラを取り出す auto PtrCamera = ViewPtr->GetCamera(); //カメラの取得 Matrix4X4 View, Proj; View = PtrCamera->GetViewMatrix(); Proj = PtrCamera->GetProjMatrix(); //コンスタントバッファの設定 Texture3DConstantBuffer cb1; //行列の設定(転置する) cb1.Model = Matrix4X4EX::Transpose(m_WorldMatrix); cb1.View = Matrix4X4EX::Transpose(View); cb1.Projection = Matrix4X4EX::Transpose(Proj); //ライトの設定 //ステージから0番目のライトを取り出す auto PtrLight = ViewPtr->GetMultiLight()->GetLight(0); cb1.LightDir = PtrLight->GetDirectional(); cb1.LightDir.w = 1.0f; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(CBTexture3D::GetPtr()->GetBuffer(), 0, nullptr, &cb1, 0, 0); //ストライドとオフセット UINT stride = sizeof(VertexPositionNormalTexture); UINT offset = 0; //頂点バッファの設定 pID3D11DeviceContext->IASetVertexBuffers(0, 1, m_VertexBuffer.GetAddressOf(), &stride, &offset); //インデックスバッファのセット pID3D11DeviceContext->IASetIndexBuffer(m_IndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); //描画方法(3角形) pID3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //透明処理 pID3D11DeviceContext->OMSetBlendState(RenderStatePtr->GetAlphaBlendEx(), nullptr, 0xffffffff); //デプスステンシルは使用する pID3D11DeviceContext->OMSetDepthStencilState(RenderStatePtr->GetDepthDefault(), 0); //シェーダの設定 pID3D11DeviceContext->VSSetShader(VSTexture3D::GetPtr()->GetShader(), nullptr, 0); pID3D11DeviceContext->PSSetShader(PSTexture3D::GetPtr()->GetShader(), nullptr, 0); //リニアサンプラーを設定 ID3D11SamplerState* samplerState = RenderStatePtr->GetLinearClamp(); pID3D11DeviceContext->PSSetSamplers(0, 1, &samplerState); for (auto& m : m_Materials){ //テクスチャを設定 pID3D11DeviceContext->PSSetShaderResources(0, 1, m.m_ShaderResView.GetAddressOf()); //インプットレイアウトの設定 pID3D11DeviceContext->IASetInputLayout(VSTexture3D::GetPtr()->GetInputLayout()); //コンスタントバッファの設定 ID3D11Buffer* pConstantBuffer = CBTexture3D::GetPtr()->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullFront()); //描画 pID3D11DeviceContext->DrawIndexed(m.m_IndexCount, m.m_StartIndex, 0); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullBack()); //描画 pID3D11DeviceContext->DrawIndexed(m.m_IndexCount, m.m_StartIndex,0); } //後始末 Dev->InitializeStates(RenderStatePtr); }
void Buffered::DoUpdate( float ticks ) { GetRenderState()->GetMatrix().RotateZ( 360.0f / 5000.0f * ticks ); }
bool Buffered::DoInitialize( Renderer* renderer ) { // Disable background color GetRenderState()->ClearFlag( BLEND_COLOR_F ); return Cube::DoInitialize( renderer ); }
void Ortho::Render( int pass ) throw(std::exception) { // backup previous viewport - needed if we render into a pbuffer GLint vp[4]; glGetIntegerv( GL_VIEWPORT, vp ); // backup projection matrix for internal storage Matrix modelview; glGetFloatv( GL_MODELVIEW_MATRIX, (float*)modelview ); Matrix projection; glGetFloatv( GL_PROJECTION_MATRIX, (float*)projection ); int lighting; glGetIntegerv(GL_LIGHTING, &lighting ); if ( lighting ) glDisable( GL_LIGHTING ); int depthTest; glGetIntegerv(GL_DEPTH_TEST, &depthTest ); if ( depthTest ) glDisable( GL_DEPTH_TEST ); // Position from the top const SDL_VideoInfo* info = SDL_GetVideoInfo(); float screenHeight(info->current_h); // make top the 0 for 2D positioning - glViewport( m_RenderStateProxy->m_XPos, screenHeight - ( m_RenderStateProxy->m_YPos + m_RenderStateProxy->m_Height ), m_RenderStateProxy->m_Width, m_RenderStateProxy->m_Height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); // flip this upside down // float x0(m_RenderStateProxy->m_XPos); // float x1(m_RenderStateProxy->m_XPos+m_RenderStateProxy->m_Width-1); // float y0(m_RenderStateProxy->m_YPos+m_RenderStateProxy->m_Height-1); // float y1(m_RenderStateProxy->m_YPos); // glOrtho( x0, x1, y0, y1, -1000.0f, 1000.0f ); // TODO: Override this with a virtual coord bounding box (x0,y0,x1,y1) float w(5); float h = w * float(m_RenderStateProxy->m_Width)/float(m_RenderStateProxy->m_Height); glOrtho( -w, w, -h, h, -100.0f, 100.0f ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // if regular mode do transform, if replay read & load projection matrix from render state glMultMatrixf( GetRenderState()->GetMatrix() ); // use a flag to enable clear color / and clear flags if ( m_RenderStateProxy->m_ClearFlags ) { if ( m_RenderStateProxy->m_ClearFlags & GL_COLOR_BUFFER_BIT ) { glClearColor( m_RenderStateProxy->m_ClearColor[ Vector::R ], m_RenderStateProxy->m_ClearColor[ Vector::G ], m_RenderStateProxy->m_ClearColor[ Vector::B ], m_RenderStateProxy->m_ClearColor[ Vector::A ]); } // clear buffer glClear( m_RenderStateProxy->m_ClearFlags ); } Entity::Render( pass ); if ( lighting ) glEnable( GL_LIGHTING ); if ( depthTest ) glEnable( GL_DEPTH_TEST ); // restore previous viewport glViewport(vp[0], vp[1], vp[2], vp[3]); // restore projection matrix glMatrixMode(GL_PROJECTION); glLoadMatrixf( projection ); // restore modelview matrix glMatrixMode(GL_MODELVIEW); glLoadMatrixf( modelview ); }
void ContentHostTexture::Composite(LayerComposite* aLayer, EffectChain& aEffectChain, float aOpacity, const gfx::Matrix4x4& aTransform, const Filter& aFilter, const Rect& aClipRect, const nsIntRegion* aVisibleRegion) { NS_ASSERTION(aVisibleRegion, "Requires a visible region"); AutoLockCompositableHost lock(this); if (lock.Failed()) { return; } if (!mTextureHost->BindTextureSource(mTextureSource)) { return; } MOZ_ASSERT(mTextureSource.get()); if (!mTextureHostOnWhite) { mTextureSourceOnWhite = nullptr; } if (mTextureHostOnWhite && !mTextureHostOnWhite->BindTextureSource(mTextureSourceOnWhite)) { return; } RefPtr<TexturedEffect> effect = CreateTexturedEffect(mTextureSource.get(), mTextureSourceOnWhite.get(), aFilter, true, GetRenderState()); if (!effect) { return; } aEffectChain.mPrimaryEffect = effect; nsIntRegion tmpRegion; const nsIntRegion* renderRegion; #ifndef MOZ_IGNORE_PAINT_WILL_RESAMPLE if (PaintWillResample()) { // If we're resampling, then the texture image will contain exactly the // entire visible region's bounds, and we should draw it all in one quad // to avoid unexpected aliasing. tmpRegion = aVisibleRegion->GetBounds(); renderRegion = &tmpRegion; } else { renderRegion = aVisibleRegion; } #else renderRegion = aVisibleRegion; #endif nsIntRegion region(*renderRegion); nsIntPoint origin = GetOriginOffset(); // translate into TexImage space, buffer origin might not be at texture (0,0) region.MoveBy(-origin); // Figure out the intersecting draw region gfx::IntSize texSize = mTextureSource->GetSize(); IntRect textureRect = IntRect(0, 0, texSize.width, texSize.height); textureRect.MoveBy(region.GetBounds().TopLeft()); nsIntRegion subregion; subregion.And(region, textureRect); if (subregion.IsEmpty()) { // Region is empty, nothing to draw return; } nsIntRegion screenRects; nsIntRegion regionRects; // Collect texture/screen coordinates for drawing nsIntRegionRectIterator iter(subregion); while (const IntRect* iterRect = iter.Next()) { IntRect regionRect = *iterRect; IntRect screenRect = regionRect; screenRect.MoveBy(origin); screenRects.Or(screenRects, screenRect); regionRects.Or(regionRects, regionRect); } BigImageIterator* bigImgIter = mTextureSource->AsBigImageIterator(); BigImageIterator* iterOnWhite = nullptr; if (bigImgIter) { bigImgIter->BeginBigImageIteration(); } if (mTextureSourceOnWhite) { iterOnWhite = mTextureSourceOnWhite->AsBigImageIterator(); MOZ_ASSERT(!bigImgIter || bigImgIter->GetTileCount() == iterOnWhite->GetTileCount(), "Tile count mismatch on component alpha texture"); if (iterOnWhite) { iterOnWhite->BeginBigImageIteration(); } } bool usingTiles = (bigImgIter && bigImgIter->GetTileCount() > 1); do { if (iterOnWhite && bigImgIter) { MOZ_ASSERT(iterOnWhite->GetTileRect() == bigImgIter->GetTileRect(), "component alpha textures should be the same size."); } IntRect texRect = bigImgIter ? bigImgIter->GetTileRect() : IntRect(0, 0, texSize.width, texSize.height); // Draw texture. If we're using tiles, we do repeating manually, as texture // repeat would cause each individual tile to repeat instead of the // compound texture as a whole. This involves drawing at most 4 sections, // 2 for each axis that has texture repeat. for (int y = 0; y < (usingTiles ? 2 : 1); y++) { for (int x = 0; x < (usingTiles ? 2 : 1); x++) { IntRect currentTileRect(texRect); currentTileRect.MoveBy(x * texSize.width, y * texSize.height); nsIntRegionRectIterator screenIter(screenRects); nsIntRegionRectIterator regionIter(regionRects); const IntRect* screenRect; const IntRect* regionRect; while ((screenRect = screenIter.Next()) && (regionRect = regionIter.Next())) { IntRect tileScreenRect(*screenRect); IntRect tileRegionRect(*regionRect); // When we're using tiles, find the intersection between the tile // rect and this region rect. Tiling is then handled by the // outer for-loops and modifying the tile rect. if (usingTiles) { tileScreenRect.MoveBy(-origin); tileScreenRect = tileScreenRect.Intersect(currentTileRect); tileScreenRect.MoveBy(origin); if (tileScreenRect.IsEmpty()) continue; tileRegionRect = regionRect->Intersect(currentTileRect); tileRegionRect.MoveBy(-currentTileRect.TopLeft()); } gfx::Rect rect(tileScreenRect.x, tileScreenRect.y, tileScreenRect.width, tileScreenRect.height); effect->mTextureCoords = Rect(Float(tileRegionRect.x) / texRect.width, Float(tileRegionRect.y) / texRect.height, Float(tileRegionRect.width) / texRect.width, Float(tileRegionRect.height) / texRect.height); GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain, aOpacity, aTransform); if (usingTiles) { DiagnosticFlags diagnostics = DiagnosticFlags::CONTENT | DiagnosticFlags::BIGIMAGE; if (iterOnWhite) { diagnostics |= DiagnosticFlags::COMPONENT_ALPHA; } GetCompositor()->DrawDiagnostics(diagnostics, rect, aClipRect, aTransform, mFlashCounter); } } } } if (iterOnWhite) { iterOnWhite->NextTile(); } } while (usingTiles && bigImgIter->NextTile()); if (bigImgIter) { bigImgIter->EndBigImageIteration(); } if (iterOnWhite) { iterOnWhite->EndBigImageIteration(); } DiagnosticFlags diagnostics = DiagnosticFlags::CONTENT; if (iterOnWhite) { diagnostics |= DiagnosticFlags::COMPONENT_ALPHA; } GetCompositor()->DrawDiagnostics(diagnostics, nsIntRegion(mBufferRect), aClipRect, aTransform, mFlashCounter); }
void prefix::CLineRenderable::Render( COglRenderer & r ) { r.CommitRenderState(GetRenderState()); if ( m_pTransform != NULL ) { r.CommitTransform( *m_pTransform ); } CShader *pShader = *GetRenderState().GetShaderHandle(); r.CommitShader( pShader ); if ( !GetRenderState().GetShaderHandle().IsNull()) { GetRenderState().GetShaderAttribs().Apply(r); GetRenderState().GetShaderUniforms().Apply(r); if ( r.GetCurrentCamera() ) { // Update matrices GetRenderState().GetShaderViewUniform().SetData( &r.GetCurrentCamera()->GetViewMatrix()); GetRenderState().GetShaderProjectionUniform().SetData(&r.GetCurrentCamera()->GetProjectionMatrix()); if ( GetTransform() ) { GetRenderState().GetShaderModelUniform().SetData( &GetTransform()->GetMatrix() ); } else { GetRenderState().GetShaderModelUniform().SetData( &CMatrix4x4<float>::Identity ); } // Send data to shader GetRenderState().GetShaderViewUniform().Apply(r); GetRenderState().GetShaderProjectionUniform().Apply(r); GetRenderState().GetShaderModelUniform().Apply(r); } } r.CommitPrimitive( g_IndexMgr->GetResource("moose_linerenderable_indices") ); GetRenderState().GetShaderAttribs().Disable(r); if ( m_pTransform != NULL ) r.RollbackTransform(); }
void Cube::DoRender( int pass ) throw(std::exception) { int normalArrayEnabled; int colorArrayEnabled; int vertexArrayEnabled; int texCoordArrayEnabled; // enable vertex arrays glGetIntegerv( GL_NORMAL_ARRAY, &normalArrayEnabled ); if ( !normalArrayEnabled ) { glEnableClientState(GL_NORMAL_ARRAY); } glGetIntegerv( GL_COLOR_ARRAY, &colorArrayEnabled ); if ( !colorArrayEnabled && (GetRenderState()->GetFlags() & BLEND_COLOR_F) ) { glEnableClientState(GL_COLOR_ARRAY); } glGetIntegerv( GL_VERTEX_ARRAY, &vertexArrayEnabled ); if (!vertexArrayEnabled) { glEnableClientState(GL_VERTEX_ARRAY); } glGetIntegerv( GL_TEXTURE_COORD_ARRAY, &texCoordArrayEnabled ); if ( m_Textures.size() && !texCoordArrayEnabled ) { if (!texCoordArrayEnabled) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); } } int blend_enabled; glGetIntegerv(GL_BLEND, &blend_enabled); // Render with VBO - if available glBindBuffer(GL_ARRAY_BUFFER, m_VboID); // before draw, specify vertex and index arrays with their offsets std::size_t offset(0); glVertexPointer(3, GL_FLOAT, 0, (void*)offset); offset += sizeof(vertices); glNormalPointer( GL_FLOAT, 0, (void*)offset); offset += sizeof(normals); glColorPointer (4, GL_FLOAT, 0, (void*)offset); if ( m_Textures.size()) { m_Textures[0]->Enable(); offset += sizeof(texCoords); glTexCoordPointer(2, GL_FLOAT, 0, (void*)offset ); if (blend_enabled) { glDisable( GL_BLEND ); } } glDrawArrays(GL_TRIANGLES, 0, 36); glBindBuffer(GL_ARRAY_BUFFER, 0); if ( m_Textures.size() ) { m_Textures[0]->Disable(); if (!texCoordArrayEnabled) { glDisableClientState(GL_TEXTURE_COORD_ARRAY); } if (blend_enabled) { glEnable( GL_BLEND ); } } if (!vertexArrayEnabled) { glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays } if (!colorArrayEnabled) { glDisableClientState(GL_COLOR_ARRAY); } if (!normalArrayEnabled) { glDisableClientState(GL_NORMAL_ARRAY); } }
void ImageHost::Composite(LayerComposite* aLayer, EffectChain& aEffectChain, float aOpacity, const gfx::Matrix4x4& aTransform, const gfx::SamplingFilter aSamplingFilter, const gfx::IntRect& aClipRect, const nsIntRegion* aVisibleRegion) { if (!GetCompositor()) { // should only happen when a tab is dragged to another window and // async-video is still sending frames but we haven't attached the // set the new compositor yet. return; } int imageIndex = ChooseImageIndex(); if (imageIndex < 0) { return; } if (uint32_t(imageIndex) + 1 < mImages.Length()) { GetCompositor()->CompositeUntil(mImages[imageIndex + 1].mTimeStamp + TimeDuration::FromMilliseconds(BIAS_TIME_MS)); } TimedImage* img = &mImages[imageIndex]; img->mTextureHost->SetCompositor(GetCompositor()); SetCurrentTextureHost(img->mTextureHost); { AutoLockCompositableHost autoLock(this); if (autoLock.Failed()) { NS_WARNING("failed to lock front buffer"); return; } if (!mCurrentTextureHost->BindTextureSource(mCurrentTextureSource)) { return; } if (!mCurrentTextureSource) { // BindTextureSource above should have returned false! MOZ_ASSERT(false); return; } bool isAlphaPremultiplied = !(mCurrentTextureHost->GetFlags() & TextureFlags::NON_PREMULTIPLIED); RefPtr<TexturedEffect> effect = CreateTexturedEffect(mCurrentTextureHost, mCurrentTextureSource.get(), aSamplingFilter, isAlphaPremultiplied, GetRenderState()); if (!effect) { return; } if (!GetCompositor()->SupportsEffect(effect->mType)) { return; } DiagnosticFlags diagnosticFlags = DiagnosticFlags::IMAGE; if (effect->mType == EffectTypes::NV12) { diagnosticFlags |= DiagnosticFlags::NV12; } else if (effect->mType == EffectTypes::YCBCR) { diagnosticFlags |= DiagnosticFlags::YCBCR; } if (mLastFrameID != img->mFrameID || mLastProducerID != img->mProducerID) { if (mImageContainer) { static_cast<LayerManagerComposite*>(aLayer->GetLayerManager())-> AppendImageCompositeNotification(ImageCompositeNotification( mImageContainer, nullptr, img->mTimeStamp, GetCompositor()->GetCompositionTime(), img->mFrameID, img->mProducerID)); } mLastFrameID = img->mFrameID; mLastProducerID = img->mProducerID; } aEffectChain.mPrimaryEffect = effect; gfx::Rect pictureRect(0, 0, img->mPictureRect.width, img->mPictureRect.height); BigImageIterator* it = mCurrentTextureSource->AsBigImageIterator(); if (it) { // This iteration does not work if we have multiple texture sources here // (e.g. 3 YCbCr textures). There's nothing preventing the different // planes from having different resolutions or tile sizes. For example, a // YCbCr frame could have Cb and Cr planes that are half the resolution of // the Y plane, in such a way that the Y plane overflows the maximum // texture size and the Cb and Cr planes do not. Then the Y plane would be // split into multiple tiles and the Cb and Cr planes would just be one // tile each. // To handle the general case correctly, we'd have to create a grid of // intersected tiles over all planes, and then draw each grid tile using // the corresponding source tiles from all planes, with appropriate // per-plane per-tile texture coords. // DrawQuad currently assumes that all planes use the same texture coords. MOZ_ASSERT(it->GetTileCount() == 1 || !mCurrentTextureSource->GetNextSibling(), "Can't handle multi-plane BigImages"); it->BeginBigImageIteration(); do { IntRect tileRect = it->GetTileRect(); gfx::Rect rect(tileRect.x, tileRect.y, tileRect.width, tileRect.height); rect = rect.Intersect(pictureRect); effect->mTextureCoords = Rect(Float(rect.x - tileRect.x) / tileRect.width, Float(rect.y - tileRect.y) / tileRect.height, Float(rect.width) / tileRect.width, Float(rect.height) / tileRect.height); if (img->mTextureHost->GetFlags() & TextureFlags::ORIGIN_BOTTOM_LEFT) { effect->mTextureCoords.y = effect->mTextureCoords.YMost(); effect->mTextureCoords.height = -effect->mTextureCoords.height; } GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain, aOpacity, aTransform); GetCompositor()->DrawDiagnostics(diagnosticFlags | DiagnosticFlags::BIGIMAGE, rect, aClipRect, aTransform, mFlashCounter); } while (it->NextTile()); it->EndBigImageIteration(); // layer border GetCompositor()->DrawDiagnostics(diagnosticFlags, pictureRect, aClipRect, aTransform, mFlashCounter); } else { IntSize textureSize = mCurrentTextureSource->GetSize(); effect->mTextureCoords = Rect(Float(img->mPictureRect.x) / textureSize.width, Float(img->mPictureRect.y) / textureSize.height, Float(img->mPictureRect.width) / textureSize.width, Float(img->mPictureRect.height) / textureSize.height); if (img->mTextureHost->GetFlags() & TextureFlags::ORIGIN_BOTTOM_LEFT) { effect->mTextureCoords.y = effect->mTextureCoords.YMost(); effect->mTextureCoords.height = -effect->mTextureCoords.height; } GetCompositor()->DrawQuad(pictureRect, aClipRect, aEffectChain, aOpacity, aTransform); GetCompositor()->DrawDiagnostics(diagnosticFlags, pictureRect, aClipRect, aTransform, mFlashCounter); } } // Update mBias last. This can change which frame ChooseImage(Index) would // return, and we don't want to do that until we've finished compositing // since callers of ChooseImage(Index) assume the same image will be chosen // during a given composition. This must happen after autoLock's // destructor! mBias = UpdateBias( GetCompositor()->GetCompositionTime(), mImages[imageIndex].mTimeStamp, uint32_t(imageIndex + 1) < mImages.Length() ? mImages[imageIndex + 1].mTimeStamp : TimeStamp(), mBias); }
Cube::Cube( std::vector<BrushPtr> assetList ) : m_VboID(0) , m_Assets( assetList ) { GetRenderState()->SetFlag( BLEND_COLOR_F ); }
Cube::Cube() : m_VboID(0) { GetRenderState()->SetFlag( BLEND_COLOR_F ); }
void ImageHost::Composite(EffectChain& aEffectChain, float aOpacity, const gfx::Matrix4x4& aTransform, const gfx::Filter& aFilter, const gfx::Rect& aClipRect, const nsIntRegion* aVisibleRegion) { if (!GetCompositor()) { // should only happen when a tab is dragged to another window and // async-video is still sending frames but we haven't attached the // set the new compositor yet. return; } if (!mFrontBuffer) { return; } // Make sure the front buffer has a compositor mFrontBuffer->SetCompositor(GetCompositor()); AutoLockCompositableHost autoLock(this); if (autoLock.Failed()) { NS_WARNING("failed to lock front buffer"); return; } if (!mFrontBuffer->BindTextureSource(mTextureSource)) { return; } if (!mTextureSource) { // BindTextureSource above should have returned false! MOZ_ASSERT(false); return; } bool isAlphaPremultiplied = !(mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED); RefPtr<TexturedEffect> effect = CreateTexturedEffect(mFrontBuffer->GetFormat(), mTextureSource.get(), aFilter, isAlphaPremultiplied, GetRenderState()); if (!effect) { return; } aEffectChain.mPrimaryEffect = effect; IntSize textureSize = mTextureSource->GetSize(); gfx::Rect gfxPictureRect = mHasPictureRect ? gfx::Rect(0, 0, mPictureRect.width, mPictureRect.height) : gfx::Rect(0, 0, textureSize.width, textureSize.height); gfx::Rect pictureRect(0, 0, mPictureRect.width, mPictureRect.height); BigImageIterator* it = mTextureSource->AsBigImageIterator(); if (it) { // This iteration does not work if we have multiple texture sources here // (e.g. 3 YCbCr textures). There's nothing preventing the different // planes from having different resolutions or tile sizes. For example, a // YCbCr frame could have Cb and Cr planes that are half the resolution of // the Y plane, in such a way that the Y plane overflows the maximum // texture size and the Cb and Cr planes do not. Then the Y plane would be // split into multiple tiles and the Cb and Cr planes would just be one // tile each. // To handle the general case correctly, we'd have to create a grid of // intersected tiles over all planes, and then draw each grid tile using // the corresponding source tiles from all planes, with appropriate // per-plane per-tile texture coords. // DrawQuad currently assumes that all planes use the same texture coords. MOZ_ASSERT(it->GetTileCount() == 1 || !mTextureSource->GetNextSibling(), "Can't handle multi-plane BigImages"); it->BeginBigImageIteration(); do { IntRect tileRect = it->GetTileRect(); gfx::Rect rect(tileRect.x, tileRect.y, tileRect.width, tileRect.height); if (mHasPictureRect) { rect = rect.Intersect(pictureRect); effect->mTextureCoords = Rect(Float(rect.x - tileRect.x)/ tileRect.width, Float(rect.y - tileRect.y) / tileRect.height, Float(rect.width) / tileRect.width, Float(rect.height) / tileRect.height); } else { effect->mTextureCoords = Rect(0, 0, 1, 1); } if (mFrontBuffer->GetFlags() & TextureFlags::ORIGIN_BOTTOM_LEFT) { effect->mTextureCoords.y = effect->mTextureCoords.YMost(); effect->mTextureCoords.height = -effect->mTextureCoords.height; } GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain, aOpacity, aTransform); GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE | DiagnosticFlags::BIGIMAGE, rect, aClipRect, aTransform, mFlashCounter); } while (it->NextTile()); it->EndBigImageIteration(); // layer border GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE, gfxPictureRect, aClipRect, aTransform, mFlashCounter); } else { IntSize textureSize = mTextureSource->GetSize(); gfx::Rect rect; if (mHasPictureRect) { effect->mTextureCoords = Rect(Float(mPictureRect.x) / textureSize.width, Float(mPictureRect.y) / textureSize.height, Float(mPictureRect.width) / textureSize.width, Float(mPictureRect.height) / textureSize.height); rect = pictureRect; } else { effect->mTextureCoords = Rect(0, 0, 1, 1); rect = gfx::Rect(0, 0, textureSize.width, textureSize.height); } if (mFrontBuffer->GetFlags() & TextureFlags::ORIGIN_BOTTOM_LEFT) { effect->mTextureCoords.y = effect->mTextureCoords.YMost(); effect->mTextureCoords.height = -effect->mTextureCoords.height; } GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain, aOpacity, aTransform); GetCompositor()->DrawDiagnostics(DiagnosticFlags::IMAGE, rect, aClipRect, aTransform, mFlashCounter); } }