本文整理汇总了C++中ShaderProgram::attach方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::attach方法的具体用法?C++ ShaderProgram::attach怎么用?C++ ShaderProgram::attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::attach方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vsFile
TEST_F(TransformFeedbackTest, test)
{
std::ifstream vsFile("data/transform_feedback.vert");
std::ifstream gsFile("data/transform_feedback.geom");
Shader vertex(GL_VERTEX_SHADER);
Shader geometry(GL_GEOMETRY_SHADER);
ShaderProgram shader;
Query query(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
VAO vao;
VBO vbo;
TFBO tfbo;
const GLchar* feedbackVaryings[] = { "outValue" };
GLfloat data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
GLfloat feedback[15];
GLuint primitives;
ASSERT_TRUE(vertex.compile(vsFile));
ASSERT_TRUE(geometry.compile(gsFile));
shader.attach(vertex);
shader.attach(geometry);
shader.setTransformFeedbackVaryings(1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);
ASSERT_TRUE(shader.link());
shader.use();
shader.printDebug();
vao.bind();
vbo.bind();
vbo.setData(sizeof(data), data, GL_STATIC_DRAW);
GLint inputAttrib = shader.getAttribLocation("inValue");
vao.enableAttrib(inputAttrib);
glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);
tfbo.setData(sizeof(data) * 3, nullptr, GL_STATIC_READ);
tfbo.bindBufferBase(0);
mogl::enable(GL_RASTERIZER_DISCARD);
query.begin();
TransformFeedback::begin(GL_TRIANGLES);
glDrawArrays(GL_POINTS, 0, 5);
TransformFeedback::end();
query.end();
mogl::disable(GL_RASTERIZER_DISCARD);
mogl::Sync::flush();
primitives = query.get<GLuint>(GL_QUERY_RESULT);
tfbo.getSubData(0, sizeof(feedback), feedback);
std::cout << primitives << " primitives written" << std::endl;
for (unsigned int i = 0; i < 15; ++i)
std::cout << feedback[i] << std::endl;
}
示例2: canLinkProgramWhenShadersCompiled
void canLinkProgramWhenShadersCompiled()
{
ShaderProgram shaderProgram;
Shader fragmentShader(Shader::FRAGMENT_SHADER);
shaderProgram.attach(fragmentShader);
fragmentShader.compile(VALID_FRAGMENT_SHADER_SOURCE);
QVERIFY(shaderProgram.link());
Shader vertexShader(Shader::VERTEX_SHADER);
vertexShader.compile(VALID_VERTEX_SHADER_SOURCE);
shaderProgram.attach(vertexShader);
QVERIFY(shaderProgram.link());
}
示例3: cannotLinkProgramWhenShaderNotCompiled
void cannotLinkProgramWhenShaderNotCompiled()
{
ShaderProgram shaderProgram;
Shader shader(Shader::FRAGMENT_SHADER);
shaderProgram.attach(shader);
QVERIFY(!shaderProgram.link());
QVERIFY(!shaderProgram.getLastLinkLog().empty());
}
示例4: canCopyProgram
void canCopyProgram()
{
ShaderProgram shaderProgram;
Shader fragmentShader(Shader::FRAGMENT_SHADER);
fragmentShader.compile(VALID_FRAGMENT_SHADER_SOURCE);
shaderProgram.attach(fragmentShader);
Shader vertexShader(Shader::VERTEX_SHADER);
vertexShader.compile(VALID_VERTEX_SHADER_SOURCE);
shaderProgram.attach(vertexShader);
ShaderProgram copy = shaderProgram;
QVERIFY(copy.exists());
QVERIFY(copy.getId() != 0);
QVERIFY(glIsProgram(copy.getId()));
QVERIFY(copy.has(fragmentShader));
QVERIFY(copy.has(vertexShader));
QVERIFY(copy.link());
}
示例5: canAttachDetachShader
void canAttachDetachShader()
{
ShaderProgram shaderProgram;
Shader shader(Shader::FRAGMENT_SHADER);
QVERIFY(shaderProgram.attach(shader));
QVERIFY(shaderProgram.has(shader));
QVERIFY(shaderProgram.detach(shader));
QVERIFY(!shaderProgram.has(shader));
}
示例6: canAssignProgram
void canAssignProgram()
{
ShaderProgram shaderProgram;
Shader fragmentShader(Shader::FRAGMENT_SHADER);
fragmentShader.compile(VALID_FRAGMENT_SHADER_SOURCE);
shaderProgram.attach(fragmentShader);
Shader vertexShader(Shader::VERTEX_SHADER);
vertexShader.compile(VALID_VERTEX_SHADER_SOURCE);
shaderProgram.attach(vertexShader);
ShaderProgram copy;
Shader anotherShader(Shader::VERTEX_SHADER);
copy.attach(anotherShader);
QVERIFY(copy.has(anotherShader));
copy = shaderProgram;
QVERIFY(copy.has(fragmentShader));
QVERIFY(copy.has(vertexShader));
QVERIFY(!copy.has(anotherShader));
QVERIFY(copy.link());
}
示例7: buildCurrentProject
void GLShaderDev::buildCurrentProject()
{
ShaderProgram* prog = new ShaderProgram;
bool success = true;
int i = 1;
OutputParser parser(_glInfo.getVendor());
const ShaderProject::Stages& stages = _projectManager.getCurrentProject()->getStages();
_editor->saveAll();
_output->getModel()->clear();
_buildOutputDock->setVisible(true);
for (ShaderProject::Stages::const_iterator it = stages.begin(); it != stages.end(); ++it)
{
QFile file(it->second);
QFileInfo fileInfo(file);
ShaderObject* obj = new ShaderObject;
QString str = QString(tr("[%1/%2] Compiling %3...")).arg(i).arg(stages.size()).arg(fileInfo.fileName());
_output->getModel()->addItem(OutputItem(str, OutputItem::InformationItem));
if (!file.open(QIODevice::ReadOnly))
throw (GlsdException(std::string("Could not open shader file") + it->second.toStdString())); // TODO proper exception handling
if (!obj->compile(QString(file.readAll()).toStdString(), static_cast<ShaderObject::ShaderType>(it->first)))
{
_output->getModel()->addItems(parser.parse(obj->getErrorLog(), fileInfo.absoluteFilePath().toStdString()));
success = false;
}
prog->attach(*obj);
++i;
}
_output->getModel()->addItem(OutputItem(tr("Linking shader..."), OutputItem::InformationItem));
if (!prog->link())
{
_output->getModel()->addItem(OutputItem(prog->getLog().c_str(), OutputItem::ErrorItem));
success = false;
}
if (!success)
{
_output->getModel()->addItem(OutputItem(tr("*** Compilation failed ***"), OutputItem::StandardItem));
return;
}
_output->getModel()->addItem(OutputItem(tr("*** Compilation successful ***"), OutputItem::StandardItem));
// FIXME Set shader properly, with attributes correctly bound
_glwidget->setShader(prog);
prog->printDebug();
}
示例8: onCreate
inline bool OmniStereoGraphicsRenderer::onCreate() {
mOmni.onCreate();
Shader vert, frag;
vert.source(OmniStereo::glsl() + vertexCode(), Shader::VERTEX).compile();
vert.printLog();
frag.source(fragmentCode(), Shader::FRAGMENT).compile();
frag.printLog();
mShader.attach(vert).attach(frag).link();
mShader.printLog();
mShader.begin();
mShader.uniform("lighting", 0.0);
mShader.uniform("texture", 0.0);
mShader.end();
return true;
}
示例9: canDetachAllShaders
void canDetachAllShaders()
{
ShaderProgram shaderProgram;
Shader shader1(Shader::VERTEX_SHADER);
Shader shader2(Shader::FRAGMENT_SHADER);
QVERIFY(shaderProgram.attach(shader1));
QVERIFY(shaderProgram.attach(shader2));
QVERIFY(shaderProgram.has(shader1));
QVERIFY(shaderProgram.has(shader2));
shaderProgram.detachAllShaders();
QVERIFY(!shaderProgram.has(shader1));
QVERIFY(!shaderProgram.has(shader2));
}
示例10: onCreate
bool onCreate(){
// initialize the shaders:
frag.compile();
vert.compile();
shaderprogram.attach(vert);
shaderprogram.attach(frag);
shaderprogram.link();
shaderprogram.listParams();
printf("frag %s\n", frag.log());
printf("vert %s\n", vert.log());
// draw the models into a display list:
scene_list.begin();
Mesh mesh;
for (unsigned i=0; i<ascene->meshes(); i++) {
ascene->mesh(i, mesh);
gl.draw(mesh);
}
scene_list.end();
return true;
}