本文整理汇总了C++中ShaderProgram::bind方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::bind方法的具体用法?C++ ShaderProgram::bind怎么用?C++ ShaderProgram::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
//void Renderer::draw(const VertexArray& va, const ElementBuffer& eb, const ShaderProgram& shader) const
void Renderer::draw(const VertexArray& va, const ElementBuffer& eb, const ShaderProgram& shader)
{
va.bind();
eb.bind();
shader.bind();
GLCall(glDrawElements(GL_TRIANGLES, eb.count(), GL_UNSIGNED_INT, nullptr));
//
// UNBIND [optional]... discuss
}
示例2:
/*!
Set a shader program to be used in the current rendering pipeline
@param shader Reference to the shader program to set as active
@return Wether the specified shader was set as active or not.
*/
bool sgct::ShaderManager::bindShaderProgram( const ShaderProgram & shaderProgram ) const
{
if( shaderProgram == NullShader )
{
sgct::MessageHandler::instance()->print(sgct::MessageHandler::NOTIFY_WARNING, "Could not set shader program [Invalid Pointer] as active: Not found in manager.\n");
glUseProgram( GL_FALSE ); //unbind to prevent errors
return false;
}
return shaderProgram.bind();
}
示例3: startBatch
void BatchSpriteRenderer::startBatch() {
checkGLError("BatchSpriteRenderer Start");
glBindTexture(GL_TEXTURE_2D, textureId);
glFrontFace(GL_CW);
if (context->gConfig->useShaders) {
ShaderProgram *shaderProgram = context->glResourceManager->getShaderProgram("quad");
shaderProgram->bind();
glUniform1i(shaderProgram->getUniformLoc("tex"), 0);
Vector4f colorFilter = context->renderContext->colorFilter;
glUniform4f(shaderProgram->getUniformLoc("colorFilter"), colorFilter.x,colorFilter.y,colorFilter.z,colorFilter.a);
}
}
示例4: getShaderProgram
/*!
Set a shader program to be used in the current rendering pipeline
@param name Name of the shader program to set as active
@return Wether the specified shader was set as active or not.
*/
bool sgct::ShaderManager::bindShaderProgram( const std::string & name ) const
{
ShaderProgram sp = getShaderProgram( name );
if( sp == NullShader )
{
sgct::MessageHandler::instance()->print(sgct::MessageHandler::NOTIFY_WARNING, "Could not set shader program [%s] as active: Not found in manager.\n", name.c_str() );
glUseProgram( GL_FALSE ); //unbind to prevent errors
return false;
}
return sp.bind();
}
示例5: draw_integer
void MeshRenderer::draw_integer(unsigned int name)
{
if (!data_ || !data_->vertices || !data_->triangles)
return;
//set up vertex array object
if (update_)
{
update();
update_ = false;
}
ShaderProgram* shader = 0;
glBindVertexArray(m_vao);
GLMgroup* group = data_->groups;
GLint pos = 0;
//set up shader
shader = msh_shader_factory_.shader(1,
0, false, false, false);
if (shader)
{
if (!shader->valid())
shader->create();
shader->bind();
}
//uniforms
shader->setLocalParamMatrix(0, glm::value_ptr(m_proj_mat));
shader->setLocalParamMatrix(1, glm::value_ptr(m_mv_mat));
shader->setLocalParamUInt(0, name);
while (group)
{
if (group->numtriangles == 0)
{
group = group->next;
continue;
}
//draw
glDrawArrays(GL_TRIANGLES, pos, (GLsizei)(group->numtriangles*3));
pos += group->numtriangles*3;
group = group->next;
}
glBindVertexArray(0);
// Release shader.
if (shader && shader->valid())
shader->release();
}
示例6: initGL
void initGL(){
glClearColor(1,1,1,1);
srand( time(NULL) );
string Vert = AVertex + Varying + UMatrix + NTransform + VLighting + VCalc + MVert;
string Frag = USampler + Varying + MFrag;
program.source(Vert,Frag);
program.bind();
Pipe::BindAttributes();
program.unbind();
}
示例7: initGL
void initGL(){
glClearColor(1,1,1,1);
srand( time(NULL) );
string Vert = AVertex + Varying + UMatrix + NTransform + VLighting + VCalc + MVert;
string Frag = MFrag;
program.source(Vert,Frag);
program.bind();
pipe.bindAttributes();
program.unbind();
pipe.program = &program;
initBufferObjects();
}
示例8: onDraw
virtual void onDraw(){
using namespace vsr;
static Circle c = CXY(1).trs(0,0,-3);
static Point p = PT(0,0,0);
static Field<Pnt> f(30,30,1,.1);
//static Field<Sca> f(30,30,1);
static DualSphere dls = Ro::dls(p, .3);
Par par = Gen::bst( Ro::par( dls, Vec::y) * .1);
static double time = 0.0; time += .01;
Circle tc = c.sp( Gen::mot( DLN(1,0,0).trs(0,0,-3) * time ) );
Vector tv = Vec(1,0,0).sp( Gen::rot( Biv::xy * time ) );
for (int i = 0; i < f.num(); ++i){
double dist = 1.0 / ( Ro::sqd( f[i], PAO ) +.01 );
f[i] = Ro::loc( f[i] .sp( Gen::bst( par * dist) ) );//.sp(bst) );
}
//Dipole changes size and moves around screen
dls = Ro::dls(p, .3 + sin(time) ).trs(1,0,0).sp( Gen::mot( DLN(0,0,1) * time ) );
program.bind();
program.uniform("projection", scene.xf.proj);
program.uniform("lightPosition", 2.0, 2.0, 2.0);
program.uniform("normalMatrix", scene.xf.normal);
program.uniform("modelView", scene.xf.modelView );//app.scene().xf.modelView);
Render( f, scene.xf.modelViewMatrixf(), program );
//Pipe::Line(circle);
program.unbind();
}
示例9: main
void
PhysicsRendererer::initShader()
{
//--------------------------------------------------------------------------
// setup the shader
//--------------------------------------------------------------------------
const GLchar * vertexShaderSrc =
"attribute vec3 positionAttr;"
""
"uniform mat4 projectionTransform;"
"uniform mat4 viewTransform;"
"uniform mat4 modelTransform;"
""
"void main() {"
" gl_Position = projectionTransform * viewTransform * modelTransform * vec4(positionAttr.xyz, 1.0);"
"}";
const GLchar * fragShaderSrc =
""
"uniform " HIGHP " vec3 color;"
""
"void main() {"
" gl_FragColor = vec4(color,1.0);"
"}";
_shader.setVertexShaderSrc(vertexShaderSrc);
_shader.setFragmentShaderSrc(fragShaderSrc);
_shader.declareAttrib("positionAttr", _positionAttrib);
_shader.initGL();
//--------------------------------------------------------------------------
// setup the shader matrices
//--------------------------------------------------------------------------
_proj.makeOrtho(0, 1, 0, 1, 1, 10);
_view.makeLookAt(0, 0, 4, 0, 0, 0, 0, 1, 0);
_model.makeIdentity();
_shader.bind();
_shader.setUniformMat4fv("projectionTransform", _proj.get());
_shader.setUniformMat4fv("viewTransform", _view.get());
_shader.setUniformMat4fv("modelTransform", _model.get());
_shader.unbind();
}
示例10: onRender
void SkyBox::onRender()
{
glPushMatrix();
GLfloat modelviewMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelviewMatrix);
// Remove translation from modelview matrix.
for (int i = 12; i <= 14; i++)
modelviewMatrix[i] = 0.0f;
glLoadMatrixf(modelviewMatrix);
glScalef(500.0f, 500.0f, 500.0f);
glTranslatef(0.0f, 0.2f, 0.0f);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
glVertexAttribPointer(2, 2, GL_SHORT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(2);
ShaderProgram *program = m_engine->m_skyboxProgram;
program->bind();
program->sendMatrices();
program->sendUniform("texture0", 0);
program->sendMaterialProps(m_materialProps);
for (int i = 0; i < 5; i++)
{
glBindTexture(GL_TEXTURE_2D, m_textures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glDrawArrays(GL_QUADS, (i) * 4, 4);
}
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(0);
glPopMatrix();
}
示例11: run
static void run(int argc, char *argv[])
{
Logger::init(&cerr);
GLFWwindow *window;
srand(time(nullptr));
if (!glfwInit())
throw runtime_error("Couldn't initialize GLFW.");
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "KUIPER RACE", nullptr, nullptr);
if (!window) {
glfwTerminate();
throw runtime_error("Couldn't create GLFWwindow.");
}
InputHandler &input = InputHandler::getInstance();
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetKeyCallback(window, InputHandler::keyCallback);
glfwSetCursorPosCallback(window, InputHandler::mousePositionCallback);
glfwSetMouseButtonCallback(window, InputHandler::mouseButtonCallback);
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
glfwDestroyWindow(window);
glfwTerminate();
throw runtime_error("Couldn't initialize GLEW.");
}
glfwSwapInterval(1);
glClearColor(0, 0, 0, 1);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
TransformPipeline tp;
tp.perspectiveProjection(70, width, WINDOW_HEIGHT, 0.1f, 100000);
TransformPipeline tpHud;
tpHud.orthographicProjection(-width / 2, width / 2, -height / 2, height / 2, -10, 10);
initialize();
Texture gbufferDiffuse(width, height, Texture::RGBA8, Texture::RGB, Texture::UnsignedByte);
Texture gbufferDepth(width, height, Texture::DepthComponent32f, Texture::Depth, Texture::Float);
Framebuffer framebuffer;
framebuffer.bind(Framebuffer::DrawFramebuffer);
framebuffer.attachTexture(gbufferDiffuse, Framebuffer::Color0);
framebuffer.attachTexture(gbufferDepth, Framebuffer::Depth);
framebuffer.drawBuffers({Framebuffer::Color0});
framebuffer.unbind(Framebuffer::DrawFramebuffer);
ShaderProgram postprocessShader("shaders/postprocess.vert", "shaders/postprocess.frag");
postprocessShader.bindAttribLocation("in_Position", 0);
postprocessShader.bindFragDataLocation("out_Color", 0);
postprocessShader.link();
postprocessShader.bind();
postprocessShader["u_Texture"].set1i(1);
postprocessShader["u_Depth"].set1i(2);
postprocessShader["u_Width"].set1f(width);
postprocessShader["u_Height"].set1f(height);
postprocessShader.unbind();
Sampler samplerScreenquad(Sampler::MinLinear, Sampler::MagLinear, Sampler::ClampToEdge);
ShaderProgram *screenShader = Registry::shaders["screen"];
bool running = true;
bool titleScreen = true;
float currentTime = glfwGetTime();
level.init();
while (running) {
float dt = glfwGetTime() - currentTime;
currentTime = glfwGetTime();
input.poll();
if (glfwWindowShouldClose(window) || input.keyWasPressed(InputHandler::Quit))
running = false;
update(dt);
float speed = level.getShipSpeed();
tp.perspectiveProjection(58 + speed * 0.9, width, height, 0.1f, 100000);
//.........这里部分代码省略.........
示例12: draw_wireframe
void MeshRenderer::draw_wireframe()
{
if (!data_ || !data_->vertices || !data_->triangles)
return;
//set up vertex array object
if (update_)
{
update();
update_ = false;
}
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
ShaderProgram* shader = 0;
glBindVertexArray(m_vao);
GLMgroup* group = data_->groups;
GLint pos = 0;
int peel = 0;
bool tex = false;
bool light = false;
//set up shader
shader = msh_shader_factory_.shader(0,
peel, tex, fog_, light);
if (shader)
{
if (!shader->valid())
shader->create();
shader->bind();
}
//uniforms
shader->setLocalParamMatrix(0, glm::value_ptr(m_proj_mat));
shader->setLocalParamMatrix(1, glm::value_ptr(m_mv_mat));
GLMmaterial* material = &data_->materials[0];
if (material)
shader->setLocalParam(0, material->diffuse[0], material->diffuse[1], material->diffuse[2], material->diffuse[3]);
else
shader->setLocalParam(0, 1.0, 0.0, 0.0, 1.0);
shader->setLocalParam(3, 0.0, 1.0, 0.0, 0.0);//alpha
if (fog_)
shader->setLocalParam(8, m_fog_intensity, m_fog_start, m_fog_end, 0.0);
while (group)
{
if (group->numtriangles == 0)
{
group = group->next;
continue;
}
//draw
glDrawArrays(GL_TRIANGLES, pos, (GLsizei)(group->numtriangles*3));
pos += group->numtriangles*3;
group = group->next;
}
glBindVertexArray(0);
// Release shader.
if (shader && shader->valid())
shader->release();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
示例13: draw
void MeshRenderer::draw()
{
if (!data_ || !data_->vertices || !data_->triangles)
return;
//set up vertex array object
if (update_)
{
update();
update_ = false;
}
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
ShaderProgram* shader = 0;
glBindVertexArray(m_vao);
GLMgroup* group = data_->groups;
GLint pos = 0;
bool tex = data_->hastexture==GL_TRUE;
while (group)
{
if (group->numtriangles == 0)
{
group = group->next;
continue;
}
//set up shader
shader = msh_shader_factory_.shader(0,
depth_peel_, tex, fog_, light_);
if (shader)
{
if (!shader->valid())
shader->create();
shader->bind();
}
//uniforms
shader->setLocalParamMatrix(0, glm::value_ptr(m_proj_mat));
shader->setLocalParamMatrix(1, glm::value_ptr(m_mv_mat));
if (light_)
{
glm::mat4 normal_mat = glm::mat4(glm::inverseTranspose(glm::mat3(m_mv_mat)));
shader->setLocalParamMatrix(2, glm::value_ptr(normal_mat));
GLMmaterial* material = &data_->materials[group->material];
if (material)
{
shader->setLocalParam(0, material->ambient[0], material->ambient[1], material->ambient[2], material->ambient[3]);
shader->setLocalParam(1, material->diffuse[0], material->diffuse[1], material->diffuse[2], material->diffuse[3]);
shader->setLocalParam(2, material->specular[0], material->specular[1], material->specular[2], material->specular[3]);
shader->setLocalParam(3, material->shininess, alpha_, 0.0, 0.0);
}
}
else
{//color
GLMmaterial* material = &data_->materials[group->material];
if (material)
shader->setLocalParam(0, material->diffuse[0], material->diffuse[1], material->diffuse[2], material->diffuse[3]);
else
shader->setLocalParam(0, 1.0, 0.0, 0.0, 1.0);//color
shader->setLocalParam(3, 0.0, alpha_, 0.0, 0.0);//alpha
}
if (tex)
{
GLMmaterial* material = &data_->materials[group->material];
if (material)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,
material->textureID);
}
}
if (fog_)
shader->setLocalParam(8, m_fog_intensity, m_fog_start, m_fog_end, 0.0);
if (depth_peel_)
shader->setLocalParam(7, 1.0/double(vp[2]), 1.0/double(vp[3]), 0.0, 0.0);
//draw
glDrawArrays(GL_TRIANGLES, pos, (GLsizei)(group->numtriangles*3));
pos += group->numtriangles*3;
group = group->next;
}
glBindVertexArray(0);
// Release shader.
if (shader && shader->valid())
shader->release();
//release texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
}
示例14: render
void RenderDevice::render( const RenderState& state, const LightQueue& lights )
{
BufferManager* buffers = activeContext->bufferManager;
ProgramManager* programs = activeContext->programManager;
RenderBatch* renderable = state.renderable;
bindBuffers(renderable);
const GeometryBuffer* gb = renderable->getGeometryBuffer().get();
if( gb->data.Empty() ) return;
BufferEntry* bufs = buffers->getBuffer(gb);
// Setup the vertex buffer format.
VertexBuffer* vb = bufs->vb.get();
renderBackend->setupVertexBuffer(vb);
Material* material = state.material;
ShaderMaterial* shader = material->getShader().Resolve();
ShaderProgram* shaderProgram = programs->getProgram(shader);
if( !shaderProgram ) return;
if( !shaderProgram->isLinked() && !shaderProgram->link() )
return;
shaderProgram->bind();
renderBackend->setupRenderState(state, true);
bindTextureUnits(state, true);
if( !renderable->onPreRender.empty() )
{
// Call the user pre render hook.
renderable->onPreRender(activeView, state);
}
RenderLayer stage = renderable->getRenderLayer();
if( stage != RenderLayer::Overlays )
{
if( !setupRenderStateMatrix(state) )
return;
//if( !setupRenderStateLight(state, lights) )
// return;
}
else if( stage == RenderLayer::Overlays )
{
if( !setupRenderStateOverlay(state) )
return;
}
UniformBuffer* ub = renderable->getUniformBuffer().get();
shaderProgram->setUniforms(ub);
renderBackend->renderBatch(renderable);
if( !renderable->onPostRender.empty() )
{
// Call the user post render hook.
renderable->onPostRender(activeView, state);
}
renderBackend->unsetupRenderState(state);
unbindTextureUnits(state.material);
shaderProgram->unbind();
renderBackend->unbindVertexBuffer(vb);
unbindBuffers(renderable);
}
示例15: render
DRReturn PlanetSektor::render(float fTime, Camera* cam)
{
#if SDL_VERSION_ATLEAST(1,3,0)
Uint8 *keystate = SDL_GetKeyboardState(NULL);
#else
Uint8 *keystate = SDL_GetKeyState(NULL);
#endif
//if(isObjectInSektor(cam->getSektorPosition())) return DR_OK;
//Unit distance1 = Vector3Unit(mSektorPosition - cam->getSektorPosition()).length();
//Unit distance1 = Vector3Unit(mSektorPosition - mLastRelativeCameraPosition).length();
Unit distance1 = (-mLastRelativeCameraPosition).length();
//DRVector3 diff = Vector3Unit(mSektorPosition - cam->getSektorPosition()).convertTo(KM).getVector3();
distance1 = distance1.convertTo(mRadius.getType());
double distance2 = 200.0f;
Unit radius1 = mRadius;
double radius2 = ((radius1 * distance2) / distance1);
//DRVector3 pos = (mSektorPosition - cam->getSektorPosition()).getVector3().normalize();
//DRVector3 pos = (mSektorPosition - mLastRelativeCameraPosition).getVector3().normalize();
DRVector3 pos = (-mLastRelativeCameraPosition).getVector3().normalize();
// DRVector3 relCameraPos = -pos*distance1/mRadius;
pos *= static_cast<DRReal>(distance2);
/* printf("\r %f %f %f, %.8f, %s x:%s y:%s z:%s (%f %f %f)", pos.x, pos.y, pos.z, radius2, distance1.print().data(),
absCameraPosition.x.print().data(), absCameraPosition.y.print().data(),
absCameraPosition.z.print().data(), diff.x, diff.y, diff.z);
//*/
//glTranslatef(pos.x, pos.y, pos.z);
//glScaled(radius2, radius2, radius2);
mMatrix = DRMatrix::scaling(DRVector3(static_cast<DRReal>(radius2))) * DRMatrix::translation(pos) * cam->getKameraMatrixRotation();
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//if(mRenderer && !isObjectInSektor(cam->getSektorPosition()))
//DRReturn ret = mRenderer->render(fTime, cam);
if(!isObjectInSektor(mLastRelativeCameraPosition))
{
mNotRenderSeconds = 0.0f;
if(!mRenderer)
mRenderer = new RenderPlanet(mID, getSektorPathName(), &mPlanetNoiseParameters);
if(!mRenderer) LOG_ERROR("no renderer", DR_ERROR);
if(radius2 > 160.0f) mRenderer->setCurrentDetail(10);
else if(radius2 > 140.0f) mRenderer->setCurrentDetail(9);
else if(radius2 > 120.0f) mRenderer->setCurrentDetail(8);
else if(radius2 > 90.0f) mRenderer->setCurrentDetail(7);
else if(radius2 > 70.0f) mRenderer->setCurrentDetail(6);
else if(radius2 > 30.0f) mRenderer->setCurrentDetail(5);
else if(radius2 > 25.0f) mRenderer->setCurrentDetail(4);
else if(radius2 > 15.0f) mRenderer->setCurrentDetail(3);
else if(radius2 > 5.0f) mRenderer->setCurrentDetail(2);
else if(radius2 > 1.0f) mRenderer->setCurrentDetail(1);
else mRenderer->setCurrentDetail(0);
//GlobalRenderer::getSingleton().getPlanetShaderPtr()->bind();
ShaderProgram* shader = mRenderer->getShaderProgram();
if(!shader) LOG_ERROR("RenderPlanet hasn't valid shader", DR_ERROR);
shader->bind();
shader->setUniformMatrix("modelview", mMatrix);
shader->setUniformMatrix("projection", GlobalRenderer::Instance().getProjectionMatrix().transpose());
DRGrafikError("PlanetSektor::render");
DRReturn ret = mRenderer->render(fTime, cam);
shader->unbind();
// GlobalRenderer::getSingleton().getPlanetShaderPtr()->unbind();
if(ret) LOG_ERROR("Fehler bei call planet renderer", DR_ERROR);
//child didn't need to render
return DR_NOT_ERROR;
//return DR_OK;
}
else
{
mNotRenderSeconds += fTime;
}
return DR_OK;
}