本文整理汇总了C++中QOpenGLShader类的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShader类的具体用法?C++ QOpenGLShader怎么用?C++ QOpenGLShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QOpenGLShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QOpenGLShader
void CPageCurlFX::InitEffect(QObject* parent)
{
CEffect::InitEffect(parent);
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, parent);
// Flip y coordinate for input texture (render to texture with framebuffer)
const char* vsrc =
"attribute highp vec4 vertex;\n"
"varying mediump vec2 texc;\n"
"void main(void)\n"
"{\n"
" gl_Position = vec4(vertex.xy, 0.0, 1.0);\n"
" texc.x = 0.5 * (1.0 + vertex.x);\n"
" texc.y = 0.5 * (1.0 + vertex.y);\n"
"}\n";
vshader->compileSourceCode(vsrc);
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, parent);
QFile frag(":/CMainWindow/page-curl.frag");
frag.open(QIODevice::ReadOnly | QIODevice::Text);
fshader->compileSourceCode(frag.readAll());
m_program.setParent(parent);
m_program.addShader(vshader);
m_program.addShader(fshader);
m_program.bindAttributeLocation("vertex", 0);
m_program.link();
m_vertexLoc = m_program.attributeLocation("vertex");
m_sourceTexLoc = m_program.uniformLocation("sourceTex");
m_targetTexLoc = m_program.uniformLocation("targetTex");
m_timeLoc = m_program.uniformLocation("time");
}
示例2: QOpenGLShader
void QtRenderer::initialize()
{
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
vshader->compileSourceCode(
"attribute highp vec4 vertex;"
"attribute mediump vec3 normal;"
"uniform mediump mat4 matrix;"
"uniform lowp vec4 sourceColor;"
"varying mediump vec4 color;"
"void main(void)"
"{"
" vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));"
" float angle = max(dot(normal, toLight), 0.0);"
" vec3 col = sourceColor.rgb;"
" color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);"
" color = clamp(color, 0.0, 1.0);"
" gl_Position = matrix * vertex;"
"}");
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
fshader->compileSourceCode(
"varying mediump vec4 color;"
"void main(void)"
"{"
" gl_FragColor = color;"
"}");
m_program = new QOpenGLShaderProgram(this);
m_program->addShader(vshader);
m_program->addShader(fshader);
m_program->link();
m_program->bind();
vertexAttr = m_program->attributeLocation("vertex");
normalAttr = m_program->attributeLocation("normal");
matrixUniform = m_program->uniformLocation("matrix");
colorUniform = m_program->uniformLocation("sourceColor");
m_fAngle = 0;
createGeometry();
m_vbo.create();
m_vbo.bind();
const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
m_vbo.allocate(verticesSize * 2);
m_vbo.write(0, vertices.constData(), verticesSize);
m_vbo.write(verticesSize, normals.constData(), verticesSize);
QOpenGLFunctions *f = m_context->functions();
f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
f->glFrontFace(GL_CW);
f->glCullFace(GL_FRONT);
f->glEnable(GL_CULL_FACE);
f->glEnable(GL_DEPTH_TEST);
m_program->enableAttributeArray(vertexAttr);
m_program->enableAttributeArray(normalAttr);
m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3);
}
示例3: lock
void Renderer::initialize()
{
// Threaded shader compilation can confuse some drivers. Avoid it.
QMutexLocker lock(initMutex());
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
vshader->compileSourceCode(
"attribute highp vec4 vertex;"
"attribute mediump vec3 normal;"
"uniform mediump mat4 matrix;"
"uniform lowp vec4 sourceColor;"
"varying mediump vec4 color;"
"void main(void)"
"{"
" vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));"
" float angle = max(dot(normal, toLight), 0.0);"
" vec3 col = sourceColor.rgb;"
" color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);"
" color = clamp(color, 0.0, 1.0);"
" gl_Position = matrix * vertex;"
"}");
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
fshader->compileSourceCode(
"varying mediump vec4 color;"
"void main(void)"
"{"
" gl_FragColor = color;"
"}");
m_program = new QOpenGLShaderProgram(this);
m_program->addShader(vshader);
m_program->addShader(fshader);
m_program->link();
m_program->bind();
vertexAttr = m_program->attributeLocation("vertex");
normalAttr = m_program->attributeLocation("normal");
matrixUniform = m_program->uniformLocation("matrix");
colorUniform = m_program->uniformLocation("sourceColor");
m_fAngle = 0;
createGeometry();
m_vbo.create();
m_vbo.bind();
const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
m_vbo.allocate(verticesSize * 2);
m_vbo.write(0, vertices.constData(), verticesSize);
m_vbo.write(verticesSize, normals.constData(), verticesSize);
}
示例4: Q_ASSERT
void QAndroidTextureVideoOutput::createGLResources()
{
Q_ASSERT(QOpenGLContext::currentContext() != NULL);
if (!m_glDeleter)
m_glDeleter.reset(new OpenGLResourcesDeleter);
if (m_surfaceTextureCanAttachToContext && !m_externalTex) {
m_surfaceTexture->detachFromGLContext();
glGenTextures(1, &m_externalTex);
m_surfaceTexture->attachToGLContext(m_externalTex);
}
if (!m_fbo || m_fbo->size() != m_nativeSize) {
delete m_fbo;
m_fbo = new QOpenGLFramebufferObject(m_nativeSize);
}
if (!m_program) {
m_program = new QOpenGLShaderProgram;
QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_program);
vertexShader->compileSourceCode("attribute highp vec4 vertexCoordsArray; \n" \
"attribute highp vec2 textureCoordArray; \n" \
"uniform highp mat4 texMatrix; \n" \
"varying highp vec2 textureCoords; \n" \
"void main(void) \n" \
"{ \n" \
" gl_Position = vertexCoordsArray; \n" \
" textureCoords = (texMatrix * vec4(textureCoordArray, 0.0, 1.0)).xy; \n" \
"}\n");
m_program->addShader(vertexShader);
QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_program);
fragmentShader->compileSourceCode("#extension GL_OES_EGL_image_external : require \n" \
"varying highp vec2 textureCoords; \n" \
"uniform samplerExternalOES frameTexture; \n" \
"void main() \n" \
"{ \n" \
" gl_FragColor = texture2D(frameTexture, textureCoords); \n" \
"}\n");
m_program->addShader(fragmentShader);
m_program->bindAttributeLocation("vertexCoordsArray", 0);
m_program->bindAttributeLocation("textureCoordArray", 1);
m_program->link();
}
}
示例5: initializeOpenGLFunctions
void GLWidget::initializeGL()
{
initializeOpenGLFunctions();
makeObject();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
#define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
const char *vsrc =
"attribute highp vec4 vertex;\n"
"attribute mediump vec4 texCoord;\n"
"varying mediump vec4 texc;\n"
"uniform mediump mat4 matrix;\n"
"void main(void)\n"
"{\n"
" gl_Position = matrix * vertex;\n"
" texc = texCoord;\n"
"}\n";
vshader->compileSourceCode(vsrc);
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
const char *fsrc =
"uniform sampler2D texture;\n"
"varying mediump vec4 texc;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(texture, texc.st);\n"
"}\n";
fshader->compileSourceCode(fsrc);
program = new QOpenGLShaderProgram;
program->addShader(vshader);
program->addShader(fshader);
program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
program->link();
program->bind();
program->setUniformValue("texture", 0);
}
示例6: fs
void MyGLWidget::carregaShaders()
{
// Creem els shaders per al fragment shader i el vertex shader
QOpenGLShader fs (QOpenGLShader::Fragment, this);
QOpenGLShader vs (QOpenGLShader::Vertex, this);
// Carreguem el codi dels fitxers i els compilem
fs.compileSourceFile("shaders/fragshad.frag");
vs.compileSourceFile("shaders/vertshad.vert");
// Creem el program
program = new QOpenGLShaderProgram(this);
// Li afegim els shaders corresponents
program->addShader(&fs);
program->addShader(&vs);
// Linkem el program
program->link();
// Indiquem que aquest és el program que volem usar
program->bind();
// Obtenim identificador per a l'atribut “vertex” del vertex shader
vertexLoc = glGetAttribLocation (program->programId(), "vertex");
// Obtenim identificador per a l'atribut “normal” del vertex shader
normalLoc = glGetAttribLocation (program->programId(), "normal");
// Obtenim identificador per a l'atribut “matamb” del vertex shader
matambLoc = glGetAttribLocation (program->programId(), "matamb");
// Obtenim identificador per a l'atribut “matdiff” del vertex shader
matdiffLoc = glGetAttribLocation (program->programId(), "matdiff");
// Obtenim identificador per a l'atribut “matspec” del vertex shader
matspecLoc = glGetAttribLocation (program->programId(), "matspec");
// Obtenim identificador per a l'atribut “matshin” del vertex shader
matshinLoc = glGetAttribLocation (program->programId(), "matshin");
// Demanem identificadors per als uniforms del vertex shader
transLoc = glGetUniformLocation (program->programId(), "TG");
projLoc = glGetUniformLocation (program->programId(), "proj");
viewLoc = glGetUniformLocation (program->programId(), "view");
//COLOR
posFocus = glGetUniformLocation (program->programId(), "posFocus");
colFocus = glGetUniformLocation (program->programId(), "colFocus");
llumAmbient = glGetUniformLocation (program->programId(), "llumAmbient");
franges = glGetUniformLocation (program->programId(), "franges");
}
示例7: QOpenGLShaderProgram
QOpenGLShaderProgram *generateShaderProgram(QObject *parent, QByteArray vsrc, QByteArray fsrc)
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(parent);
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, program);
vshader->compileSourceCode(vsrc);
if (!vshader->compileSourceCode(vsrc))
qFatal("Error in vertex src:\n%s\n", vsrc.constData());
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, program);
if (!fshader->compileSourceCode(fsrc))
qFatal("Error in fragment src:\n%s\n", fsrc.constData());
program->addShader(vshader);
program->addShader(fshader);
if (!program->link())
qFatal("Error linking:\n%s\n%s\n", vsrc.constData(), fsrc.constData());
return program;
}
示例8: QOpenGLShader
void Renderer::initialize()
{
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
vshader->compileSourceCode(
"attribute highp vec4 vertex;"
"attribute mediump vec3 normal;"
"uniform mediump mat4 matrix;"
"uniform lowp vec4 sourceColor;"
"varying mediump vec4 color;"
"void main(void)"
"{"
" vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));"
" float angle = max(dot(normal, toLight), 0.0);"
" vec3 col = sourceColor.rgb;"
" color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);"
" color = clamp(color, 0.0, 1.0);"
" gl_Position = matrix * vertex;"
"}");
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
fshader->compileSourceCode(
"varying mediump vec4 color;"
"void main(void)"
"{"
" gl_FragColor = color;"
"}");
m_program = new QOpenGLShaderProgram(this);
m_program->addShader(vshader);
m_program->addShader(fshader);
m_program->link();
vertexAttr = m_program->attributeLocation("vertex");
normalAttr = m_program->attributeLocation("normal");
matrixUniform = m_program->uniformLocation("matrix");
colorUniform = m_program->uniformLocation("sourceColor");
m_fAngle = 0;
createGeometry();
}
示例9: QOpenGLFramebufferObject
void QAndroidVideoRendererControl::createGLResources()
{
if (!m_fbo || m_fbo->size() != m_nativeSize) {
delete m_fbo;
m_fbo = new QOpenGLFramebufferObject(m_nativeSize);
m_glDeleter->setFbo(m_fbo);
}
if (!m_program) {
m_program = new QOpenGLShaderProgram;
QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_program);
vertexShader->compileSourceCode("attribute highp vec4 vertexCoordsArray; \n" \
"attribute highp vec2 textureCoordArray; \n" \
"uniform highp mat4 texMatrix; \n" \
"varying highp vec2 textureCoords; \n" \
"void main(void) \n" \
"{ \n" \
" gl_Position = vertexCoordsArray; \n" \
" textureCoords = (texMatrix * vec4(textureCoordArray, 0.0, 1.0)).xy; \n" \
"}\n");
m_program->addShader(vertexShader);
QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_program);
fragmentShader->compileSourceCode("#extension GL_OES_EGL_image_external : require \n" \
"varying highp vec2 textureCoords; \n" \
"uniform samplerExternalOES frameTexture; \n" \
"void main() \n" \
"{ \n" \
" gl_FragColor = texture2D(frameTexture, textureCoords); \n" \
"}\n");
m_program->addShader(fragmentShader);
m_program->bindAttributeLocation("vertexCoordsArray", 0);
m_program->bindAttributeLocation("textureCoordArray", 1);
m_program->link();
m_glDeleter->setShaderProgram(m_program);
}
}
示例10: glClearColor
void SingleTri::initializeGL()
{
glClearColor(0.0f, 0.25f, 0.0f, 1.0f);
const char * vs_source =
"#version 130 \n"
" \n"
"void main(void) \n"
"{ \n"
" const vec4 vertices[] = vec4[](vec4( 0.25, -0.25, 0.5, 1.0), \n"
" vec4(-0.25, -0.25, 0.5, 1.0), \n"
" vec4( 0.25, 0.25, 0.5, 1.0)); \n"
" \n"
" gl_Position = vertices[gl_VertexID]; \n"
"} \n";
const char * fs_source =
"#version 130 \n"
" \n"
"out vec4 color; \n"
" \n"
"void main(void) \n"
"{ \n"
" color = vec4(0.0, 0.8, 1.0, 1.0); \n"
"} \n";
QOpenGLShader* fs = new QOpenGLShader(QOpenGLShader::Fragment);
fs->compileSourceCode(fs_source);
QOpenGLShader* vs = new QOpenGLShader(QOpenGLShader::Vertex);
vs->compileSourceCode(vs_source);
program = new QOpenGLShaderProgram(this);
program->addShader(vs);
program->addShader(fs);
QOpenGLVertexArrayObject* vao = new QOpenGLVertexArrayObject(this);
vao->bind();
program->bind();
}
示例11: QOpenGLShaderProgram
// Build a passthrough glsl program
QOpenGLShaderProgram* GLImageProcessor::buildPassthorughProgram() const
{
QOpenGLShaderProgram* prog = new QOpenGLShaderProgram();
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, prog);
const char *vsrc =
"attribute highp vec4 in_Vertex;\n"
"attribute mediump vec4 in_TexCoord;\n"
"varying mediump vec4 texCoord;\n"
"void main(void)\n"
"{\n"
" gl_Position = in_Vertex;\n"
" texCoord = in_TexCoord;\n"
"}\n";
vshader->compileSourceCode(vsrc);
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, prog);
const char *fsrc =
"uniform sampler2D in_Texture;\n"
"varying mediump vec4 texCoord;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(in_Texture, texCoord.st);\n"
"}\n";
fshader->compileSourceCode(fsrc);
prog->addShader(vshader);
prog->addShader(fshader);
prog->bindAttributeLocation("in_Vertex", 0);
prog->bindAttributeLocation("in_TexCoord", 1);
prog->link();
prog->bind();
prog->setUniformValue("in_Texture", 0);
prog->release();
return prog;
}
示例12: fs
void MyGLWidget::carregaShaders()
{
// Creem els shaders per al fragment shader i el vertex shader
QOpenGLShader fs (QOpenGLShader::Fragment, this);
QOpenGLShader vs (QOpenGLShader::Vertex, this);
// Carreguem el codi dels fitxers i els compilem
fs.compileSourceFile("shaders/fragshad.frag");
vs.compileSourceFile("shaders/vertshad.vert");
// Creem el program
program = new QOpenGLShaderProgram(this);
// Li afegim els shaders corresponents
program->addShader(&fs);
program->addShader(&vs);
// Linkem el program
program->link();
// Indiquem que aquest és el program que volem usar
program->bind();
// Obtenim identificador per a l'atribut “vertex” del vertex shader
vertexLoc = glGetAttribLocation (program->programId(), "vertex");
// Obtenim identificador per a l'atribut “color” del vertex shader
colorLoc = glGetAttribLocation (program->programId(), "color");
// Uniform locations
transLoc = glGetUniformLocation(program->programId(), "TG");
//Uniform projection
projLoc = glGetUniformLocation(program->programId(), "proj");
//Uniform view
viewLoc = glGetUniformLocation(program->programId(), "view");
glEnable(GL_DEPTH_TEST);
}
示例13: QOpenGLShader
Shader::Shader(QString vshaderName, QString fshaderName, QObject *parent)
:QOpenGLShaderProgram(parent)
{
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, parent);
{
QFile file(":/res/Shaders/"+vshaderName+".vert");
if (file.open(QIODevice::ReadOnly)) {
QString vsrc = file.readAll();
if (!vshader->compileSourceCode(vsrc)){
printf("%s", vshader->log().data());
exit(1);
}
}
}
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, parent);
{
QFile file(":/res/Shaders/"+fshaderName+".frag");
if (file.open(QIODevice::ReadOnly)) {
QString fsrc = file.readAll();
if (!fshader->compileSourceCode(fsrc)){
printf("%s", fshader->log().data());
exit(1);
}
}
}
this->addShader(vshader);
this->addShader(fshader);
this->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
this->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
this->bindAttributeLocation("lightPosition", PROGRAM_LIGHT_POSITION_ATTRIBUTE);
this->bindAttributeLocation("lightColour", PROGRAM_LIGHT_COLOUR_ATTRIBUTE);
this->bindAttributeLocation("useTexture", PROGRAM_USE_TEXTURE);
if (!this->link())
{
printf("%s", this->log().data());
exit(1);
}
this->bind();
this->setUniformValue("texture", 0);
}
示例14: blitShaderProg
QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
: blitShaderProg(0)
, simpleShaderProg(0)
{
/*
Rather than having the shader source array statically initialised, it is initialised
here instead. This is to allow new shader names to be inserted or existing names moved
around without having to change the order of the glsl strings. It is hoped this will
make future hard-to-find runtime bugs more obvious and generally give more solid code.
*/
static bool snippetsPopulated = false;
if (!snippetsPopulated) {
const char** code = qShaderSnippets; // shortcut
code[MainVertexShader] = qopenglslMainVertexShader;
code[MainWithTexCoordsVertexShader] = qopenglslMainWithTexCoordsVertexShader;
code[MainWithTexCoordsAndOpacityVertexShader] = qopenglslMainWithTexCoordsAndOpacityVertexShader;
code[UntransformedPositionVertexShader] = qopenglslUntransformedPositionVertexShader;
code[PositionOnlyVertexShader] = qopenglslPositionOnlyVertexShader;
code[ComplexGeometryPositionOnlyVertexShader] = qopenglslComplexGeometryPositionOnlyVertexShader;
code[PositionWithPatternBrushVertexShader] = qopenglslPositionWithPatternBrushVertexShader;
code[PositionWithLinearGradientBrushVertexShader] = qopenglslPositionWithLinearGradientBrushVertexShader;
code[PositionWithConicalGradientBrushVertexShader] = qopenglslPositionWithConicalGradientBrushVertexShader;
code[PositionWithRadialGradientBrushVertexShader] = qopenglslPositionWithRadialGradientBrushVertexShader;
code[PositionWithTextureBrushVertexShader] = qopenglslPositionWithTextureBrushVertexShader;
code[AffinePositionWithPatternBrushVertexShader] = qopenglslAffinePositionWithPatternBrushVertexShader;
code[AffinePositionWithLinearGradientBrushVertexShader] = qopenglslAffinePositionWithLinearGradientBrushVertexShader;
code[AffinePositionWithConicalGradientBrushVertexShader] = qopenglslAffinePositionWithConicalGradientBrushVertexShader;
code[AffinePositionWithRadialGradientBrushVertexShader] = qopenglslAffinePositionWithRadialGradientBrushVertexShader;
code[AffinePositionWithTextureBrushVertexShader] = qopenglslAffinePositionWithTextureBrushVertexShader;
code[MainFragmentShader_CMO] = qopenglslMainFragmentShader_CMO;
code[MainFragmentShader_CM] = qopenglslMainFragmentShader_CM;
code[MainFragmentShader_MO] = qopenglslMainFragmentShader_MO;
code[MainFragmentShader_M] = qopenglslMainFragmentShader_M;
code[MainFragmentShader_CO] = qopenglslMainFragmentShader_CO;
code[MainFragmentShader_C] = qopenglslMainFragmentShader_C;
code[MainFragmentShader_O] = qopenglslMainFragmentShader_O;
code[MainFragmentShader] = qopenglslMainFragmentShader;
code[MainFragmentShader_ImageArrays] = qopenglslMainFragmentShader_ImageArrays;
code[ImageSrcFragmentShader] = qopenglslImageSrcFragmentShader;
code[ImageSrcWithPatternFragmentShader] = qopenglslImageSrcWithPatternFragmentShader;
code[NonPremultipliedImageSrcFragmentShader] = qopenglslNonPremultipliedImageSrcFragmentShader;
code[CustomImageSrcFragmentShader] = qopenglslCustomSrcFragmentShader; // Calls "customShader", which must be appended
code[SolidBrushSrcFragmentShader] = qopenglslSolidBrushSrcFragmentShader;
code[TextureBrushSrcFragmentShader] = qopenglslTextureBrushSrcFragmentShader;
code[TextureBrushSrcWithPatternFragmentShader] = qopenglslTextureBrushSrcWithPatternFragmentShader;
code[PatternBrushSrcFragmentShader] = qopenglslPatternBrushSrcFragmentShader;
code[LinearGradientBrushSrcFragmentShader] = qopenglslLinearGradientBrushSrcFragmentShader;
code[RadialGradientBrushSrcFragmentShader] = qopenglslRadialGradientBrushSrcFragmentShader;
code[ConicalGradientBrushSrcFragmentShader] = qopenglslConicalGradientBrushSrcFragmentShader;
code[ShockingPinkSrcFragmentShader] = qopenglslShockingPinkSrcFragmentShader;
code[NoMaskFragmentShader] = "";
code[MaskFragmentShader] = qopenglslMaskFragmentShader;
code[RgbMaskFragmentShaderPass1] = qopenglslRgbMaskFragmentShaderPass1;
code[RgbMaskFragmentShaderPass2] = qopenglslRgbMaskFragmentShaderPass2;
code[RgbMaskWithGammaFragmentShader] = ""; //###
code[NoCompositionModeFragmentShader] = "";
code[MultiplyCompositionModeFragmentShader] = ""; //###
code[ScreenCompositionModeFragmentShader] = ""; //###
code[OverlayCompositionModeFragmentShader] = ""; //###
code[DarkenCompositionModeFragmentShader] = ""; //###
code[LightenCompositionModeFragmentShader] = ""; //###
code[ColorDodgeCompositionModeFragmentShader] = ""; //###
code[ColorBurnCompositionModeFragmentShader] = ""; //###
code[HardLightCompositionModeFragmentShader] = ""; //###
code[SoftLightCompositionModeFragmentShader] = ""; //###
code[DifferenceCompositionModeFragmentShader] = ""; //###
code[ExclusionCompositionModeFragmentShader] = ""; //###
#if defined(QT_DEBUG)
// Check that all the elements have been filled:
for (int i = 0; i < TotalSnippetCount; ++i) {
if (qShaderSnippets[i] == 0) {
qFatal("Shader snippet for %s (#%d) is missing!",
snippetNameStr(SnippetName(i)).constData(), i);
}
}
#endif
snippetsPopulated = true;
}
QOpenGLShader* fragShader;
QOpenGLShader* vertexShader;
QByteArray vertexSource;
QByteArray fragSource;
// Compile up the simple shader:
vertexSource.append(qShaderSnippets[MainVertexShader]);
vertexSource.append(qShaderSnippets[PositionOnlyVertexShader]);
fragSource.append(qShaderSnippets[MainFragmentShader]);
fragSource.append(qShaderSnippets[ShockingPinkSrcFragmentShader]);
//.........这里部分代码省略.........
示例15: contextWanted
void Renderer::render()
{
if (m_exiting)
return;
QOpenGLContext *ctx = m_glwidget->context();
if (!ctx) // QOpenGLWidget not yet initialized
return;
// Grab the context.
m_grabMutex.lock();
emit contextWanted();
m_grabCond.wait(&m_grabMutex);
QMutexLocker lock(&m_renderMutex);
m_grabMutex.unlock();
if (m_exiting)
return;
Q_ASSERT(ctx->thread() == QThread::currentThread());
// Make the context (and an offscreen surface) current for this thread. The
// QOpenGLWidget's fbo is bound in the context.
m_glwidget->makeCurrent();
if (!m_inited) {
m_inited = true;
initializeOpenGLFunctions();
QMutexLocker initLock(initMutex());
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
const char *vsrc =
"attribute highp vec4 vertex;\n"
"attribute mediump vec3 normal;\n"
"uniform mediump mat4 matrix;\n"
"varying mediump vec4 color;\n"
"void main(void)\n"
"{\n"
" vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
" float angle = max(dot(normal, toLight), 0.0);\n"
" vec3 col = vec3(0.40, 1.0, 0.0);\n"
" color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n"
" color = clamp(color, 0.0, 1.0);\n"
" gl_Position = matrix * vertex;\n"
"}\n";
vshader->compileSourceCode(vsrc);
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
const char *fsrc =
"varying mediump vec4 color;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = color;\n"
"}\n";
fshader->compileSourceCode(fsrc);
program.addShader(vshader);
program.addShader(fshader);
program.link();
vertexAttr = program.attributeLocation("vertex");
normalAttr = program.attributeLocation("normal");
matrixUniform = program.uniformLocation("matrix");
m_fAngle = 0;
m_fScale = 1;
createGeometry();
vbo.create();
vbo.bind();
const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
vbo.allocate(verticesSize * 2);
vbo.write(0, vertices.constData(), verticesSize);
vbo.write(verticesSize, normals.constData(), verticesSize);
m_elapsed.start();
}
//qDebug("%p elapsed %lld", QThread::currentThread(), m_elapsed.restart());
glClearColor(0.1f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CW);
glCullFace(GL_FRONT);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.scale(m_fScale);
modelview.translate(0.0f, -0.2f, 0.0f);
program.bind();
program.setUniformValue(matrixUniform, modelview);
paintQtLogo();
program.release();
//.........这里部分代码省略.........