QT-地形3D

QT-地形3D

一、 演示效果


二、关键程序

c 复制代码
#include "ShaderProgram.h"

namespace t3d::core
{

void ShaderProgram::init()
{
    initializeOpenGLFunctions();
    loadShaders();
}

void ShaderProgram::addShader(const QString &filename, QOpenGLShader::ShaderType shaderType)
{
    QOpenGLShader *shader = new QOpenGLShader(shaderType, mProgram.get());
    if (!shader->compileSourceFile(gDefaultPathShaders + filename))
        qDebug() << "Error compiling shader " << filename << " of type "
                 << static_cast<int>(shaderType);

    if (!mProgram->addShader(shader))
        qDebug() << "Error adding shader " << filename << " of type "
                 << static_cast<int>(shaderType);
}

void ShaderProgram::loadShaders()
{
    mProgram = makeUnique<QOpenGLShaderProgram>();
    addShaders();

    if (mProgram->link() == false)
        qFatal("Problem linking shaders");
    else
        qDebug() << "Initialized shaders";

    mProgram->bind();
    queryUniformLocations();
    refreshUniformValues();
    flushQueuedUniformValueChanges();
    mProgram->release();
}

bool ShaderProgram::bind()
{
    if (!mProgram->bind())
    {
        System::warn("Unable to bind OpenGL ShaderProgram");
        return false;
    }

    flushQueuedUniformValueChanges();

    return true;
}

void ShaderProgram::reloadShaders()
{
    loadShaders();
}

void ShaderProgram::enqueueUniformValueChange(const GLint *uniformLocation, QVariant value)
{
    if (mProgram && mProgram->isLinked())
    {
        mProgram->bind();
        setUniformFromQVariant(*uniformLocation, value);
        mProgram->release(); // TODO this can cause issues if used while the program was bound
                             // externally
    }
    else
        mQueuedUniformValueChanges.append(QPair<const GLint *, QVariant>(uniformLocation, value));
}

void ShaderProgram::setUniformFromQVariant(GLint location, QVariant &value)
{
    switch (static_cast<QMetaType::Type>(value.type()))
    {
    case QMetaType::Int:
        mProgram->setUniformValue(location, static_cast<GLint>(value.toInt()));
        break;
    case QMetaType::Double:
        mProgram->setUniformValue(location, static_cast<GLfloat>(value.toDouble()));
        break;
    case QMetaType::Float:
        mProgram->setUniformValue(location, static_cast<GLfloat>(value.toFloat()));
        break;
    default:
        qFatal("Trying to set a queued shader uniform value for an unknown type");
        // TODO this is all we support. Eventuall QOpenGLShaderProgram should support
        // setUniformValue directly from a QVariant.
    }
}

void ShaderProgram::flushQueuedUniformValueChanges()
{
    for (auto pair : mQueuedUniformValueChanges)
    {
        setUniformFromQVariant(*pair.first, pair.second);
    }

    mQueuedUniformValueChanges.clear();
}

}

三、下载链接

https://download.csdn.net/download/u013083044/88850945

相关推荐
CodeCraft Studio2 小时前
PPT处理控件Aspose.Slides教程:在 C# 中将 PPTX 转换为 Markdown
开发语言·c#·powerpoint·markdown·ppt·aspose·ai大模型
萧鼎3 小时前
深入理解 Python Scapy 库:网络安全与协议分析的瑞士军刀
开发语言·python·web安全
阿拉丁的梦5 小时前
教程1:用vscode->ptvsd-创建和调试一个UI(python)-转载官方翻译(有修正)
开发语言·python
木宇(记得热爱生活)5 小时前
一键搭建开发环境:制作bash shell脚本
开发语言·bash
Cisyam^6 小时前
Go环境搭建实战:告别Java环境配置的复杂
java·开发语言·golang
IAR Systems7 小时前
在IAR Embedded Workbench for Arm中实现Infineon TRAVEO™ T2G安全调试
开发语言·arm开发·安全·嵌入式软件开发·iar
jayzhang_7 小时前
SPARK入门
大数据·开发语言
蹦极的考拉7 小时前
网站日志里面老是出现{pboot:if((\x22file_put_co\x22.\x22ntents\x22)(\x22temp.php\x22.....
android·开发语言·php
fured7 小时前
[调试][实现][原理]用Golang实现建议断点调试器
开发语言·后端·golang
大翻哥哥8 小时前
Python地理空间数据分析:从地图绘制到智能城市应用
开发语言·python·数据分析