// only find local links void EntityLinkDecorator::gatherLinksLocal(Vec4f::List& vList, RenderContext& context, Model::Entity& curEnt) { if (!context.filter().entityVisible(curEnt)) return; Model::EntityList::const_iterator it, end; const Model::EntityList& targetList = curEnt.linkTargets(); for (it = targetList.begin(), end = targetList.end(); it != end; ++it) { const Model::Entity& targetEnt = **it; if (!context.filter().entityVisible(targetEnt)) continue; addArrowVerts(vList, curEnt.center(), targetEnt.center()); } const Model::EntityList& sourceList = curEnt.linkSources(); for (it = sourceList.begin(), end = sourceList.end(); it != end; ++it) { const Model::Entity& sourceEnt = **it; if (!context.filter().entityVisible(sourceEnt)) continue; addArrowVerts(vList, sourceEnt.center(), curEnt.center()); } }
void DefaultPointHandleRenderer::render(Vbo& vbo, RenderContext& context) { const Vec4f::List& positionList = positions(); if (positionList.empty()) return; SetVboState activateVbo(vbo, Vbo::VboActive); if (m_vertexArray == NULL) { Vec3f::List vertices = sphere(); unsigned int vertexCount = static_cast<unsigned int>(vertices.size()); m_vertexArray = new VertexArray(vbo, GL_TRIANGLES, vertexCount, Attribute::position3f()); SetVboState mapVbo(vbo, Vbo::VboMapped); Vec3f::List::const_iterator vIt, vEnd; for (vIt = vertices.begin(), vEnd = vertices.end(); vIt != vEnd; ++vIt) { const Vec3f& vertex = *vIt; m_vertexArray->addAttribute(vertex); } } Renderer::ActivateShader shader(context.shaderManager(), Renderer::Shaders::PointHandleShader); shader.currentShader().setUniformVariable("Color", color()); shader.currentShader().setUniformVariable("CameraPosition", context.camera().position()); shader.currentShader().setUniformVariable("ScalingFactor", scalingFactor()); shader.currentShader().setUniformVariable("MaximumDistance", maximumDistance()); Vec4f::List::const_iterator pIt, pEnd; for (pIt = positionList.begin(), pEnd = positionList.end(); pIt != pEnd; ++pIt) { const Vec4f& position = *pIt; shader.currentShader().setUniformVariable("Position", position); m_vertexArray->render(); } }
void Video::renderImpl(RenderContext& ctxt) const { Mutex::Lock l(mutex); if(skipRender()) return; //Video is especially optimized for GL rendering //It needs special treatment for SOFTWARE contextes if(ctxt.contextType != RenderContext::GL) { LOG(LOG_NOT_IMPLEMENTED, "Video::renderImpl on SOFTWARE context is not yet supported"); return; } if(!netStream.isNull() && netStream->lockIfReady()) { //All operations here should be non blocking //Get size videoWidth=netStream->getVideoWidth(); videoHeight=netStream->getVideoHeight(); const MATRIX totalMatrix=getConcatenatedMatrix(); float m[16]; totalMatrix.get4DMatrix(m); ctxt.lsglLoadMatrixf(m); //Enable YUV to RGB conversion //width and height will not change now (the Video mutex is acquired) ctxt.renderTextured(netStream->getTexture(), 0, 0, width, height, clippedAlpha(), RenderContext::YUV_MODE); netStream->unlock(); } }
void EntityRenderer::renderModels(RenderContext& context) { if (m_modelRenderers.empty()) return; Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences(); EntityModelRendererManager& modelRendererManager = m_document.sharedResources().modelRendererManager(); ShaderManager& shaderManager = m_document.sharedResources().shaderManager(); ShaderProgram& entityModelProgram = shaderManager.shaderProgram(Shaders::EntityModelShader); if (entityModelProgram.activate()) { modelRendererManager.activate(); entityModelProgram.setUniformVariable("Brightness", prefs.getFloat(Preferences::RendererBrightness)); entityModelProgram.setUniformVariable("ApplyTinting", m_applyTinting); entityModelProgram.setUniformVariable("TintColor", m_tintColor); entityModelProgram.setUniformVariable("GrayScale", m_grayscale); EntityModelRenderers::iterator it, end; for (it = m_modelRenderers.begin(), end = m_modelRenderers.end(); it != end; ++it) { Model::Entity* entity = it->first; if (context.filter().entityVisible(*entity)) { EntityModelRenderer* renderer = it->second.renderer; renderer->render(entityModelProgram, context.transformation(), *entity); } } modelRendererManager.deactivate(); entityModelProgram.deactivate(); } }
void WindowTree::onRenderItem( RenderContext & context, const RectInt & window, PointInt & pos, Item * pItem ) { WindowStyle * pStyle = windowStyle(); ASSERT( pStyle ); Font * pFont = windowStyle()->font(); ASSERT( pFont ); // get the depth of this item int depth = itemDepth( pItem ); // determine the X position based on it's depth pos.x = window.left + (depth * m_Indent); // get the size of the label text SizeInt labelSize( pFont->size( pItem->sLabel ) ); // determine the height of this item int height = (int)(labelSize.height + TREE_ITEM_BUFFER); RectInt itemRect( window.left, pos.y, window.right, pos.y + height ); // check if this item is highlighted or not if ( m_CursorInWindow && itemRect.inRect( m_LastCursorPosition ) ) onHighlight( pItem ); PrimitiveMaterial::push( context.display(), WHITE, PrimitiveMaterial::ALPHA ); if ( pItem->dwFlags & BUTTON ) { bool expanded = (pItem->dwFlags & EXPANDED) != 0; Color backColor( expanded ? pStyle->backColor() * TREE_SHADE_COLOR : pStyle->backColor() ); Color shadeColor( expanded ? pStyle->borderColor() * TREE_LIGHT_COLOR : pStyle->borderColor() * TREE_SHADE_COLOR ); Color lightColor( expanded ? pStyle->borderColor() * TREE_SHADE_COLOR : pStyle->borderColor() * TREE_LIGHT_COLOR ); // render the button pushBackground( context, itemRect, backColor, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER ); pushBorder( context, itemRect, lightColor, shadeColor, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER ); // draw glow around this object if the mouse is currently over this button if ( m_pCursorOver == pItem ) pushGlow( context, itemRect, TREE_GLOW_SIZE, TREE_GLOW_INNER, TREE_GLOW_OUTER, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER ); // place the label in the center of the button PointInt labelPos( itemRect.center() - PointInt( labelSize.width / 2, labelSize.height / 2 ) ); // draw the label Font::push( context.display(), pFont, labelPos, pItem->sLabel, pItem->cColor ); } else { if ( m_pSelected == pItem ) pushBackground( context, itemRect, pStyle->highColor(), 0, 0 ); if ( m_pCursorOver == pItem ) pushGlow( context, itemRect, TREE_GLOW_SIZE, TREE_GLOW_INNER, TREE_GLOW_OUTER, 0, 0 ); PointInt labelPos( pos.x, (int)(pos.y + (TREE_ITEM_BUFFER / 2)) ); // render the label text` Font::push( context.display(), pFont, labelPos, pItem->sLabel, pItem->cColor ); } // move y down pos.y += (int)(height + WINDOW_TREE_SPACING); }
void ButtonBuildStructure::onRender( RenderContext & context, const RectInt & window ) { WindowButton::onRender( context, window ); if ( enabled() && m_Build.valid() ) { DisplayDevice * pDisplay = context.display(); ASSERT( pDisplay ); // draw the eta to build this structure Font * pFont = windowStyle()->font(); if ( pFont != NULL ) { WideString eta; GameDocument * pDoc = (GameDocument *)document(); if ( pDoc != NULL ) { NounShip::Ref pShip = pDoc->ship(); if ( pShip.valid() ) { int buildTime = m_Build->buildTime()* pShip->calculateModifier(MT_BUILD_SPEED,true); eta.format( "%d:%2.2d", buildTime / 60, buildTime % 60); SizeInt etaSize( pFont->size( eta ) ); PointInt etaPos( window.right - etaSize.width, window.bottom - etaSize.height ); Font::push( context.display(), pFont, etaPos, eta, WHITE ); } } } } }
void ToggleButton::render(RenderContext& rc) const { rc.image(x(), y(), width(), height(), texture); if (enabled) rc.border(x(), y(), width(), height(), colour::WHITE); }
void TextNode::renderItself(RenderContext& renderContext) { NVGcontext& nanoVgContext = renderContext.getNanoVgContext(); nvgSave(&nanoVgContext); setupContext(nanoVgContext); Color finalColor = mFontColor.getBlendedColor(renderContext.getBlendColors()); nvgFillColor(&nanoVgContext, nvgRGBAf(finalColor.getRed(), finalColor.getGreen(), finalColor.getBlue(), finalColor.getAlpha())); for(const Text& text : mTexts) { const char* charArray = text.getString().getCharArray(); float positionX = text.getPosition().getX(); float positionY = text.getPosition().getY(); if(isPositive(text.getBoxWidth())) { nvgTextBox(&nanoVgContext, positionX, positionY, text.getBoxWidth(), charArray, nullptr); } else { nvgText(&nanoVgContext, positionX, positionY, charArray, nullptr); } } nvgRestore(&nanoVgContext); Node::renderItself(renderContext); }
void ThrottleMeter::render(RenderContext& rc) const { IFontPtr font = rc.theme().font(font_name); int ox = x(), oy = y(); rc.offset(ox, oy); static const string LABEL = "Power: "; font->print(ox, oy, colour::WHITE, LABEL); glPushMatrix(); const int off = (height() - METER_HEIGHT) / 2; glTranslatef(ox + static_cast<float>(font->text_width(LABEL)), static_cast<float>(oy + off), 0.0f); const int unit = METER_WIDTH / (max_value + 1); // Neutral bit glColor3f(1.0f, 1.0f, 0.0f); glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(0, METER_HEIGHT); glVertex2i(unit, METER_HEIGHT); glVertex2i(unit, 0); glEnd(); int square_len = value_ >= max_value ? (max_value - 1) * unit : (value_ > 0 ? unit * (value_ - 1) : 0); glTranslatef(static_cast<float>(unit), 0.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f); // Forwards bit if (square_len > 0) { glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(0, METER_HEIGHT); glVertex2i(square_len, METER_HEIGHT); glVertex2i(square_len, 0); glEnd(); } const bool want_triangle = value_ < max_value && value_ > 0; if (want_triangle) { // Triangle bit glBegin(GL_TRIANGLES); glVertex2i(square_len, 0); glVertex2i(square_len, METER_HEIGHT); glVertex2i(square_len + unit, METER_HEIGHT / 2); glEnd(); } glPopMatrix(); }
void Compass::renderBackground(RenderContext& renderContext) { PreferenceManager& prefs = PreferenceManager::instance(); const MultiplyModelMatrix rotate(renderContext.transformation(), Mat4x4f::Rot90XCCW); ActiveShader shader(renderContext.shaderManager(), Shaders::CompassBackgroundShader); shader.set("Color", prefs.get(Preferences::CompassBackgroundColor)); m_backgroundRenderer.render(); shader.set("Color", prefs.get(Preferences::CompassBackgroundOutlineColor)); m_backgroundOutlineRenderer.render(); }
void SkyRenderer::Draw(RenderContext& renderContext, const SceneConstants& sceneConstants) { ID3D11DeviceContext& context = m_graphicsDevice.GetD3DContext(); // // Update the constant buffer. // m_constants.viewMatrix = sceneConstants.viewMatrix; m_constants.projectionMatrix = sceneConstants.projectionMatrix; D3D11_MAPPED_SUBRESOURCE map; D3DCHECK(m_graphicsDevice.GetD3DContext().Map(m_constantBuffer.get(), // pResource 0, // Subresource D3D11_MAP_WRITE_DISCARD, // MapType 0, // MapFlags &map)); // pMappedResource memcpy(map.pData, &m_constants, sizeof(m_constants)); m_graphicsDevice.GetD3DContext().Unmap(m_constantBuffer.get(), 0); // // Execute the render op. // ID3D11Buffer* vertexBufferPtr = m_shared->vertexBuffer.get(); size_t offset = 0, stride = sizeof(Vertex); ID3D11ShaderResourceView* shaderResourceViewPtrs[] = { m_shared->skyTextureView.get() }; ID3D11SamplerState* samplerPtr = m_shared->samplerState.get(); context.IASetVertexBuffers(0, 1, &vertexBufferPtr, &stride, &offset); context.IASetIndexBuffer(m_shared->indexBuffer.get(), DXGI_FORMAT_R16_UINT, 0); context.IASetInputLayout(m_shared->inputLayout.get()); context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ID3D11Buffer* constantBufferPtr = m_constantBuffer.get(); context.VSSetConstantBuffers(0, 1, &constantBufferPtr); context.VSSetShader(m_shared->vertexShader.get(), NULL, 0); context.GSSetShader(NULL, NULL, 0); context.PSSetShader(m_shared->pixelShader.get(), NULL, 0); context.PSSetShaderResources(0, 1, shaderResourceViewPtrs); context.PSSetSamplers(0, 1, &samplerPtr); renderContext.PushRasterizerState(m_shared->rasterizerState); renderContext.PushDepthStencilState(m_shared->depthStencilState); context.DrawIndexed(36, 0, 0); renderContext.PopRasterizerState(); renderContext.PopDepthStencilState(); }
void Force::render(RenderContext& context, const gameplay::Rectangle& rect) { context.activateLayer(m_tiler); std::vector<Unit*>::iterator it = m_units.begin(); std::vector<Unit*>::iterator last = m_units.end(); for (; it != last; it++) (*it)->render(context); context.deactivateLayer(); }
void ButtonUnit::onRender( RenderContext & context, const RectInt & window ) { WindowButton::onRender( context, window ); if ( enabled() && m_Unit.valid() ) { GameDocument * pDoc = (GameDocument *)document(); ASSERT( pDoc ); NounShip * pShip = pDoc->ship(); if (! pShip ) return; DisplayDevice * pDisplay = context.display(); ASSERT( pDisplay ); // draw the gadget icon if ( m_Icon.valid() ) { RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) ); RectFloat iconUV(0,0,1,1); Material::push( context, m_Icon ); PrimitiveWindow::push( pDisplay, iconBox, iconUV, pShip->isFriend( m_Unit ) ? GREEN : pShip->isEnemy( m_Unit ) ? RED : YELLOW ); } // draw the unit health on the button Font * pFont = windowStyle()->font(); ASSERT( pFont ); WideString sHealth; sHealth.format( STR("%d%%"), 100 - ((m_Unit->damage() * 100) / m_Unit->maxDamage()) ); SizeInt szHealth( pFont->size( sHealth ) ); PointInt ptHealth( window.right - szHealth.width, window.bottom - szHealth.height ); Font::push( context.display(), pFont, ptHealth, sHealth, WHITE ); // display damage bar if ( m_Unit->damage() > 0 ) { float damage = 1.0f - (m_Unit->damage() / m_Unit->maxDamage()); RectInt bar( window.m_Left, window.m_Bottom + 1, window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 ); RectFloat barUV(0,0,1,1); Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 ); PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE ); PrimitiveWindow::push( pDisplay, bar, barUV, barColor ); } // display blinking border if this unit is the current target if ( pDoc->target() == m_Unit && (pDoc->tick() % 10) < 6) renderGlow( context ); } }
void Material::createDevicePrimitives( RenderContext & context ) { DisplayDevice * pDisplay = context.display(); ASSERT( pDisplay ); m_Material = NULL; // clear any previous primitive pDisplay->create( m_Material ); if ( context.alpha() < 1.0f ) { m_Material->setMaterial( Color( m_Diffuse.r, m_Diffuse.g, m_Diffuse.b, (u8)(context.alpha() * m_Diffuse.a) ), m_Ambient, m_Emissive, m_Specular, m_SpecularPower ); m_Material->setPass( DisplayDevice::SECONDARY ); if ( m_Blending == PrimitiveMaterial::NONE ) m_Material->setBlending( PrimitiveMaterial::ALPHA ); else m_Material->setBlending( m_Blending ); } else { m_Material->setMaterial( m_Diffuse, m_Ambient, m_Emissive, m_Specular, m_SpecularPower ); m_Material->setPass( m_nPass ); m_Material->setBlending( m_Blending ); } m_Material->setLightEnable( m_LightEnable ); m_Material->setDoubleSided( m_DoubleSided ); if ( m_sShader.length() > 0 ) m_Material->setShader( m_sShader ); if (! m_bSurfaceReady ) createDeviceSurfaces( context.display() ); // attach the surfaces to the material now if ( m_Surfaces.size() > 0 ) { Array< PrimitiveSurface::Ref > & surfaces = m_Surfaces[ 0 ]; ASSERT( surfaces.size() == m_Textures.size() ); for(int i=0;i<surfaces.size();++i) { Texture & texture = m_Textures[ i ]; m_Material->addSurface( surfaces[i], texture.m_eType, texture.m_nIndex, texture.m_nUV, texture.m_fParams ); } } m_nLastFrame = 0; m_fLastAlpha = context.alpha(); }
Ref<Material> Material::read(RenderContext& context, const std::string& name) { initializeMaps(); if (Material* cached = context.cache().find<Material>(name)) return cached; const Path path = context.cache().findFile(name); if (path.isEmpty()) { logError("Failed to find material %s", name.c_str()); return nullptr; } pugi::xml_document document; const pugi::xml_parse_result result = document.load_file(path.name().c_str()); if (!result) { logError("Failed to load material %s: %s", name.c_str(), result.description()); return nullptr; } pugi::xml_node root = document.child("material"); if (!root || root.attribute("version").as_uint() != MATERIAL_XML_VERSION) { logError("Material file format mismatch in %s", name.c_str()); return nullptr; } Ref<Material> material = Material::create(ResourceInfo(context.cache(), name, path), context); for (auto pn : root.children("pass")) { const std::string phaseName(pn.attribute("phase").value()); if (!phaseMap.hasKey(phaseName)) { logError("Invalid render phase %s in material %s", phaseName.c_str(), name.c_str()); return nullptr; } if (!parsePass(context, material->pass(phaseMap[phaseName]), pn)) { logError("Failed to parse pass for material %s", name.c_str()); return nullptr; } } return material; }
bool Game::drawNode(RenderContext& context) { BOOST_ASSERT(context.getCurrentNode() != nullptr); auto dr = context.getCurrentNode()->getDrawable(); if( dr != nullptr ) { dr->draw(context); } return true; }
//--------------------------------------------------------------------------- void RenderableNodeSorter::Add(RenderableNode& r, RenderFlagsEnum rf, ShadersEnum shaderId) { assert(shaderId != Shaders::NONE); RenderContext* context = RenderContext::Inst(); bool selected = ( context->selection.find( r.objectId ) != context->selection.end() ); PrimitiveTypeEnum primtype = r.mesh->primitiveType; GlobalRenderFlagsEnum gflags = this->GetFlags(); bool triPrim = primtype == PrimitiveType::TriangleList || primtype == PrimitiveType::TriangleStrip; uint32_t mask =(uint32_t) ~(RenderFlags::Textured | RenderFlags::Lit); uint32_t flags = rf & (mask | gflags); flags |= (gflags & GlobalRenderFlags::RenderBackFace); bool wireflagset = (gflags & GlobalRenderFlags::WireFrame) != 0; if(triPrim) { if(gflags & GlobalRenderFlags::Solid) { Bucket& bucket = GetOrMakeBucket(flags, shaderId); bucket.renderables.push_back( r ); if(r.GetFlag(RenderableNode::kShadowCaster)) m_bounds.Extend(r.bounds); } if(selected || wireflagset) { RenderableNode node = r; node.diffuse = selected ? context->State()->GetSelectionColor() : context->State()->GetWireframeColor(); flags &= ~RenderFlags::AlphaBlend; Bucket& bucket = GetOrMakeBucket(flags, Shaders::WireFrameShader ); bucket.renderables.push_back( node ); } } else { flags &= ~RenderFlags::AlphaBlend; Bucket& bucket = GetOrMakeBucket(flags, shaderId); if(selected) { RenderableNode node = r; node.diffuse = context->State()->GetSelectionColor(); bucket.renderables.push_back( node); } else { bucket.renderables.push_back( r ); } } }
void DisplayObject::defaultRender(RenderContext& ctxt) const { const CachedSurface& surface=ctxt.getCachedSurface(this); /* surface is only modified from within the render thread * so we need no locking here */ if(!surface.tex.isValid()) return; ctxt.lsglLoadIdentity(); ctxt.renderTextured(surface.tex, surface.xOffset, surface.yOffset, surface.tex.width, surface.tex.height, surface.alpha, RenderContext::RGB_MODE); }
//---------------------------------------------------------------------------// RenderContext* RenderContext::AllocateContext() { if (!locAvailableRenderContexts.empty()) { RenderContext* context = locAvailableRenderContexts.front(); context->Reset(); locAvailableRenderContexts.pop_front(); return context; } locRenderContextPool.push_back(std::make_unique<RenderContext>()); return locRenderContextPool.back().get(); }
void EntityRenderer::render(RenderContext& context) { if (!m_boundsValid) validateBounds(context); if (!m_modelRendererCacheValid) validateModels(context); if (context.viewOptions().showEntityModels()) renderModels(context); if (context.viewOptions().showEntityBounds()) renderBounds(context); if (context.viewOptions().showEntityClassnames()) renderClassnames(context); }
void BaseNode::preRender( RenderContext &context, const Matrix33 & frame, const Vector3 & position ) { context.setInstanceKey( context.instanceKey() + key() ); if (! context.isShadowPass() || (m_nNodeFlags & NF_NOSHADOW) == 0 ) render( context, frame, position ); // recurse into the child nodes for(size_t i=0;i<m_Children.size();i++) m_Children[i]->preRender( context, frame, position ); context.setInstanceKey( context.instanceKey() - key() ); }
// All threads start execution here. int main() { if (__builtin_nyuzi_read_control_reg(0) == 0) init_vga(VGA_MODE_640x480); else workerThread(); startAllThreads(); RenderContext *context = new RenderContext(); RenderTarget *renderTarget = new RenderTarget(); Surface *colorBuffer = new Surface(kFbWidth, kFbHeight, (void*) 0x200000); Surface *depthBuffer = new Surface(kFbWidth, kFbHeight); renderTarget->setColorBuffer(colorBuffer); renderTarget->setDepthBuffer(depthBuffer); context->bindTarget(renderTarget); context->enableDepthBuffer(true); context->bindShader(new TextureShader()); const RenderBuffer kVertices(kCubeVertices, kNumCubeVertices, 5 * sizeof(float)); const RenderBuffer kIndices(kCubeIndices, kNumCubeIndices, sizeof(int)); context->bindVertexAttrs(&kVertices); Texture *texture = new Texture(); texture->setMipSurface(0, new Surface(128, 128, (void*) kTestTexture)); texture->enableBilinearFiltering(true); context->bindTexture(0, texture); Matrix projectionMatrix = Matrix::getProjectionMatrix(kFbWidth, kFbHeight); Matrix modelViewMatrix; Matrix rotationMatrix; modelViewMatrix = Matrix::getTranslationMatrix(Vec3(0.0f, 0.0f, -3.0f)); modelViewMatrix *= Matrix::getScaleMatrix(2.0f); modelViewMatrix *= Matrix::getRotationMatrix(M_PI / 3.5, Vec3(1, -1, 0)); rotationMatrix = Matrix::getRotationMatrix(M_PI / 8, Vec3(1, 1, 0.0f)); for (int frame = 0; frame < 1; frame++) { TextureUniforms uniforms; uniforms.fMVPMatrix = projectionMatrix * modelViewMatrix; context->bindUniforms(&uniforms, sizeof(uniforms)); context->clearColorBuffer(); context->drawElements(&kIndices); context->finish(); modelViewMatrix *= rotationMatrix; } return 0; }
Renderer::Renderer(const RenderContext &context) : m_currentFBOIndex(false), m_gBuffer(NULL), m_shaderGBuffer(NULL), m_ping(NULL), m_pong(NULL), m_firstRender(true), m_shaderSFQ(NULL), m_useDeferredShading(false), m_shaderDSLighting(NULL), m_shaderDSCompositing(NULL), m_dsLightRootNode(NULL), m_dsLightColor(NULL), m_useReflections(false), m_shaderRLR(NULL), m_useAntiAliasing(false), m_shaderFXAA(NULL), m_useBloom(false), m_shaderBloom(NULL), m_useBlur(false), m_shaderBlur(NULL), m_useRadialBlur(false), m_shaderRadialBlur(NULL), m_useDoF(false), m_shaderDoF(NULL), m_shaderDepth(NULL), m_useSSAO(false), m_shaderSSAOcalc(NULL), m_shaderSSAOblur(NULL), m_shaderSSAOfinal(NULL), m_useShadowMapping(false), m_shaderShadowMapping(NULL), m_smCam(NULL), m_currentViewMatrix(glm::mat4()), m_currentProjectionMatrix(glm::mat4()), m_windowWidth(0), m_windowHeight(0) { m_sfq.loadBufferData(); context.bindContext(); printInfo(); }
void PointHandleHighlightFigure::render(Vbo& vbo, RenderContext& context) { float factor = context.camera().distanceTo(m_position) * m_scalingFactor; Mat4f billboardMatrix = context.camera().billboardMatrix(); Mat4f matrix = Mat4f::Identity; matrix.translate(m_position); matrix *= billboardMatrix; matrix.scale(Vec3f(factor, factor, 0.0f)); ApplyMatrix applyBillboard(context.transformation(), matrix); ActivateShader shader(context.shaderManager(), Shaders::HandleShader); shader.currentShader().setUniformVariable("Color", m_color); CircleFigure circle(Axis::AZ, 0.0f, 2.0f * Math::Pi, 2.0f * m_radius, 16, false); circle.render(vbo, context); }
void Material::apply(const RenderContext& renderContext) const { assert(renderContext.pCamera); mGPUProgram.use(); auto& it = mTextures.find(TextureType::DIFFUSE_MAP); if (it != mTextures.end()) { it->second->bind(GL_TEXTURE0); mGPUProgram.setUniform("DiffuseMap", 0); } it = mTextures.find(TextureType::NORMAL_MAP); if (it != mTextures.end()) { it->second->bind(GL_TEXTURE1); mGPUProgram.setUniform("NormalMap", 1); } it = mTextures.find(TextureType::SPECULAR_MAP); if (it != mTextures.end()) { it->second->bind(GL_TEXTURE2); mGPUProgram.setUniform("SpecularMap", 2); } glm::mat4 worldMatrix = renderContext.getCurrentWorldMatrix(); glm::mat4 wvpMatrix = renderContext.pCamera->getViewProjectionMatrix() * worldMatrix; mGPUProgram.setUniform("WorldMatrix", worldMatrix); mGPUProgram.setUniform("WVPMatrix", wvpMatrix); mGPUProgram.setUniform("CameraPosition", renderContext.pCamera->getPosition()); mGPUProgram.setUniform("Time", renderContext.Time); }
void EditorRootStage::onRender(RenderContext& context) const { context.bind([&](Painter& painter) { auto view = Rect4f(painter.getViewPort()); // Background Sprite bg = background; bg.setTexRect(view).setSize(view.getSize()).draw(painter); halleyLogo.clone().setPos(Vector2f(getVideoAPI().getWindow().getDefinition().getSize() / 2)).draw(painter); // UI SpritePainter spritePainter; spritePainter.start(100); ui->draw(spritePainter, 0, 0); spritePainter.draw(0, painter); // Taskbar taskBar->draw(painter); if (console) { console->draw(painter, Rect4f(view.getTopLeft() + Vector2f(16, 16), view.getBottomRight() - Vector2f(16, 80))); } }); }
Color LambertianMaterial::shade(const RenderContext& rc, const Ray& ray, const HitRecord& hrec, int depth) const{ Point hp = ((Ray&)ray).pointOn(((HitRecord&)hrec).GetT()); Vector normal = ((HitRecord&)hrec).GetPrimitive()->normal(hp); hp += 0.0001f * normal; Scene* scene = (Scene*)rc.getScene(); int numlights = scene->num_lights(); Color finalc(0.f,0.f,0.f); for(int i=0; i<numlights; i++){ Vector ldir; Color lcolor; float ldist = scene->get_light(i)->getLight(lcolor, ldir, rc, hp); HitRecord shadowhr; Ray shadowray(hp, ldir); scene->get_object()->intersect(shadowhr, rc, shadowray); if(shadowhr.GetT()>=ldist || shadowhr.GetT()<0.01){ float dp = dot(normal, ldir); if(dp > 0) finalc += dp*lcolor; } } return color*(finalc*kd + scene->get_ambient()*ka); }
void LinesRenderer::render(Vbo& vbo, RenderContext& context) { Renderer::SetVboState activateVbo(vbo, Renderer::Vbo::VboActive); if (!m_valid) { delete m_vertexArray; m_vertexArray = NULL; if (!m_vertices.empty()) { Renderer::SetVboState mapVbo(vbo, Renderer::Vbo::VboMapped); m_vertexArray = new VertexArray(vbo, GL_LINES, static_cast<unsigned int>(m_vertices.size()), Attribute::position3f(), 0); m_vertexArray->addAttributes(m_vertices); m_vertices.clear(); m_valid = true; } } if (m_vertexArray != NULL) { Renderer::glSetEdgeOffset(0.3f); Renderer::ActivateShader handleShader(context.shaderManager(), Renderer::Shaders::HandleShader); glDisable(GL_DEPTH_TEST); handleShader.setUniformVariable("Color", m_occludedColor); m_vertexArray->render(); glEnable(GL_DEPTH_TEST); handleShader.setUniformVariable("Color", m_color); m_vertexArray->render(); Renderer::glResetEdgeOffset(); } }
void Blend::Execute(RenderContext& context) { gxeng::GraphicsCommandList& commandList = context.AsGraphics(); auto* pRTV = &m_blendDest; commandList.SetResourceState(pRTV->GetResource(), gxapi::eResourceState::RENDER_TARGET); commandList.SetRenderTargets(1, &pRTV); gxapi::Rectangle rect{ 0, (int)pRTV->GetResource().GetHeight(), 0, (int)pRTV->GetResource().GetWidth() }; gxapi::Viewport viewport; viewport.width = (float)rect.right; viewport.height = (float)rect.bottom; viewport.topLeftX = 0; viewport.topLeftY = 0; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; commandList.SetScissorRects(1, &rect); commandList.SetViewports(1, &viewport); commandList.SetPipelineState(m_PSO.get()); commandList.SetGraphicsBinder(&m_binder); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLELIST); commandList.SetResourceState(const_cast<Texture2D&>(m_blendSrc.GetResource()), { gxapi::eResourceState::PIXEL_SHADER_RESOURCE, gxapi::eResourceState::NON_PIXEL_SHADER_RESOURCE }); commandList.BindGraphics(m_tex0Param, m_blendSrc); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLESTRIP); commandList.DrawInstanced(4); }
void EntityRenderer::validateBounds(RenderContext& context) { delete m_boundsVertexArray; m_boundsVertexArray = NULL; Model::EntityList entities; Model::EntitySet::iterator entityIt, entityEnd; for (entityIt = m_entities.begin(), entityEnd = m_entities.end(); entityIt != entityEnd; ++entityIt) { Model::Entity* entity = *entityIt; if (context.filter().entityVisible(*entity)) entities.push_back(entity); } if (entities.empty()) return; SetVboState mapVbo(m_boundsVbo, Vbo::VboMapped); if (m_overrideBoundsColor) { unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size()); m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount, Attribute::position3f()); writeBounds(context, entities); } else { unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size()); m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount, Attribute::position3f(), Attribute::color4f()); writeColoredBounds(context, entities); } m_boundsValid = true; }