QT-地形3D
- 一、 演示效果
- 二、关键程序
- 三、下载链接
一、 演示效果
二、关键程序
#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_castint>(shaderType);
if (!mProgram->addShader(shader))
qDebug() "Error adding shader " filename " of type "
static_castint>(shaderType);
}
void ShaderProgram::loadShaders()
{
mProgram = makeUniqueQOpenGLShaderProgram>();
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->isLink服务器托管网ed())
{
mProgram->bind();
setUniformFromQVariant(*uniformLocation, value);
mProgram->release(); // TODO this can cause issues if used while the program was bound
// externally
}
else
mQueuedUniformValueChanges.append(QPairconst GLint *, QVariant>(uniformLocation, value));
}
void ShaderProgram::setUniformFromQVariant(GLint location, QVariant &服务器托管网amp;value)
{
switch (static_castQMetaType::Type>(value.type()))
{
case QMetaType::Int:
mProgram->setUniformValue(location, static_castGLint>(value.toInt()));
break;
case QMetaType::Double:
mProgram->setUniformValue(location, static_castGLfloat>(value.toDouble()));
break;
case QMetaType::Float:
mProgram->setUniformValue(location, static_castGLfloat>(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
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
一、插件准备 服务器托管网Python 插件,必须 autoDocstring 生成注释,和Pycharm一样输入三个引号”””会生产注释结构 Todo Tree 高亮显示 TODO/FIXME 二、python相关设置 一)设置python环境 按服务器托管…