void ApplicationOverlay::renderDomainConnectionStatusBorder(RenderArgs* renderArgs) { auto geometryCache = DependencyManager::get<GeometryCache>(); static std::once_flag once; std::call_once(once, [&] { QVector<vec2> points; static const float B = 0.99f; points.push_back(vec2(-B)); points.push_back(vec2(B, -B)); points.push_back(vec2(B)); points.push_back(vec2(-B, B)); points.push_back(vec2(-B)); geometryCache->updateVertices(_domainStatusBorder, points, CONNECTION_STATUS_BORDER_COLOR); }); auto nodeList = DependencyManager::get<NodeList>(); if (nodeList && !nodeList->getDomainHandler().isConnected()) { gpu::Batch& batch = *renderArgs->_batch; auto geometryCache = DependencyManager::get<GeometryCache>(); geometryCache->useSimpleDrawPipeline(batch); batch.setProjectionTransform(mat4()); batch.setModelTransform(Transform()); batch.setViewTransform(Transform()); batch.setResourceTexture(0, DependencyManager::get<TextureCache>()->getWhiteTexture()); // FIXME: THe line width of CONNECTION_STATUS_BORDER_LINE_WIDTH is not supported anymore, we ll need a workaround // TODO animate the disconnect border for some excitement while not connected? //double usecs = usecTimestampNow(); //double secs = usecs / 1000000.0; //float scaleAmount = 1.0f + (0.01f * sin(secs * 5.0f)); //batch.setModelTransform(glm::scale(mat4(), vec3(scaleAmount))); geometryCache->renderVertices(batch, gpu::LINE_STRIP, _domainStatusBorder); } }
void SkeletonModel::renderJointConstraints(gpu::Batch& batch, int jointIndex) { if (jointIndex == -1 || jointIndex >= _jointStates.size()) { return; } const FBXGeometry& geometry = _geometry->getFBXGeometry(); const float BASE_DIRECTION_SIZE = 0.3f; float directionSize = BASE_DIRECTION_SIZE * extractUniformScale(_scale); batch._glLineWidth(3.0f); do { const FBXJoint& joint = geometry.joints.at(jointIndex); const JointState& jointState = _jointStates.at(jointIndex); glm::vec3 position = _rotation * jointState.getPosition() + _translation; glm::quat parentRotation = (joint.parentIndex == -1) ? _rotation : _rotation * _jointStates.at(joint.parentIndex).getRotation(); float fanScale = directionSize * 0.75f; Transform transform = Transform(); transform.setTranslation(position); transform.setRotation(parentRotation); transform.setScale(fanScale); batch.setModelTransform(transform); const int AXIS_COUNT = 3; auto geometryCache = DependencyManager::get<GeometryCache>(); for (int i = 0; i < AXIS_COUNT; i++) { if (joint.rotationMin[i] <= -PI + EPSILON && joint.rotationMax[i] >= PI - EPSILON) { continue; // unconstrained } glm::vec3 axis; axis[i] = 1.0f; glm::vec3 otherAxis; if (i == 0) { otherAxis.y = 1.0f; } else { otherAxis.x = 1.0f; } glm::vec4 color(otherAxis.r, otherAxis.g, otherAxis.b, 0.75f); QVector<glm::vec3> points; points << glm::vec3(0.0f, 0.0f, 0.0f); const int FAN_SEGMENTS = 16; for (int j = 0; j < FAN_SEGMENTS; j++) { glm::vec3 rotated = glm::angleAxis(glm::mix(joint.rotationMin[i], joint.rotationMax[i], (float)j / (FAN_SEGMENTS - 1)), axis) * otherAxis; points << rotated; } // TODO: this is really inefficient constantly recreating these vertices buffers. It would be // better if the skeleton model cached these buffers for each of the joints they are rendering geometryCache->updateVertices(_triangleFanID, points, color); geometryCache->renderVertices(batch, gpu::TRIANGLE_FAN, _triangleFanID); } renderOrientationDirections(jointIndex, position, _rotation * jointState.getRotation(), directionSize); jointIndex = joint.parentIndex; } while (jointIndex != -1 && geometry.joints.at(jointIndex).isFree); }
void PerlinFace::update() { if (!_initialized) { init(); } updatePositions(); updateVertices(); glBindBuffer(GL_ARRAY_BUFFER, _vboID); glBufferData(GL_ARRAY_BUFFER, FLOAT_PER_VERTEX * VERTEX_PER_TRIANGLE * _trianglesCount * sizeof(GLfloat), _triangles, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, _nboID); glBufferData(GL_ARRAY_BUFFER, FLOAT_PER_VERTEX * VERTEX_PER_TRIANGLE * _trianglesCount * sizeof(GLfloat), _normals, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, _cboID); glBufferData(GL_ARRAY_BUFFER, FLOAT_PER_VERTEX * VERTEX_PER_TRIANGLE * _trianglesCount * sizeof(GLubyte), _colors, GL_DYNAMIC_DRAW); }
void wySpriteEx::updateTransform() { if(!m_useBatchNode) { LOGW("This func only applies to sprite using batchnode"); return; } if(!m_texDirty && !m_colorDirty && !m_transformDirty) { return; } if(m_texDirty || m_transformDirty) { if(m_transformDirty) { wyAffineTransform t = getNodeToBatchNodeTransform(); updateVertices(t); } if(m_texDirty) updateTextureCoords(); m_batchNode->m_atlas->updateQuad(m_texCoords, m_vertices, m_atlasIndex); } if(m_colorDirty) { updateColor(); } m_texDirty = m_colorDirty = m_transformDirty = false; }
void MetaballParticleSystem::render(sf::RenderTarget &renderTarget) { updateVertices(); if (m_particles->countAlive <= 0) return; sf::RenderStates states = sf::RenderStates::Default; states.blendMode = sf::BlendAdd; states.texture = m_texture; const sf::Vertex *ver = &m_vertices[0]; sf::View oldView = renderTarget.getView(); sf::View defaultView = renderTarget.getDefaultView(); m_renderTexture.setView(oldView); m_renderTexture.clear(sf::Color(0, 0, 0, 0)); m_renderTexture.draw(ver, m_particles->countAlive * 4, sf::Quads, states); m_renderTexture.display(); m_sprite.setTexture(m_renderTexture.getTexture()); sf::Glsl::Vec4 colorVec = sf::Glsl::Vec4(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f); m_shader.setUniform("customColor", colorVec); m_shader.setUniform("threshold", threshold); renderTarget.setView(defaultView); renderTarget.draw(m_sprite, &m_shader); renderTarget.setView(oldView); }
CircleRB::CircleRB(float xPosition, float yPosition, float xVelocity, float yVelocity, float radius, float angularPosition, float angularVelocity, float m, float frictionCoeff, float gravityResistance, float elasticity, RungeKuttaODESolver *odeSolver) { r = radius; criticalRadius = radius; xPos = xPosition; yPos = yPosition; xVel = xVelocity; yVel = yVelocity; angularPos = angularPosition; angularVel = angularVelocity; mass = m; friction = frictionCoeff; gravityScale = gravityResistance; e = elasticity; momentOfInertia = mass*(2.0f*r*r)/12.0f; oneOverMass = 1.0f/mass; oneOverI = 1.0f/momentOfInertia; Tx = 0.0f; Ty = 0.0f; Rx = 0.0f; Ry = 0.0f; solver = odeSolver; nVertices = nVert+1; vertices = vector<float>(nVertices*2,0.0f); updateVertices(); color[0] = 0.1; color[1] = 0.6; color[2] = 0.8; }
void Particle::step(float dtime) { m_time += dtime; if (m_collisiondetection) { core::aabbox3d<f32> box = m_collisionbox; v3f p_pos = m_pos*BS; v3f p_velocity = m_velocity*BS; v3f p_acceleration = m_acceleration*BS; collisionMoveSimple(m_env, m_gamedef, BS*0.5, box, 0, dtime, p_pos, p_velocity, p_acceleration); m_pos = p_pos/BS; m_velocity = p_velocity/BS; m_acceleration = p_acceleration/BS; } else { m_velocity += m_acceleration * dtime; m_pos += m_velocity * dtime; } // Update lighting updateLight(); // Update model updateVertices(); }
void Particle::step(float dtime) { m_time += dtime; if (m_collisiondetection) { aabb3f box = m_collisionbox; v3f p_pos = m_pos * BS; v3f p_velocity = m_velocity * BS; collisionMoveResult r = collisionMoveSimple(m_env, m_gamedef, BS * 0.5, box, 0, dtime, &p_pos, &p_velocity, m_acceleration * BS); if (m_collision_removal && r.collides) { // force expiration of the particle m_expiration = -1.0; } else { m_pos = p_pos / BS; m_velocity = p_velocity / BS; } } else { m_velocity += m_acceleration * dtime; m_pos += m_velocity * dtime; } // Update lighting updateLight(); // Update model updateVertices(); }
Vector3 FlexAirfoil::flexit() { Vector3 center; if (smanager->getShadowTechnique()==SHADOWTYPE_STENCIL_MODULATIVE || smanager->getShadowTechnique()==SHADOWTYPE_STENCIL_ADDITIVE) { center=updateShadowVertices(); //find the binding unsigned posbinding=msh->sharedVertexData->vertexDeclaration->findElementBySemantic(VES_POSITION)->getSource(); HardwareVertexBufferSharedPtr pbuf=msh->sharedVertexData->vertexBufferBinding->getBuffer(posbinding); //pbuf->lock(HardwareBuffer::HBL_NORMAL); pbuf->writeData(0, pbuf->getSizeInBytes(), shadowposvertices, true); //pbuf->unlock(); //find the binding unsigned norbinding=msh->sharedVertexData->vertexDeclaration->findElementBySemantic(VES_NORMAL)->getSource(); HardwareVertexBufferSharedPtr nbuf=msh->sharedVertexData->vertexBufferBinding->getBuffer(norbinding); //nbuf->lock(HardwareBuffer::HBL_NORMAL); nbuf->writeData(0, nbuf->getSizeInBytes(), shadownorvertices, true); //nbuf->unlock(); EdgeData * ed=msh->getEdgeList(); ed->updateFaceNormals(0, pbuf); } else { center=updateVertices(); //vbuf->lock(HardwareBuffer::HBL_NORMAL); vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true); //vbuf->unlock(); //msh->sharedVertexData->vertexBufferBinding->getBuffer(0)->writeData(0, vbuf->getSizeInBytes(), vertices, true); } return center; }
void Rectangle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec3 position = getPosition(); glm::vec2 dimensions = getDimensions(); glm::vec2 halfDimensions = dimensions * 0.5f; glm::quat rotation = getRotation(); auto batch = args->_batch; if (batch) { Transform transform; transform.setTranslation(position); transform.setRotation(rotation); batch->setModelTransform(transform); auto geometryCache = DependencyManager::get<GeometryCache>(); if (getIsSolid()) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->bindSimpleProgram(*batch); geometryCache->renderQuad(*batch, topLeft, bottomRight, rectangleColor); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f); glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor); geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor); geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor); geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor); } else { if (halfDimensions != _previousHalfDimensions) { QVector<glm::vec3> border; border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); geometryCache->updateVertices(_geometryCacheID, border, rectangleColor); _previousHalfDimensions = halfDimensions; } geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID); } } } }
inline void vertex_buffer_object<Ta, Te>::update() { updateVertices(); updateNormals(); updateColors(); updateTexCoords(); updateElements(); }
bool BoneNode::init() { _rackLength = 50; _rackWidth = 20; updateVertices(); updateColor(); setGLProgramState(cocos2d::GLProgramState::getOrCreateWithGLProgramName(cocos2d::GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP)); return true; }
void AudioScope::renderLineStrip(gpu::Batch& batch, int id, const glm::vec4& color, int x, int y, int n, int offset, const QByteArray* byteArray) { int16_t sample; int16_t* samples = ((int16_t*) byteArray->data()) + offset; int numSamplesToAverage = _framesPerScope / DEFAULT_FRAMES_PER_SCOPE; int count = (n - offset) / numSamplesToAverage; int remainder = (n - offset) % numSamplesToAverage; y += SCOPE_HEIGHT / 2; auto geometryCache = DependencyManager::get<GeometryCache>(); QVector<glm::vec2> points; // Compute and draw the sample averages from the offset position for (int i = count; --i >= 0; ) { sample = 0; for (int j = numSamplesToAverage; --j >= 0; ) { sample += *samples++; } sample /= numSamplesToAverage; points << glm::vec2(x++, y - sample); } // Compute and draw the sample average across the wrap boundary if (remainder != 0) { sample = 0; for (int j = remainder; --j >= 0; ) { sample += *samples++; } samples = (int16_t*) byteArray->data(); for (int j = numSamplesToAverage - remainder; --j >= 0; ) { sample += *samples++; } sample /= numSamplesToAverage; points << glm::vec2(x++, y - sample); } else { samples = (int16_t*) byteArray->data(); } // Compute and draw the sample average from the beginning to the offset count = (offset - remainder) / numSamplesToAverage; for (int i = count; --i >= 0; ) { sample = 0; for (int j = numSamplesToAverage; --j >= 0; ) { sample += *samples++; } sample /= numSamplesToAverage; points << glm::vec2(x++, y - sample); } geometryCache->updateVertices(id, points, color); geometryCache->renderVertices(batch, gpu::LINE_STRIP, id); }
Particle::Particle( IGameDef *gamedef, scene::ISceneManager* smgr, LocalPlayer *player, ClientEnvironment *env, v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, bool vertical, video::ITexture *texture, v2f texpos, v2f texsize ): scene::ISceneNode(smgr->getRootSceneNode(), smgr) { // Misc m_gamedef = gamedef; m_env = env; // Texture m_material.setFlag(video::EMF_LIGHTING, false); m_material.setFlag(video::EMF_BACK_FACE_CULLING, false); m_material.setFlag(video::EMF_BILINEAR_FILTER, false); m_material.setFlag(video::EMF_FOG_ENABLE, true); m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; m_material.setTexture(0, texture); m_texpos = texpos; m_texsize = texsize; // Particle related m_pos = pos; m_velocity = velocity; m_acceleration = acceleration; m_expiration = expirationtime; m_time = 0; m_player = player; m_size = size; m_collisiondetection = collisiondetection; m_collision_removal = collision_removal; m_vertical = vertical; // Irrlicht stuff m_collisionbox = aabb3f (-size/2,-size/2,-size/2,size/2,size/2,size/2); this->setAutomaticCulling(scene::EAC_OFF); // Init lighting updateLight(); // Init model updateVertices(); }
void RenderablePolyLineEntityItem::update(const quint64& now) { PolyLineUniforms uniforms; uniforms.color = toGlm(getXColor()); memcpy(&_uniformBuffer.edit<PolyLineUniforms>(), &uniforms, sizeof(PolyLineUniforms)); if (_pointsChanged || _strokeWidthsChanged || _normalsChanged) { updateVertices(); updateGeometry(); } }
/** * Update the modl state */ void Dodecahedron::update() { radius = 300 * get( "radius" ); modelRotation = 64 * Vec3f( get( "rotationX" ) , get( "rotationY" ) , get( "rotationZ" ) ); edgesColor = ColorAf( get( "edgeColorR" ) , get( "edgeColorG" ) , get( "edgeColorB" ) ); updateVertices(); calcWallCenters(); calcWallCoordinateSystems(); }
void PointParticleSystem::render(sf::RenderTarget &renderTarget) { updateVertices(); if (m_particles->countAlive <= 0) return; sf::RenderStates states = sf::RenderStates::Default; const sf::Vertex *ver = &m_vertices[0]; renderTarget.draw(ver, m_particles->countAlive, sf::Points, states); }
void updateVertices(const QTransform &t, ShaderType type) { if (shader[type] != currentShader) currentShader = shader[type]; updateVertices(t); if (!currentShader->bind()) qWarning() << __func__ << "failed to bind shader program"; currentShader->setWorldMatrix(worldMatrix); }
void RenderableLineEntityItem::updateGeometry() { auto geometryCache = DependencyManager::get<GeometryCache>(); if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { _lineVerticesID = geometryCache ->allocateID(); } if (_pointsChanged) { glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); _pointsChanged = false; } }
void wyGradientColorLayer::setContentSize(float w, float h) { // 原始位置opengl顶点,依次为左上,左下,右上,右下 if (m_originalVertices != NULL) { m_originalVertices[1] = h; m_originalVertices[4] = w; m_originalVertices[5] = h; m_originalVertices[6] = w; } wyLayer::setContentSize(w, h); updateVertices(); }
GuiSprite::GuiSprite() { model.setNew(); std::vector<unsigned int> indices(6); indices[0] = 0; indices[1] = 3; indices[2] = 2; indices[3] = 2; indices[4] = 1; indices[5] = 0; model->setIndices(indices); updateVertices(); }
void updateVertices(const QTransform &t, GLuint customShaderId) { if (!customShaderId) return; MShaderProgram* frag = customShadersById.value(customShaderId, 0); if (!frag) return; currentShader = frag; updateVertices(t); if (!currentShader->bind()) qWarning() << __func__ << "failed to bind shader program"; currentShader->setWorldMatrix(worldMatrix); }
bool BlockPlaneIntersectionGeometry::initialize() { if (_vaoId == 0) glGenVertexArrays(1, &_vaoId); if (_vBufferId == 0) { glGenBuffers(1, &_vBufferId); if (_vBufferId == 0) { LERROR("Could not create vertex buffer"); return false; } } updateVertices(); return true; }
void SpriteSheetParticleSystem::render(sf::RenderTarget &renderTarget) { updateVertices(); if (m_particles->countAlive <= 0) return; sf::RenderStates states = sf::RenderStates::Default; if (additiveBlendMode) { states.blendMode = sf::BlendAdd; } states.texture = m_texture; const sf::Vertex *ver = &m_vertices[0]; renderTarget.draw(ver, m_particles->countAlive * 4, sf::Quads, states); }
void MeshView::partialUpdate( const FractalData* data ) { if ( m_resolution.isNull() || m_resolution != data->size() ) return; const QList<QRect> validRegions = data->validRegions(); if ( validRegions.count() > 0 && validRegions.first().top() == 0 && validRegions.first().bottom() > m_updatedRegion.bottom() ) { int top = m_updatedRegion.bottom() + 1; QRect region( 0, top, validRegions.first().width(), validRegions.first().bottom() - top + 1 ); updateVertices( data, region ); m_updatedRegion = validRegions.first(); updateGL(); } }
void render(void) { DMAPoolBuffer *dma = updateVertices(0.2, 0.8, 0.2, 0, 0); int row; trashBuffer(); uploadRow(0, dma); for (row = 1; row < MESH_HEIGHT; row++) { uploadRow(row, dma); drawStrip(row - 1); } SVGA3DUtil_AsyncCall((AsyncCallFn) SVGA3DUtil_DMAPoolFreeBuffer, dma); }
void NinePatch::update(const TexturePtr& tex, const Vec2& inSize, float l, float r, float t, float b) { size = inSize; left = l; right = r; top = t; bottom = b; material->setTexture(0, tex); updateVertices(); updateTexCoords(); }
void SGBox::setMaxZ(Real z) { // v0, v1, v2, v3, v4, v5, v14, v15, v17, v19, v20, v22 mVertices[0].position.z() = z; mVertices[1].position.z() = z; mVertices[2].position.z() = z; mVertices[3].position.z() = z; mVertices[4].position.z() = z; mVertices[5].position.z() = z; mVertices[14].position.z() = z; mVertices[15].position.z() = z; mVertices[17].position.z() = z; mVertices[19].position.z() = z; mVertices[20].position.z() = z; mVertices[22].position.z() = z; updateVertices(); }
void SGBox::setMaxY(Real y) { // v0, v2, v4, v6, v8, v10, v12, v14, v16, v17, v18, v19 mVertices[0].position.y() = y; mVertices[2].position.y() = y; mVertices[4].position.y() = y; mVertices[6].position.y() = y; mVertices[8].position.y() = y; mVertices[10].position.y() = y; mVertices[12].position.y() = y; mVertices[14].position.y() = y; mVertices[16].position.y() = y; mVertices[17].position.y() = y; mVertices[18].position.y() = y; mVertices[19].position.y() = y; updateVertices(); }
void SGBox::setMinZ(Real z) { // v6, v7, v8, v9, v10, v11, v12, v13, v16, v18, v21, v23 mVertices[6].position.z() = z; mVertices[7].position.z() = z; mVertices[8].position.z() = z; mVertices[9].position.z() = z; mVertices[10].position.z() = z; mVertices[11].position.z() = z; mVertices[12].position.z() = z; mVertices[13].position.z() = z; mVertices[16].position.z() = z; mVertices[18].position.z() = z; mVertices[21].position.z() = z; mVertices[23].position.z() = z; updateVertices(); }