本文整理汇总了C++中ShaderProgram类的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram类的具体用法?C++ ShaderProgram怎么用?C++ ShaderProgram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShaderProgram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render
void BatchSpriteRenderer::render(F32 x, F32 y, F32 width, F32 height, F32 angleRads) {
F32 top = height/2;
F32 right = width/2;
F32 bottom = -height/2;
F32 left = -width/2;
F32 verts[] = {
left, top, 0, right, top, 0, right, bottom, 0, left, bottom, 0
};
F32 uvs[] = {
0, 0, 1, 0, 1, 1, 0, 1
};
if (context->gConfig->useShaders) {
ShaderProgram *shaderProgram = context->glResourceManager->getShaderProgram("quad");
Matrix4f myMvMatrix = context->renderContext->mvMatrix;
myMvMatrix.translate(x, y, 0);
myMvMatrix.rotate(angleRads * (180 / PI), 0, 0, -1.0f);
glVertexAttribPointer(shaderProgram->getVertexAttributeLoc("vPosition"), 3, GL_FLOAT, GL_FALSE, 0, verts);
glVertexAttribPointer(shaderProgram->getVertexAttributeLoc("uvMap"), 2, GL_FLOAT, GL_FALSE, 0, uvs);
glUniformMatrix4fv(shaderProgram->getUniformLoc("projection_matrix"), 1, GL_FALSE, (GLfloat*) context->renderContext->projMatrix.data);
glUniformMatrix4fv(shaderProgram->getUniformLoc("modelview_matrix"), 1, GL_FALSE, (GLfloat*) myMvMatrix.data);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
} else {
// GL1 rendering branch
Vector4f colorFilter = context->renderContext->colorFilter;
glColor4f(colorFilter.x,colorFilter.y,colorFilter.z,colorFilter.a);
glPushMatrix();
glTranslatef(x, y, 0);
glRotatef(angleRads * (180 / PI), 0, 0, 1.0f);
glVertexPointer(3, GL_FLOAT, 0, &verts);
glTexCoordPointer(2, GL_FLOAT, 0, &uvs);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glPopMatrix();
}
}
示例2: LOG
ShaderProgram & ShaderManager::loadShader(const char * vertexShaderFilename, const char * fragmentShaderFilename)
{
// Has that shader already been loaded?
for(vector<ShaderCacheHandle>::iterator iter = shaderProgramCache.begin(); iter != shaderProgramCache.end(); iter++) {
if (iter->vertexShaderFilename.compare(vertexShaderFilename) == 0 && iter->fragmentShaderFilename.compare(fragmentShaderFilename) == 0) {
LOG(LOG_RESOURCE, LOG_DEBUG) << "Returning cached shaderprogram: " << iter->shaderProgram->getProgramHandle();
return *iter->shaderProgram;
}
}
bool success = true;
// Compile and link the shader program
ShaderProgram * shaderProgram = new ShaderProgram();
success = success && shaderProgram->addShaderFromFileResource(ShaderProgram::TYPE_VERTEX_SHADER, FileResource(vertexShaderFilename));
success = success && shaderProgram->addShaderFromFileResource(ShaderProgram::TYPE_FRAGMENT_SHADER, FileResource(fragmentShaderFilename));
success = success && shaderProgram->link();
if (!success) {
shaderProgram->unload();
}
ShaderCacheHandle cacheHandle;
cacheHandle.vertexShaderFilename = vertexShaderFilename;
cacheHandle.fragmentShaderFilename = fragmentShaderFilename;
cacheHandle.shaderProgram = shaderProgram;
shaderProgramCache.push_back(cacheHandle);
return * shaderProgram;
}
示例3: enable
void VertexLayout::enable(ShaderProgram& _program, size_t _byteOffset, void* _ptr) {
GLuint glProgram = _program.getGlProgram();
// Enable all attributes for this layout
for (auto& attrib : m_attribs) {
GLint location = _program.getAttribLocation(attrib.name);
if (location != -1) {
auto& loc = s_enabledAttribs[location];
// Track currently enabled attribs by the program to which they are bound
if (loc != glProgram) {
glEnableVertexAttribArray(location);
loc = glProgram;
}
void* data = _ptr ? _ptr : ((unsigned char*) attrib.offset) + _byteOffset;
glVertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized, m_stride, data);
}
}
// Disable previously bound and now-unneeded attributes
for (auto& locationProgramPair : s_enabledAttribs) {
const GLint& location = locationProgramPair.first;
GLuint& boundProgram = locationProgramPair.second;
if (boundProgram != glProgram && boundProgram != 0) {
glDisableVertexAttribArray(location);
boundProgram = 0;
}
}
}
示例4: Java_android_filterfw_core_ShaderProgram_setShaderAttributeVertexFrame
jboolean Java_android_filterfw_core_ShaderProgram_setShaderAttributeVertexFrame(
JNIEnv* env,
jobject thiz,
jstring attr_name,
jobject vertex_frame,
jint type,
jint component_count,
jint stride,
jint offset,
jboolean normalize) {
ShaderProgram* program = ConvertFromJava<ShaderProgram>(env, thiz);
if (program) {
// Get the vertex frame
VertexFrame* v_frame = ConvertFromJava<VertexFrame>(env, vertex_frame);
// Get the program variable to set
const std::string attr_string = ToCppString(env, attr_name);
ProgramVar program_var = program->GetAttribute(attr_string);
// Set the variable
if (v_frame && ShaderProgram::IsVarValid(program_var)) {
const bool success = program->SetAttributeValues(program_var,
v_frame,
type,
component_count,
stride,
offset,
ToCppBool(normalize));
return ToJBool(success);
}
}
return JNI_FALSE;
}
示例5: textureCount
ParticleSystem::ParticleSystem() :
textureCount(0), textureSheet(NULL),
projectionMatrix(1.0f), viewMatrix(1.0f) {
std::vector<Vertex::Element> elements;
elements.push_back(Vertex::Element(Vertex::Attribute::Position , Vertex::Element::Float, 3));
elements.push_back(Vertex::Element(Vertex::Attribute::get("a_vel"), Vertex::Element::Float, 3));
elements.push_back(Vertex::Element(Vertex::Attribute::Color , Vertex::Element::Float, 4));
elements.push_back(Vertex::Element(Vertex::Attribute::get("a_size"), Vertex::Element::Float, 1));
elements.push_back(Vertex::Element(Vertex::Attribute::get("a_texIndex"), Vertex::Element::Int, 1));
Vertex::Format format(elements);
Mesh* mesh= new Mesh(format, 0, Mesh::STREAM);
mesh->setPrimitiveType(Mesh::POINTS);
model.mesh = mesh;
Meshes.add("particlesMesh",mesh);
if(!Programs.exists("__particleShader")) {
ShaderProgram* p = new ShaderProgram();
p->makeProgramFromString(vertexShader,geometryShader,fragmentShader);
Programs.add("__particleShader",p);
}
model.program = Programs.get("__particleShader");
setName("particleSystem");
setUpdatePriority(-100);
setDrawPriority(100);
}
示例6: openGLThread
void openGLThread(bool _draw, GLfloat _red) {
//WindowGL * window = WindowGL::createWindow(640, 480);
Context context;
DriverGPU *driver = DriverGPU::get();
Shader vShader(eShaderType::eVertexShader, "../../src/shaders/vTriangleShader.vertex");
Shader fShader(eShaderType::eFragmentShader, "../../src/shaders/fTriangleShader.fragment");
ShaderProgram sProgram;
sProgram.attachShader(vShader);
sProgram.attachShader(fShader);
sProgram.bindAttribute(0, "vPosition");
sProgram.link();
while(running) {
//window->peekMessage();
//window->swapBuffers();
//if (_draw)
// drawOnBuffer(640, 480, sProgram, _red);
}
delete driver;
}
示例7: main
ShaderProgram* SpriteCache::createDefaultShader () {
if (!Gdx::graphics->isGL20Available()) return NULL;
std::string vertexShader = "attribute vec4 " + ShaderProgram::POSITION_ATTRIBUTE + ";\n" //
"attribute vec4 " + ShaderProgram::COLOR_ATTRIBUTE + ";\n" //
"attribute vec2 " + ShaderProgram::TEXCOORD_ATTRIBUTE + "0;\n" //
"uniform mat4 u_projectionViewMatrix;\n" //
"varying vec4 v_color;\n" //
"varying vec2 v_texCoords;\n" //
"\n" //
"void main()\n" //
"{\n" //
" v_color = " + ShaderProgram::COLOR_ATTRIBUTE + ";\n" //
" v_texCoords = " + ShaderProgram::TEXCOORD_ATTRIBUTE + "0;\n" //
" gl_Position = u_projectionViewMatrix * " + ShaderProgram::POSITION_ATTRIBUTE + ";\n" //
"}\n";
std::string fragmentShader = "#ifdef GL_ES\n" //
"precision mediump float;\n" //
"#endif\n" //
"varying vec4 v_color;\n" //
"varying vec2 v_texCoords;\n" //
"uniform sampler2D u_texture;\n" //
"void main()\n"//
"{\n" //
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" //
"}";
ShaderProgram* shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader->isCompiled() == false)
throw std::runtime_error("Error compiling shader: " + shader->getLog());
return shader;
}
示例8: move_it
void move_it(ShaderProgram program, Matrix& modelMatrix, Matrix& projectionMatrix, Matrix& viewMatrix,float x, float y){
program.setModelMatrix(modelMatrix);
program.setProjectionMatrix(projectionMatrix);
program.setViewMatrix(viewMatrix);
modelMatrix.identity();
modelMatrix.Translate(x, y, 0.0);
}
示例9: cannotValidateUnlinkProgram
void cannotValidateUnlinkProgram()
{
ShaderProgram shaderProgram;
QVERIFY(!shaderProgram.validate());
QVERIFY(!shaderProgram.getLastValidationLog().empty());
}
示例10: FrameBuffer
void TerrainDeformationProgram::Initialize(){
m_FrameBuffer = new FrameBuffer();
m_FrameBuffer->Init();
glGenTextures(1, &m_BrushTexture);
glBindTexture(GL_TEXTURE_2D, m_BrushTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_BRUSH_RES, m_BRUSH_RES, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
//fill in brush
m_BrushGenProgram = g_ShaderBank.LoadShaderProgram("../../../shader/BrushTexGenProgram.glsl");
ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_BrushGenProgram);
prog->Apply();
prog->SetUniformFloat("hardness", 1.0f);
glBindImageTexture(0, m_BrushTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
const int WORK_GROUP_SIZE = 32;
GLuint WorkGroupSize = GLuint((m_BRUSH_RES + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE));
glDispatchCompute(WorkGroupSize, WorkGroupSize, 1);
m_DrawProgram = g_ShaderBank.LoadShaderProgram("../../../shader/SpriteShader.glsl");
m_BrushTex = new Texture();
m_BrushTex->Init("../../../binasset/texture/brush.png", TEXTURE_COLOR);
m_FilterProgram = g_ShaderBank.LoadShaderProgram("../../../shader/TerrainDeformFilter.glsl");
}
示例11: assign_shader_layouts
/*-------------------------------------
* Set the vertex layout locations for an unlinked shader program
-------------------------------------*/
bool ShaderProgramAssembly::assign_shader_layouts(
const ShaderProgram& prog,
const ShaderObject& shdr
) const noexcept {
if (prog.get_attached_shader_id(shdr.get_shader_type()) != shdr.gpu_id()) {
return false;
}
// fragment shaders in OpenGLES 3.0 can't have their location manually
// specified as glBindFragDataLocation is unavailable. Geometry shaders on
// desktop GL versions should not have attribs as it increases the amount
// of required maintenance for a feature with limited support.
if (shdr.get_shader_type() != shader_stage_t::SHADER_STAGE_VERTEX) {
return true;
}
// Manually assign layout locations so OpenGL doesn't optimize out
// perfectly valid locations of variables.
const ShaderAttribArray& attribs = shdr.get_attribs();
for (unsigned i = 0; i < attribs.get_num_attribs(); ++i) {
const ShaderAttrib& attrib = attribs.get_attrib(i);
glBindAttribLocation(prog.gpu_id(), attrib.get_location(), attrib.get_name().get());
LS_LOG_GL_ERR();
}
return true;
}
示例12: glEnable
void Font::Flush(float deltaTime)
{
//flush all of the vertices to the GPU for drawing
if (!preRenderStage)
{
timer += deltaTime;
if (timer > 1.f / 60.f) //60fps text updating
{
timer = 0;
preRenderStage = true;
//clear out the memory to start rendering new ones
vertices = new vector<Vertex>();
indices = new vector<int>();
}
}
else
{
m->SetVertices(vertices, GL_STREAM_DRAW, true);
m->SetIndices(indices, GL_STREAM_DRAW, true);
m->FlushBuffers();
preRenderStage = false;
}
glEnable(GL_BLEND);
renderer->Ready();
ShaderProgram *prog = renderer->GetProgram();
prog->SetUniform("MVP", (void*)value_ptr(guiCam->Get()));
renderer->Render();
glDisable(GL_BLEND);
}
示例13: enable
void VertexLayout::enable(RenderState& rs, ShaderProgram& _program, size_t _byteOffset, void* _ptr) {
GLuint glProgram = _program.getGlProgram();
// Enable all attributes for this layout
for (auto& attrib : m_attribs) {
GLint location = _program.getAttribLocation(attrib.name);
if (location != -1) {
auto& loc = rs.attributeBindings[location];
// Track currently enabled attribs by the program to which they are bound
if (loc != glProgram) {
GL::enableVertexAttribArray(location);
loc = glProgram;
}
void* data = (unsigned char*)_ptr + attrib.offset + _byteOffset;
GL::vertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized, m_stride, data);
}
}
// Disable previously bound and now-unneeded attributes
for (size_t i = 0; i < RenderState::MAX_ATTRIBUTES; ++i) {
GLuint& boundProgram = rs.attributeBindings[i];
if (boundProgram != glProgram && boundProgram != 0) {
GL::disableVertexAttribArray(i);
boundProgram = 0;
}
}
}
示例14: update
void Entity::update(float& lastFrameTicks, float& elapsed, Matrix& projectionMatrix, Matrix& viewMatrix, ShaderProgram& program, bool stat) {
// Update modelMatrix
Matrix modelMatrix;
static bool wall = false;
if (stat) {
modelMatrix.identity();
modelMatrix.Scale(0.5, 2, 0);
program.setModelMatrix(modelMatrix);
}
else {
if (y >= -0.65) {
if (x > -1.85 && !wall) {
x -= elapsed/2;
}
if (x <= -1.85) {
wall = true;
y -= elapsed*2;
}
if (x < 1.85 && wall) {
x += elapsed/2;
}
if (x >= 1.85) {
wall = false;
y -= elapsed*4;
}
}
modelMatrix.identity();
modelMatrix.Scale(0.5, 2, 0);
modelMatrix.Translate(x, y+0.4, 0);
program.setModelMatrix(modelMatrix);
}
}
示例15: cannotLinkProgramWithoutShader
void cannotLinkProgramWithoutShader()
{
ShaderProgram shaderProgram;
QVERIFY(!shaderProgram.link());
QCOMPARE(shaderProgram.getLastLinkLog().c_str(), "Cannot link program because no shader is attached!");
}