本文整理汇总了C++中QOpenGLShader::compileSourceCode方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShader::compileSourceCode方法的具体用法?C++ QOpenGLShader::compileSourceCode怎么用?C++ QOpenGLShader::compileSourceCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShader
的用法示例。
在下文中一共展示了QOpenGLShader::compileSourceCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitEffect
void CMoviePlayback::InitEffect(QObject* parent)
{
CEffect::InitEffect(parent);
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, parent);
vshader->compileSourceCode(BASIC_VERTEX_SHADER);
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, parent);
const char *fsrc =
"varying mediump vec2 texc;\n"
"uniform sampler2D videoTex;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(videoTex, texc);\n"
"}\n";
fshader->compileSourceCode(fsrc);
m_program.setParent(parent);
m_program.addShader(vshader);
m_program.addShader(fshader);
m_program.bindAttributeLocation("vertex", 0);
m_program.link();
m_ffmpegLoc = m_program.uniformLocation("videoTex");
}
示例2: initialize
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: initialize
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: createGLResources
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: initializeGL
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: 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;
}
示例7: file
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);
}
示例8: initialize
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: createGLResources
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: initializeGL
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: buildPassthorughProgram
// 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: initializeGL
void GLWidget::initializeGL()
{
initializeOpenGLFunctions();
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
makeCurrent();
qglClearColor(QColor::fromCmykF(0.79, 0.79, 0.79, 0.0).dark());
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
glEnable(GL_DEPTH_TEST);
qDebug() << "Loading quad (vertex shader)";
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
vshader->compileSourceFile(":/resources/plane.vert");
if (!vshader->log().isEmpty()) qDebug() << vshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (fragment shader)";
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
fshader->compileSourceFile(":/resources/plane.frag");
if (!fshader->log().isEmpty()) qDebug() << fshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (tessellation control shader)";
QOpenGLShader *tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl, this);
tcshader->compileSourceFile(":/resources/plane.tcs.vert");
if (!tcshader->log().isEmpty()) qDebug() << tcshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (tessellation evaluation shader)";
QOpenGLShader *teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation, this);
teshader->compileSourceFile(":/resources/plane.tes.vert");
if (!teshader->log().isEmpty()) qDebug() << teshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (geometry shader)";
QOpenGLShader *gshader = new QOpenGLShader(QOpenGLShader::Geometry, this);
QFile gFile(":/resources/plane.geom");
gFile.open(QFile::ReadOnly);
qDebug() << gFile.isOpen() << " File";
QTextStream in(&gFile);
QString preambule = "#version 400 core\n"
"layout(triangle_strip, max_vertices = 3) out;\n" ;
QString shaderCode = in.readAll();
gshader->compileSourceCode(preambule+shaderCode);
//gshader->compileSourceFile(in.readAll());
if (!gshader->log().isEmpty()) qDebug() << gshader->log();
else qDebug() << "done";
program = new QOpenGLShaderProgram(this);
program->addShader(vshader);
program->addShader(fshader);
program->addShader(tcshader);
program->addShader(teshader);
program->addShader(gshader);
program->bindAttributeLocation("FragColor",0);
program->bindAttributeLocation("FragNormal",1);
program->bindAttributeLocation("FragGlowColor",2);
program->bindAttributeLocation("FragPosition",3);
GLCHK(program->link());
GLCHK(program->bind());
program->setUniformValue("texDiffuse" , 0);
program->setUniformValue("texNormal" , 1);
program->setUniformValue("texSpecular" , 2);
program->setUniformValue("texHeight" , 3);
program->setUniformValue("texSSAO" , 4);
program->setUniformValue("texRoughness", 5);
program->setUniformValue("texMetallic", 6);
program->setUniformValue("texMaterial", 7);
program->setUniformValue("texDiffuseEnvMap", 8);
program->setUniformValue("texEnvMap" , 9);
// lines shader
qDebug() << "Compiling lines program...";
preambule = QString("#version 400 core\n")+
"layout(line_strip, max_vertices = 3) out;\n" ;
gshader->compileSourceCode(preambule+shaderCode);
line_program = new QOpenGLShaderProgram(this);
line_program->addShader(vshader);
line_program->addShader(fshader);
line_program->addShader(tcshader);
line_program->addShader(teshader);
line_program->addShader(gshader);
line_program->bindAttributeLocation("FragColor",0);
line_program->bindAttributeLocation("FragNormal",1);
line_program->bindAttributeLocation("FragGlowColor",2);
line_program->bindAttributeLocation("FragPosition",3);
GLCHK(line_program->link());
GLCHK(line_program->bind());
line_program->setUniformValue("texDiffuse" , 0);
line_program->setUniformValue("texNormal" , 1);
line_program->setUniformValue("texSpecular" , 2);
line_program->setUniformValue("texHeight" , 3);
//.........这里部分代码省略.........
示例13: resizeTextureData
void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height)
{
QOpenGLContext *ctx = QOpenGLContext::currentContext();
if (ctx == 0) {
qWarning("QOpenGLTextureGlyphCache::resizeTextureData: Called with no context");
return;
}
int oldWidth = m_textureResource->m_width;
int oldHeight = m_textureResource->m_height;
// Make the lower glyph texture size 16 x 16.
if (width < 16)
width = 16;
if (height < 16)
height = 16;
GLuint oldTexture = m_textureResource->m_texture;
createTextureData(width, height);
if (ctx->d_func()->workaround_brokenFBOReadBack) {
QImageTextureGlyphCache::resizeTextureData(width, height);
Q_ASSERT(image().depth() == 8);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, oldHeight, GL_ALPHA, GL_UNSIGNED_BYTE, image().constBits());
glDeleteTextures(1, &oldTexture);
return;
}
// ### the QTextureGlyphCache API needs to be reworked to allow
// ### resizeTextureData to fail
QOpenGLFunctions funcs(ctx);
funcs.glBindFramebuffer(GL_FRAMEBUFFER, m_textureResource->m_fbo);
GLuint tmp_texture;
glGenTextures(1, &tmp_texture);
glBindTexture(GL_TEXTURE_2D, tmp_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
m_filterMode = Nearest;
glBindTexture(GL_TEXTURE_2D, 0);
funcs.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, tmp_texture, 0);
funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
glBindTexture(GL_TEXTURE_2D, oldTexture);
if (pex != 0)
pex->transferMode(BrushDrawingMode);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
glViewport(0, 0, oldWidth, oldHeight);
QOpenGLShaderProgram *blitProgram = 0;
if (pex == 0) {
if (m_blitProgram == 0) {
m_blitProgram = new QOpenGLShaderProgram(ctx);
{
QString source;
source.append(QLatin1String(qopenglslMainWithTexCoordsVertexShader));
source.append(QLatin1String(qopenglslUntransformedPositionVertexShader));
QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_blitProgram);
vertexShader->compileSourceCode(source);
m_blitProgram->addShader(vertexShader);
}
{
QString source;
source.append(QLatin1String(qopenglslMainFragmentShader));
source.append(QLatin1String(qopenglslImageSrcFragmentShader));
QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_blitProgram);
fragmentShader->compileSourceCode(source);
m_blitProgram->addShader(fragmentShader);
}
m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
m_blitProgram->link();
}
funcs.glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_vertexCoordinateArray);
funcs.glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_textureCoordinateArray);
m_blitProgram->bind();
m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
//.........这里部分代码省略.........
示例14: simpleShaderCache
//.........这里部分代码省略.........
#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]);
simpleShaderProg = new QOpenGLShaderProgram;
CachedShader simpleShaderCache(fragSource, vertexSource);
bool inCache = simpleShaderCache.load(simpleShaderProg, context);
if (!inCache) {
vertexShader = new QOpenGLShader(QOpenGLShader::Vertex);
shaders.append(vertexShader);
if (!vertexShader->compileSourceCode(vertexSource))
qWarning("Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader) failed to compile");
fragShader = new QOpenGLShader(QOpenGLShader::Fragment);
shaders.append(fragShader);
if (!fragShader->compileSourceCode(fragSource))
qWarning("Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile");
simpleShaderProg->addShader(vertexShader);
simpleShaderProg->addShader(fragShader);
simpleShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
simpleShaderProg->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR);
simpleShaderProg->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR);
simpleShaderProg->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR);
}
simpleShaderProg->link();
if (simpleShaderProg->isLinked()) {
if (!inCache)
simpleShaderCache.store(simpleShaderProg, context);
} else {
qCritical("Errors linking simple shader: %s", qPrintable(simpleShaderProg->log()));
}
// Compile the blit shader:
vertexSource.clear();
vertexSource.append(qShaderSnippets[MainWithTexCoordsVertexShader]);
vertexSource.append(qShaderSnippets[UntransformedPositionVertexShader]);
fragSource.clear();
fragSource.append(qShaderSnippets[MainFragmentShader]);
示例15: initializeGL
void FragColorFromPos::initializeGL()
{
glClearColor(0.0f, 0.25f, 0.0f, 1.0f);
const char * vsInterpolate_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 * fsInterpolate_source =
"#version 130 \n"
" \n"
"out vec4 color; \n"
" \n"
"void main(void) \n"
"{ \n"
" color = vec4(sin(gl_FragCoord.x * 0.25) * 0.5 + 0.5, \n"
" cos(gl_FragCoord.y * 0.25) * 0.5 + 0.5, \n"
" sin(gl_FragCoord.x * 0.15) * cos(gl_FragCoord.y * 0.1), \n"
" 1.0); \n"
"} \n";
QOpenGLShader* fs = new QOpenGLShader(QOpenGLShader::Fragment);
fs->compileSourceCode(fsInterpolate_source);
QOpenGLShader* vs = new QOpenGLShader(QOpenGLShader::Vertex);
vs->compileSourceCode(vsInterpolate_source);
interpolateProgram = new QOpenGLShaderProgram(this);
interpolateProgram->addShader(vs);
interpolateProgram->addShader(fs);
interpolateProgram->link();
const char * vs_source =
"#version 130 \n"
" \n"
"out vec4 vs_color; \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"
" const vec4 colors[] = vec4[](vec4(1.0, 0.0, 0.0, 1.0), \n"
" vec4(0.0, 1.0, 0.0, 1.0), \n"
" vec4(0.0, 0.0, 1.0, 1.0)); \n"
" \n"
" gl_Position = vertices[gl_VertexID]; \n"
" vs_color = colors[gl_VertexID]; \n"
"} \n";
const char * fs_source =
"#version 130 \n"
" \n"
"in vec4 vs_color; \n"
"out vec4 color; \n"
" \n"
"void main(void) \n"
"{ \n"
" color = vs_color; \n"
"} \n";
fs->compileSourceCode(fs_source);
vs->compileSourceCode(vs_source);
nonInterpolateProgram = new QOpenGLShaderProgram(this);
nonInterpolateProgram->addShader(vs);
nonInterpolateProgram->addShader(fs);
QOpenGLVertexArrayObject* vao = new QOpenGLVertexArrayObject(this);
vao->bind();
nonInterpolateProgram->bind();
}