本文整理汇总了C++中ShaderProgram::getProgram方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::getProgram方法的具体用法?C++ ShaderProgram::getProgram怎么用?C++ ShaderProgram::getProgram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::getProgram方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeBuffers
void GLPatch::initializeBuffers(ShaderProgram & shaderProgram) {
std::vector<BezierPatch> patchesv;
ReadBezierPatches("data/teapot.data", patchesv);
float patchesf[patchesv.size()][192];
for (int i = 0; i < patchesv.size(); i++)
{
float patch[192];
paramSurfaces(patchesv[i], patch);
m_numberOfPatches[i] = sizeof(patch) / sizeof(float); //i know this will be constant
m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
GLuint m_Patch;
m_Patches[i] = m_Patch;
glGenBuffers(1, &m_Patch);
glBindBuffer(GL_ARRAY_BUFFER, m_Patch);
glBufferData(GL_ARRAY_BUFFER, sizeof(patch), patch, GL_STATIC_DRAW);
}
// glGenBuffers(1, &m_Patch);
// glBindBuffer(GL_ARRAY_BUFFER, m_Patch);
// glBufferData(GL_ARRAY_BUFFER, sizeof(patch), patch, GL_STATIC_DRAW);
glm::vec3 Normal = glm::cross((patchesv[0][0][0] - patchesv[0][0][2]),(patchesv[0][0][2] - patchesv[0][3][3]));
glm::vec3 N = glm::normalize(glm::vec3(Normal[0]+0.00001f,Normal[1]+0.000001f,Normal[2]+0.00001f));
glUniform4f(glGetUniformLocation(shaderProgram.getProgram(), "uNormal"), N[0], N[0], N[2], 1.0);
//Get a handle to the shader attribute aPosition and set it up:
m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
示例2: renderSceneCB
static void renderSceneCB() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
triangleShaderProgram.useProgram();
glm::mat4 modelMatrix;
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.f, 0.0f, -105.0f));
glUniformMatrix4fv(glGetUniformLocation(triangleShaderProgram.getProgram(), "uModelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniform3f(glGetUniformLocation(triangleShaderProgram.getProgram(), "uColour"), 0.0f, 1.0f, 0.0f);
triangle.draw();
glutSwapBuffers();
}
示例3: createShaderProgram
ShaderProgram* Manager::createShaderProgram(std::string vertexShaderPath, std::string fragmentShaderPath)
{
ShaderProgram *shProg = new ShaderProgram();
shProg->addVertexShader(vertexShaderPath.c_str());
shProg->addFragmentShader(fragmentShaderPath.c_str());
glBindAttribLocation(shProg->getProgram(), VERTICES, "in_Position");
glBindAttribLocation(shProg->getProgram(), COLORS, "in_Color");
glBindAttribLocation(shProg->getProgram(), NORMALS, "in_Normal");
glBindAttribLocation(shProg->getProgram(), TEXTURE, "in_Texture");
shProg->link();
return shProg;
}
示例4: initializeBuffers
void GLTriangle::initializeBuffers(ShaderProgram & shaderProgram) {
m_numberOfVerticesFront = 5;
m_numberOfVerticesBack = 5;
float front[] = {
0.0f, 0.0f, 0.0f,
16.0f, 0.0f, 0.0f,
16.0f, 10.0f, 0.0f,
8.0f, 16.0f, 0.0f,
0.0f, 10.0f, 0.0f
};
// float back[] = {
// 0.0f, 0.0f, 30.0f,
// 16.0f, 0.0f, 30.0f,
// 16.0f, 10.0f, 30.0f,
// 8.0f, 16.0f, 30.0f,
// 0.0f, 10.0f, 30.0f
// };
m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
//Generate a vertex buffer object (m_VBO), and copy the array data (vertices) to it:
// glGenBuffers(1, &m_BackVBO);
// glBindBuffer(GL_ARRAY_BUFFER, m_BackVBO);
// glBufferData(GL_ARRAY_BUFFER, sizeof(back), back, GL_STATIC_DRAW);
// glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
glGenBuffers(1, &m_FrontVBO);
glBindBuffer(GL_ARRAY_BUFFER, m_FrontVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(front), front, GL_STATIC_DRAW);
glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
示例5: intializeShadersAndGLObjects
static void intializeShadersAndGLObjects() {
triangleShaderProgram.init(sVertexShader, sFragmentShader);
triangle.initializeBuffers(triangleShaderProgram);
triangleShaderProgram.useProgram();
glm::mat4 projectionMatrix = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
glUniformMatrix4fv(glGetUniformLocation(triangleShaderProgram.getProgram(), "uProjectionMatrix"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
}
示例6: initializeBuffers
void GLCurve::initializeBuffers(ShaderProgram & shaderProgram) {
m_numberOfCurves = 3;
float curve[9] = {
-33.978017f, -34.985076f, 50.214926f,
84.192943f, -13.784394f, -50.214926f,
-16.236910f, 83.754546f, -50.214926f
};
m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
//Generate a vertex buffer object (m_VBO), and copy the array data (vertices) to it:
glGenBuffers(1, &m_Curve);
glBindBuffer(GL_ARRAY_BUFFER, m_Curve);
glBufferData(GL_ARRAY_BUFFER, sizeof(curve), curve, GL_STATIC_DRAW);
//Get a handle to the shader attribute aPosition and set it up:
m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
示例7: initializeUniformLightBloc
void LightManager::initializeUniformLightBloc(ShaderProgram& aProgram, std::string aUniformLightBlocName)
{
mLightUniformLightBlocName = aUniformLightBlocName;
try
{
aProgram.loadUniformBloc(aUniformLightBlocName);
mUniformBlockIndex = aProgram.getUniformBloc(aUniformLightBlocName);
mUniformBlockBindingIndex = ShaderProgram::getNextGlobalUniformBlockBindingPointAvailable();
glUniformBlockBinding(aProgram.getProgram(), mUniformBlockIndex, mUniformBlockBindingIndex);
glGenBuffers(1, &mUniformBufferIndex);
glBindBuffer(GL_UNIFORM_BUFFER, mUniformBufferIndex);
//Init the buffer with zero everywhere
size_t uniformBufferSize = sizeof(Light)*mMaxLights;
char* zeroBuf = new char[uniformBufferSize]();
glBufferData(GL_UNIFORM_BUFFER, uniformBufferSize, zeroBuf, GL_DYNAMIC_DRAW);
delete[] zeroBuf;
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glBindBufferRange(GL_UNIFORM_BUFFER, mUniformBlockBindingIndex, mUniformBufferIndex, 0, uniformBufferSize);
}
catch(ShaderProgramUniformNotLoadedException &e)
{
std::cerr << e.what() << std::endl;
}
catch(ShaderProgramUniformNotFoundException &e)
{
std::cerr << e.what() << std::endl;
}
}
示例8: iterate
SharedBasicVarCase::IterateResult SharedBasicVarCase::iterate (void)
{
const glw::Functions& gl = m_context.getRenderContext().getFunctions();
const deUint32 program = m_program->getProgram();
Buffer outputBuffer (m_context.getRenderContext());
const deUint32 outBlockNdx = gl.getProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, "Result");
const InterfaceBlockInfo outBlockInfo = getProgramInterfaceBlockInfo(gl, program, GL_SHADER_STORAGE_BLOCK, outBlockNdx);
gl.useProgram(program);
// Setup input values.
{
const int numValues = (int)product(m_workGroupSize);
const int valLoc = gl.getUniformLocation(program, "u_val[0]");
const int refLoc = gl.getUniformLocation(program, "u_ref[0]");
const int iterCountLoc = gl.getUniformLocation(program, "u_numIters");
const int scalarSize = getDataTypeScalarSize(m_basicType);
if (isDataTypeFloatOrVec(m_basicType))
{
const int maxInt = m_precision == glu::PRECISION_LOWP ? 2 : 1024;
const int minInt = -de::min(numValues/2, maxInt);
vector<float> values (numValues*scalarSize);
for (int ndx = 0; ndx < (int)values.size(); ndx++)
values[ndx] = float(minInt + (ndx % (maxInt-minInt+1)));
for (int uNdx = 0; uNdx < 2; uNdx++)
{
const int location = uNdx == 1 ? refLoc : valLoc;
if (scalarSize == 1) gl.uniform1fv(location, numValues, &values[0]);
else if (scalarSize == 2) gl.uniform2fv(location, numValues, &values[0]);
else if (scalarSize == 3) gl.uniform3fv(location, numValues, &values[0]);
else if (scalarSize == 4) gl.uniform4fv(location, numValues, &values[0]);
}
}
else if (isDataTypeIntOrIVec(m_basicType))
{
const int maxInt = m_precision == glu::PRECISION_LOWP ? 64 : 1024;
const int minInt = -de::min(numValues/2, maxInt);
vector<int> values (numValues*scalarSize);
for (int ndx = 0; ndx < (int)values.size(); ndx++)
values[ndx] = minInt + (ndx % (maxInt-minInt+1));
for (int uNdx = 0; uNdx < 2; uNdx++)
{
const int location = uNdx == 1 ? refLoc : valLoc;
if (scalarSize == 1) gl.uniform1iv(location, numValues, &values[0]);
else if (scalarSize == 2) gl.uniform2iv(location, numValues, &values[0]);
else if (scalarSize == 3) gl.uniform3iv(location, numValues, &values[0]);
else if (scalarSize == 4) gl.uniform4iv(location, numValues, &values[0]);
}
}
else if (isDataTypeUintOrUVec(m_basicType))
{
const deUint32 maxInt = m_precision == glu::PRECISION_LOWP ? 128 : 1024;
vector<deUint32> values (numValues*scalarSize);
for (int ndx = 0; ndx < (int)values.size(); ndx++)
values[ndx] = ndx % (maxInt+1);
for (int uNdx = 0; uNdx < 2; uNdx++)
{
const int location = uNdx == 1 ? refLoc : valLoc;
if (scalarSize == 1) gl.uniform1uiv(location, numValues, &values[0]);
else if (scalarSize == 2) gl.uniform2uiv(location, numValues, &values[0]);
else if (scalarSize == 3) gl.uniform3uiv(location, numValues, &values[0]);
else if (scalarSize == 4) gl.uniform4uiv(location, numValues, &values[0]);
}
}
else if (isDataTypeBoolOrBVec(m_basicType))
{
de::Random rnd (0x324f);
vector<int> values (numValues*scalarSize);
for (int ndx = 0; ndx < (int)values.size(); ndx++)
values[ndx] = rnd.getBool() ? 1 : 0;
for (int uNdx = 0; uNdx < 2; uNdx++)
{
const int location = uNdx == 1 ? refLoc : valLoc;
if (scalarSize == 1) gl.uniform1iv(location, numValues, &values[0]);
else if (scalarSize == 2) gl.uniform2iv(location, numValues, &values[0]);
else if (scalarSize == 3) gl.uniform3iv(location, numValues, &values[0]);
else if (scalarSize == 4) gl.uniform4iv(location, numValues, &values[0]);
}
}
else if (isDataTypeMatrix(m_basicType))
{
const int maxInt = m_precision == glu::PRECISION_LOWP ? 2 : 1024;
const int minInt = -de::min(numValues/2, maxInt);
vector<float> values (numValues*scalarSize);
for (int ndx = 0; ndx < (int)values.size(); ndx++)
values[ndx] = float(minInt + (ndx % (maxInt-minInt+1)));
//.........这里部分代码省略.........