Heightfield::Heightfield(ID3D11DeviceContext *mDevcon, ID3D11Device *mDev, GeometryGenerator *geoGen) : mDevcon(mDevcon), mDev(mDev) { CreateGeometry(geoGen); SetupBuffer(); SetupPipeline(); }
void LayerManagerD3D9::Render() { if (mSwapChain->PrepareForRendering() != DeviceOK) { return; } deviceManager()->SetupRenderState(); SetupPipeline(); if (CompositingDisabled()) { static_cast<LayerD3D9*>(mRoot->ImplData())->RenderLayer(); return; } nsIntRect rect; mWidget->GetClientBounds(rect); device()->Clear(0, nullptr, D3DCLEAR_TARGET, 0x00000000, 0, 0); device()->BeginScene(); const nsIntRect *clipRect = mRoot->GetClipRect(); RECT r; if (clipRect) { r.left = (LONG)clipRect->x; r.top = (LONG)clipRect->y; r.right = (LONG)(clipRect->x + clipRect->width); r.bottom = (LONG)(clipRect->y + clipRect->height); } else { r.left = r.top = 0; r.right = rect.width; r.bottom = rect.height; } device()->SetScissorRect(&r); static_cast<LayerD3D9*>(mRoot->ImplData())->RenderLayer(); device()->EndScene(); if (!mTarget) { const nsIntRect *r; for (nsIntRegionRectIterator iter(mClippingRegion); (r = iter.Next()) != nullptr;) { mSwapChain->Present(*r); } RecordFrame(); PostPresent(); } else { PaintToTarget(); } }
GroundPlane::GroundPlane(ID3D11DeviceContext *mDevcon, ID3D11Device *mDev, GeometryGenerator *geoGen, int planeSize, int increment) : mDevcon(mDevcon), mDev(mDev), size(planeSize), inc(increment) { cb = new PostPBuff(); cb->viewInvProj; cb->viewPrevProj; CreateGeometry(geoGen); SetupBuffer(); SetupPipeline(); SetupRenderTarget(); }
void ProgrammableOpAttributes::LoadRKernel(const std::string& name, const JSONNode &atts, const std::string& code) { script = JSONNode(); scriptMap = ""; stringVector args; SetupPipeline(atts,args,name); JSONNode vars = JSONNode::JSONArray(); for(int i = 0; i < args.size(); ++i) vars.Append(args[i]); JSONNode node; node["vars"] = vars; std::string argstring = ""; for(size_t i = 0; i < args.size(); ++i) argstring += args[i] + (i == args.size()-1 ? "" : ","); std::ostringstream rwrapper; rwrapper << "import rpy2,numpy\n" << "import rpy2.robjects as robjects\n" << "import rpy2.robjects.numpy2ri\n" << "rpy2.robjects.numpy2ri.activate()\n" << name << " = robjects.r('''\n" << code << "\n" << "''')\n" << "setout(numpy.asarray(" << name << "(" << argstring << ")))\n"; std::string escapedCode = rwrapper.str(); //std::cout << escapedCode << std::endl; replace(escapedCode, "\n", "\\n"); node["source"] = escapedCode; script["scripts"][name] = node; //update scriptmap scriptMap = script.ToString(); AddNode(name,name); AddFinalOutputConnection(name); }
void ProgrammableOpAttributes::LoadPythonKernel(const std::string& name, const JSONNode& atts, const std::string& code) { script = JSONNode(); scriptMap = ""; stringVector args; SetupPipeline(atts,args,name); std::string arglist = ""; JSONNode vars = JSONNode::JSONArray(); for(int i = 0; i < args.size(); ++i) { vars.Append(args[i]); arglist += args[i] + (i == args.size()-1 ? "" : ","); } JSONNode node; node["vars"] = vars; std::ostringstream pwrapper; pwrapper << "from visit_internal_funcs import *\n" //<< "exec('''" << "\n" //<< code << "''',globals())\n" << code << "\n" << "setout(" << name << "(" << arglist << "))\n"; std::string escapedCode = pwrapper.str(); //std::cout << escapedCode << std::endl; //replace(escapedCode, "'", "\""); //replace(escapedCode, "\"", "\\\""); //replace(escapedCode, "\n", "\\n"); node["source"] = escapedCode; script["scripts"][name] = node; scriptMap = script.ToString(); AddNode(name,name); AddFinalOutputConnection(name); }
////////////////////////////////////////////////////////////////////////// /// @brief InitDraw /// @param pDC - Draw context to initialize for this draw. void InitDraw( DRAW_CONTEXT *pDC, bool isSplitDraw) { // We don't need to re-setup the scissors/pipeline state again for split draw. if (isSplitDraw == false) { SetupMacroTileScissors(pDC); SetupPipeline(pDC); } pDC->inUse = true; // We are using this one now. /// @todo: remove when we send down preset sample patterns (standard or center) // If multisampling is enabled, precompute float sample offsets from fixed uint32_t numSamples = pDC->pState->state.rastState.sampleCount; if(numSamples > SWR_MULTISAMPLE_1X) { static const float fixed8Scale = 1.0f/FIXED_POINT_SCALE; float* pSamplePos = pDC->pState->state.samplePos; SWR_MULTISAMPLE_POS(&iSamplePos)[SWR_MAX_NUM_MULTISAMPLES] = pDC->pState->state.rastState.iSamplePos; for(uint32_t i = 0; i < numSamples; i++) { *(pSamplePos++) = ((float)(iSamplePos[i].x) * fixed8Scale); *(pSamplePos++) = ((float)(iSamplePos[i].y) * fixed8Scale); } } // just test the masked off samples once per draw and use the results in the backend. SWR_RASTSTATE &rastState = pDC->pState->state.rastState; uint32_t sampleMask = rastState.sampleMask; for(uint32_t i = 0; i < SWR_MAX_NUM_MULTISAMPLES; i++) { rastState.isSampleMasked[i] = !(sampleMask & 1); sampleMask>>=1; } }
void LayerManagerOGL::Render() { SAMPLE_LABEL("LayerManagerOGL", "Render"); if (mDestroyed) { NS_WARNING("Call on destroyed layer manager"); return; } nsIntRect rect; mWidget->GetClientBounds(rect); WorldTransformRect(rect); GLint width = rect.width; GLint height = rect.height; // We can't draw anything to something with no area // so just return if (width == 0 || height == 0) return; // If the widget size changed, we have to force a MakeCurrent // to make sure that GL sees the updated widget size. if (mWidgetSize.width != width || mWidgetSize.height != height) { MakeCurrent(true); mWidgetSize.width = width; mWidgetSize.height = height; } else { MakeCurrent(); } SetupBackBuffer(width, height); SetupPipeline(width, height, ApplyWorldTransform); // Default blend function implements "OVER" mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE); mGLContext->fEnable(LOCAL_GL_BLEND); const nsIntRect *clipRect = mRoot->GetClipRect(); if (clipRect) { nsIntRect r = *clipRect; WorldTransformRect(r); mGLContext->fScissor(r.x, r.y, r.width, r.height); } else { mGLContext->fScissor(0, 0, width, height); } mGLContext->fEnable(LOCAL_GL_SCISSOR_TEST); mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0); mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT); // Render our layers. RootLayer()->RenderLayer(mGLContext->IsDoubleBuffered() ? 0 : mBackBufferFBO, nsIntPoint(0, 0)); mWidget->DrawWindowOverlay(this, rect); #ifdef MOZ_DUMP_PAINTING if (gfxUtils::sDumpPainting) { nsIntRect rect; mWidget->GetBounds(rect); nsRefPtr<gfxASurface> surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(rect.Size(), gfxASurface::CONTENT_COLOR_ALPHA); nsRefPtr<gfxContext> ctx = new gfxContext(surf); CopyToTarget(ctx); WriteSnapshotToDumpFile(this, surf); } #endif if (mTarget) { CopyToTarget(mTarget); mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0); return; } if (sDrawFPS) { mFPS.DrawFPS(mGLContext, GetCopy2DProgram()); } if (mGLContext->IsDoubleBuffered()) { mGLContext->SwapBuffers(); LayerManager::PostPresent(); mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0); return; } mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0); CopyProgram *copyprog = GetCopy2DProgram(); if (mFBOTextureTarget == LOCAL_GL_TEXTURE_RECTANGLE_ARB) { copyprog = GetCopy2DRectProgram(); } mGLContext->fBindTexture(mFBOTextureTarget, mBackBufferTexture); copyprog->Activate(); copyprog->SetTextureUnit(0); if (copyprog->GetTexCoordMultiplierUniformLocation() != -1) { float f[] = { float(width), float(height) }; copyprog->SetUniform(copyprog->GetTexCoordMultiplierUniformLocation(), 2, f); } // we're going to use client-side vertex arrays for this. mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0); // "COPY" mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ZERO, LOCAL_GL_ONE, LOCAL_GL_ZERO); // enable our vertex attribs; we'll call glVertexPointer below // to fill with the correct data. GLint vcattr = copyprog->AttribLocation(CopyProgram::VertexCoordAttrib); GLint tcattr = copyprog->AttribLocation(CopyProgram::TexCoordAttrib); mGLContext->fEnableVertexAttribArray(vcattr); mGLContext->fEnableVertexAttribArray(tcattr); const nsIntRect *r; nsIntRegionRectIterator iter(mClippingRegion); while ((r = iter.Next()) != nsnull) { nsIntRect cRect = *r; r = &cRect; WorldTransformRect(cRect); float left = (GLfloat)r->x / width; float right = (GLfloat)r->XMost() / width; float top = (GLfloat)r->y / height; float bottom = (GLfloat)r->YMost() / height; float vertices[] = { left * 2.0f - 1.0f, -(top * 2.0f - 1.0f), right * 2.0f - 1.0f, -(top * 2.0f - 1.0f), left * 2.0f - 1.0f, -(bottom * 2.0f - 1.0f), right * 2.0f - 1.0f, -(bottom * 2.0f - 1.0f) }; // Use flipped texture coordinates since our // projection matrix also has a flip and we // need to cancel that out. float coords[] = { left, bottom, right, bottom, left, top, right, top }; mGLContext->fVertexAttribPointer(vcattr, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, vertices); mGLContext->fVertexAttribPointer(tcattr, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, coords); mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4); } mGLContext->fDisableVertexAttribArray(vcattr); mGLContext->fDisableVertexAttribArray(tcattr); mGLContext->fFlush(); mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0); }
void LayerManagerOGL::CreateFBOWithTexture(const nsIntRect& aRect, InitMode aInit, GLuint aCurrentFrameBuffer, GLuint *aFBO, GLuint *aTexture) { GLuint tex, fbo; mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0); mGLContext->fGenTextures(1, &tex); mGLContext->fBindTexture(mFBOTextureTarget, tex); if (aInit == InitModeCopy) { // We're going to create an RGBA temporary fbo. But to // CopyTexImage() from the current framebuffer, the framebuffer's // format has to be compatible with the new texture's. So we // check the format of the framebuffer here and take a slow path // if it's incompatible. GLenum format = GetFrameBufferInternalFormat(gl(), aCurrentFrameBuffer, mWidget); if (AreFormatsCompatibleForCopyTexImage2D(format, LOCAL_GL_RGBA)) { mGLContext->fCopyTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.x, aRect.y, aRect.width, aRect.height, 0); } else { // Curses, incompatible formats. Take a slow path. // // XXX Technically CopyTexSubImage2D also has the requirement of // matching formats, but it doesn't seem to affect us in the // real world. mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, NULL); mGLContext->fCopyTexSubImage2D(mFBOTextureTarget, 0, // level 0, 0, // offset aRect.x, aRect.y, aRect.width, aRect.height); } } else { mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, NULL); } mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fBindTexture(mFBOTextureTarget, 0); mGLContext->fGenFramebuffers(1, &fbo); mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo); mGLContext->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, mFBOTextureTarget, tex, 0); // Making this call to fCheckFramebufferStatus prevents a crash on // PowerVR. See bug 695246. GLenum result = mGLContext->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { nsCAutoString msg; msg.Append("Framebuffer not complete -- error 0x"); msg.AppendInt(result, 16); msg.Append(", mFBOTextureTarget 0x"); msg.AppendInt(mFBOTextureTarget, 16); msg.Append(", aRect.width "); msg.AppendInt(aRect.width); msg.Append(", aRect.height "); msg.AppendInt(aRect.height); NS_RUNTIMEABORT(msg.get()); } SetupPipeline(aRect.width, aRect.height, DontApplyWorldTransform); mGLContext->fScissor(0, 0, aRect.width, aRect.height); if (aInit == InitModeClear) { mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0); mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT); } *aFBO = fbo; *aTexture = tex; }
void LayerManagerD3D10::Render() { static_cast<LayerD3D10*>(mRoot->ImplData())->Validate(); SetupPipeline(); float black[] = { 0, 0, 0, 0 }; device()->ClearRenderTargetView(mRTView, black); nsIntRect rect; mWidget->GetClientBounds(rect); const nsIntRect *clipRect = mRoot->GetClipRect(); D3D10_RECT r; if (clipRect) { r.left = (LONG)clipRect->x; r.top = (LONG)clipRect->y; r.right = (LONG)(clipRect->x + clipRect->width); r.bottom = (LONG)(clipRect->y + clipRect->height); } else { r.left = r.top = 0; r.right = rect.width; r.bottom = rect.height; } device()->RSSetScissorRects(1, &r); static_cast<LayerD3D10*>(mRoot->ImplData())->RenderLayer(); if (mTarget) { PaintToTarget(); } else if (mBackBuffer) { ShadowLayerForwarder::BeginTransaction(); nsIntRect contentRect = nsIntRect(0, 0, rect.width, rect.height); if (!mRootForShadowTree) { mRootForShadowTree = new DummyRoot(this); mRootForShadowTree->SetShadow(ConstructShadowFor(mRootForShadowTree)); CreatedContainerLayer(mRootForShadowTree); ShadowLayerForwarder::SetRoot(mRootForShadowTree); } nsRefPtr<WindowLayer> windowLayer = static_cast<WindowLayer*>(mRootForShadowTree->GetFirstChild()); if (!windowLayer) { windowLayer = new WindowLayer(this); windowLayer->SetShadow(ConstructShadowFor(windowLayer)); CreatedThebesLayer(windowLayer); mRootForShadowTree->InsertAfter(windowLayer, nsnull); ShadowLayerForwarder::InsertAfter(mRootForShadowTree, windowLayer); } if (!mRootForShadowTree->GetVisibleRegion().IsEqual(contentRect)) { mRootForShadowTree->SetVisibleRegion(contentRect); windowLayer->SetVisibleRegion(contentRect); ShadowLayerForwarder::Mutated(mRootForShadowTree); ShadowLayerForwarder::Mutated(windowLayer); } FrameMetrics m; if (ContainerLayer* cl = mRoot->AsContainerLayer()) { m = cl->GetFrameMetrics(); } else { m.mScrollId = FrameMetrics::ROOT_SCROLL_ID; } if (m != mRootForShadowTree->GetFrameMetrics()) { mRootForShadowTree->SetFrameMetrics(m); ShadowLayerForwarder::Mutated(mRootForShadowTree); } SurfaceDescriptorD3D10 sd; GetDescriptor(mBackBuffer, &sd); ShadowLayerForwarder::PaintedThebesBuffer(windowLayer, contentRect, contentRect, nsIntPoint(), sd); // A source in the graphics pipeline can't also be a target. So // unbind here to avoid racing with the chrome process sourcing // the back texture. mDevice->OMSetRenderTargets(0, NULL, NULL); // XXX revisit this Flush() in bug 662109. It's not clear it's // needed. mDevice->Flush(); mRTView = NULL; AutoInfallibleTArray<EditReply, 10> replies; ShadowLayerForwarder::EndTransaction(&replies); // We expect only 1 reply, but might get none if the parent // process crashed swap(mBackBuffer, mRemoteFrontBuffer); } else { mSwapChain->Present(0, 0); } }