void GLTerrainRect::render() { if(!initalised()) initGL(); QOpenGLFunctions * f = QOpenGLContext::currentContext()->functions(); f->glEnable(GL_BLEND);CE(); f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);CE(); m_vao_constraints.bind();CE(); f->glDrawElements(GL_TRIANGLE_STRIP, m_indicies.size(), GL_UNSIGNED_INT, (void*)(0)); CE();CE(); m_vao_constraints.release();CE(); f->glDisable(GL_BLEND);CE(); }
void Shader::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) { Q_UNUSED(oldMaterial); Q_ASSERT(program()->isLinked()); Material* m = static_cast<Material*>(newMaterial); program()->setUniformValue(m_id_matrix, state.combinedMatrix()*m->transformation); if (state.isOpacityDirty()) { program()->setUniformValue(m_id_opacity, state.opacity()); } program()->setUniformValue(m_id_color, m->color); m_glFuncs->glBlendFunc(GL_ONE, GL_ONE); m_glFuncs->glEnable(GL_POINT_SPRITE); // glPointSize(m->pointSize); // Commenting this out since it is not available in QOpenGLFunctions (OpenGL ES 2.0) and apparently does not affect the point size }
void QtViewRenderer::render() { QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions(); OpenGLStateSaver state(f); f->glEnable(GL_BLEND); f->glBlendEquation(GL_FUNC_ADD); f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); f->glDisable(GL_CULL_FACE); f->glDisable(GL_DEPTH_TEST); f->glActiveTexture(GL_TEXTURE0); glClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, m_width, m_height); QMatrix4x4 ortho; ortho.ortho(m_viewBounds[0], m_viewBounds[2], m_viewBounds[3], m_viewBounds[1], -1, 1); m_shader->bind(); m_shader->setUniformValue(m_locationTex, 0); m_shader->setUniformValue(m_locationProjMtx, ortho); m_VAO->bind(); int vboSize = 0, eboSize = 0; for (const auto cmd_list : m_drawLists) { if (cmd_list->vtxBuffer().empty() || cmd_list->idxBuffer().empty()) continue; const DrawList::DrawIdx* idx_buffer_offset = nullptr; m_VBO->bind(); int vtxSize = cmd_list->vtxBuffer().size() * sizeof(DrawList::DrawVert); if (vtxSize > vboSize) { m_VBO->allocate(vtxSize); vboSize = vtxSize; } m_VBO->write(0, &cmd_list->vtxBuffer().front(), vtxSize); m_EBO->bind(); int idxSize = cmd_list->idxBuffer().size() * sizeof(DrawList::DrawIdx); if (idxSize > eboSize) { m_EBO->allocate(idxSize); eboSize = idxSize; } m_EBO->write(0, &cmd_list->idxBuffer().front(), idxSize); for (const auto& pcmd : cmd_list->cmdBuffer()) { glBindTexture(GL_TEXTURE_2D, pcmd.textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(pcmd.elemCount), GL_UNSIGNED_INT, idx_buffer_offset); idx_buffer_offset += pcmd.elemCount; } } m_shader->release(); m_VAO->release(); }