本文整理汇总了C++中GLSLProgram::getHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::getHandle方法的具体用法?C++ GLSLProgram::getHandle怎么用?C++ GLSLProgram::getHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLProgram
的用法示例。
在下文中一共展示了GLSLProgram::getHandle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: voxelRender
void MainGraphicsWidget::voxelRender()
{
VoxelGrid::getInstance()->buildVoxels(m_lightBuffer->getLight());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix3(NORMAL, glm::mat3(1.0f));
view->viewport();
view->use3D(true);
camera->transform();
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("Voxel");
glslProgram->use();
glBindFragDataLocation(glslProgram->getHandle(), 0, "fragColor");
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glslProgram->sendUniform("modelviewMatrix", &MatrixManager::getInstance()->getMatrix4(MODELVIEW)[0][0]);
glm::mat4 cameraInverse = glm::mat4(1.0);
cameraInverse = camera->transformToMatrix(cameraInverse);
cameraInverse = glm::inverse(cameraInverse);
glslProgram->sendUniform("invCameraMatrix", &cameraInverse[0][0]);
glslProgram->sendUniform("worldSize", WORLD_SIZE);
//glslProgram->sendUniform("numVoxels", VOXEL_SIZE);
//glslProgram->sendUniform("mipLevel", VoxelGrid::getInstance()->getMipLevel());
int mipFactor = pow(2.0, VoxelGrid::getInstance()->getMipLevel());
glActiveTexture(GL_TEXTURE8);
glEnable(GL_TEXTURE_3D);
VoxelGrid::getInstance()->bind(VoxelGrid::getInstance()->getMipLevel());
glslProgram->sendUniform("voxelmap", 8);
//glEnable(GL_POINT_SMOOTH);
glPointSize(10.0f*mipFactor);
float voxelWidth = (float)WORLD_SIZE / (float)VOXEL_SIZE * mipFactor;
glBegin(GL_POINTS);
for (float x=-(WORLD_SIZE/2.0)+(voxelWidth/2.0); x<(WORLD_SIZE/2.0); x+=voxelWidth)
{
for (float y=-(WORLD_SIZE/2.0)+(voxelWidth/2.0); y<(WORLD_SIZE/2.0); y+=voxelWidth)
{
for (float z=-(WORLD_SIZE/2.0)+(voxelWidth/2.0); z<(WORLD_SIZE/2.0); z+=voxelWidth)
{
glVertex3f(x,y,z);
}
}
}
glEnd();
glslProgram->disable();
}
示例2: forwardRender
void MainGraphicsWidget::forwardRender()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix3(NORMAL, glm::mat3(1.0f));
view->viewport();
view->use3D(true);
camera->transform();
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("Basic");
glslProgram->use();
glBindFragDataLocation(glslProgram->getHandle(), 0, "fragColor");
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
glBindAttribLocation(glslProgram->getHandle(), 1, "v_texture");
glBindAttribLocation(glslProgram->getHandle(), 2, "v_normal");
glBindAttribLocation(glslProgram->getHandle(), 3, "v_tangent");
glBindAttribLocation(glslProgram->getHandle(), 4, "v_bitangent");
glslProgram->sendUniform("light.direction", 1.0f,-5.0f,2.0f);
glslProgram->sendUniform("light.color", 1.0f,1.0f,1.0f);
glslProgram->sendUniform("light.ambient", 0.7f);
glslProgram->sendUniform("light.diffuse", 0.6f);
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glslProgram->sendUniform("modelviewMatrix", &MatrixManager::getInstance()->getMatrix4(MODELVIEW)[0][0]);
glslProgram->sendUniform("curveGeometry", false);
glm::mat4 cameraInverse = glm::mat4(1.0);
cameraInverse = camera->transformToMatrix(cameraInverse);
cameraInverse = glm::inverse(cameraInverse);
glslProgram->sendUniform("inverseCameraMatrix", &cameraInverse[0][0]);
glslProgram->sendUniform("cameraPos", camera->getEyeX(), camera->getEyeY(), camera->getEyeZ());
MaterialManager::getInstance()->getMaterial("Default")->sendToShader("Basic");
myGrid->draw();
SceneManager::getInstance()->draw("Basic");
glslProgram->disable();
SceneManager::getInstance()->drawTransformers();
}
示例3: buildShadowMaps
void CascadedShadowMap::buildShadowMaps(Camera *camera, View *view, DirectLight *light)
{
//Profiler::getInstance()->startProfile("Build Shadow Maps");
float nSlice[] = {0.0, m_nSlices[0], m_nSlices[1], m_nSlices[2], 1.0};
Frustum *frustum = new Frustum();
frustum->getFrustum(camera, view);
m_shadowMaps[3]->bind();
glClearDepth(1.0);
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_CULL_FACE);
for (int i=0; i<4; i++)
{
Camera *lightCamera = createLightCamera(nSlice[i],nSlice[i+1],camera,view,light);
View *lightView = createLightView(nSlice[i],nSlice[i+1],camera,lightCamera,view,frustum);
Frustum *lightFrustum = new Frustum();
lightFrustum->getOrthoFrustum(lightCamera,lightView);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
m_shadowMaps[i]->bind();
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glPushAttrib( GL_VIEWPORT_BIT );
glViewport( 0, 0, m_nSize, m_nSize);
lightView->use3D(false);
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("DirectShadow");
glslProgram->use();
glm::mat4 cameraMat = glm::mat4(1.0f);
cameraMat = lightCamera->transformToMatrix(cameraMat);
m_m4LightMatrix[i] = MatrixManager::getInstance()->getMatrix4(PROJECTION) * cameraMat;
MatrixManager::getInstance()->putMatrix4(MODELVIEW, cameraMat);
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
SceneManager::getInstance()->draw("DirectShadow");
glslProgram->disable();
glPopAttrib();
m_shadowMaps[i]->unbind();
delete lightCamera;
delete lightView;
delete lightFrustum;
}
glEnable(GL_CULL_FACE);
//Profiler::getInstance()->endProfile();
}
示例4: RenderScene
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLuint programHandle = prog.getHandle();
GLuint adsIndex = glGetSubroutineIndex( programHandle, GL_VERTEX_SHADER, "phongModel" );
GLuint diffuseIndex = glGetSubroutineIndex(programHandle, GL_VERTEX_SHADER, "diffuseOnly");
glUniformSubroutinesuiv( GL_VERTEX_SHADER, 1, &adsIndex);
model = mat4(1.0f);
model *= glm::translate(vec3(-3.0f,-1.5f,0.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
setMatrices();
teapot->render();
glUniformSubroutinesuiv( GL_VERTEX_SHADER, 1, &diffuseIndex);
model = mat4(1.0f);
model *= glm::translate(vec3(3.0f,-1.5f, 0.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
setMatrices();
teapot->render();
}
示例5: loadAssets
void loadAssets()
{
loadParticles();
loadPlane();
pstack.push(glm::perspective(45.0f,
(GLfloat)window.GetWidth()/window.GetHeight(), 0.1f, 175.0f));
mstack.push(glm::lookAt(vec3(0, 2.7, 7), vec3(0, 2.4, 6), vec3(0, 1, 0)));
// Load terrain shader
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-vert.glsl",
GLSLShader::VERTEX)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-frag.glsl",
GLSLShader::FRAGMENT)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-tc.glsl",
GLSLShader::TESS_CONTROL)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "terrain-te.glsl",
GLSLShader::TESS_EVALUATION)) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
if (!g_program.link()) {
fprintf(stderr, "%s\n", g_program.log().c_str());
exit(1);
}
// Load plane shader
if (!d_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "default-vert.glsl",
GLSLShader::VERTEX)) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
if (!d_program.compileShaderFromFile(
ROOT_PATH_RELATIVE SHADER_DIR "default-frag.glsl",
GLSLShader::FRAGMENT)) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
const char *outputNames[] = { "Position" };
glTransformFeedbackVaryings(d_program.getHandle(), 1, outputNames, GL_SEPARATE_ATTRIBS);
if (!d_program.link()) {
fprintf(stderr, "%s\n", d_program.log().c_str());
exit(1);
}
g_program.use();
g_program.setUniform("Viewport", viewport);
g_program.setUniform("MinTessLevel", 1.0f);
g_program.setUniform("MaxTessLevel", max_tess);
//g_program.setUniform("MaxTessLevel", 20.0f);
g_program.setUniform("NearClip", 0.1f);
g_program.setUniform("FarClip", 175.0f);
g_program.setUniform("NearFog", 10.0f);
g_program.setUniform("FarFog", 125.0f);
g_program.setUniform("Light0.position", vec3(L0POSITION));
g_program.setUniform("Light0.La", vec3(L0AMBIENT));
g_program.setUniform("Light0.Ld", vec3(L0DIFFUSE));
GLuint terrainmap = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "heightmap-vlarge.png",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint watermap = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "watermap.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex1 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "grass.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex2 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "stonesnow.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
GLuint ttex3 = SOIL_load_OGL_texture (
ROOT_PATH_RELATIVE TEXTURE_DIR "water.jpg",
SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_LOAD_L );
//.........这里部分代码省略.........
示例6: drawToBuffer
void IndirectBuffer::drawToBuffer(GLuint nDepthTex, GLuint nTangentTex, GLuint nBiangentTex, GLuint nNormalTex, GLuint nDiffuseTex, View *view, Camera *camera)
{
GLSLProgram *glslProgram = ShaderManager::getInstance()->getShader("Indirect");
glslProgram->use();
bind();
GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT};
glDrawBuffers(1, mrt);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushAttrib( GL_VIEWPORT_BIT );
glViewport( 0, 0, getWidth(), getHeight());
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
camera->transform();
view->use3D(true);
glm::mat4 m4InvMVP = MatrixManager::getInstance()->getMatrix4(PROJECTION) * MatrixManager::getInstance()->getMatrix4(MODELVIEW);
m4InvMVP = glm::inverse(m4InvMVP);
MatrixManager::getInstance()->putMatrix4(MODELVIEW, glm::mat4(1.0f));
MatrixManager::getInstance()->putMatrix4(PROJECTION, glm::mat4(1.0f));
view->use3D(false);
glBindFragDataLocation(glslProgram->getHandle(), 0, "glossyBuffer");
glBindAttribLocation(glslProgram->getHandle(), 0, "v_vertex");
glBindAttribLocation(glslProgram->getHandle(), 1, "v_texture");
glslProgram->sendUniform("projectionMatrix", &MatrixManager::getInstance()->getMatrix4(PROJECTION)[0][0]);
glslProgram->sendUniform("inverseMVPMatrix", &m4InvMVP[0][0]);
glslProgram->sendUniform("worldSize", WORLD_SIZE);
glslProgram->sendUniform("numVoxels", VOXEL_SIZE);
glActiveTexture(GL_TEXTURE8);
glEnable(GL_TEXTURE_3D);
VoxelGrid::getInstance()->bind(0);
glActiveTexture(GL_TEXTURE9);
glEnable(GL_TEXTURE_3D);
VoxelGrid::getInstance()->bind(1);
glActiveTexture(GL_TEXTURE10);
glEnable(GL_TEXTURE_3D);
VoxelGrid::getInstance()->bind(2);
glActiveTexture(GL_TEXTURE11);
glEnable(GL_TEXTURE_3D);
VoxelGrid::getInstance()->bind(3);
glslProgram->sendUniform("voxelmap[0]", 8);
glslProgram->sendUniform("voxelmap[1]", 9);
glslProgram->sendUniform("voxelmap[2]", 10);
glslProgram->sendUniform("voxelmap[3]", 11);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, nDepthTex);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, nTangentTex);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, nBiangentTex);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, nNormalTex);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, nDiffuseTex);
glslProgram->sendUniform("depthTex",0);
glslProgram->sendUniform("tanTex",1);
glslProgram->sendUniform("bitanTex",2);
glslProgram->sendUniform("normalTex",3);
glslProgram->sendUniform("diffuseTex",4);
drawScreenShader(0,0,1.0f,1.0f);
glFinish();
glslProgram->disable();
unbind();
}