1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
bool Success = true;
std::string nomVP = VERTEX_SHADER_SOURCE;
std::string nomFP = FRAGMENT_SHADER_SOURCE;
std::string nomGP = GEOMETRY_SHADER_SOURCE;
//nomRessource = nom;
bool l_bGeometryShader = false;
// Create the program object container.
GLuint shaderID = glCreateProgramObjectARB();
GLuint vertexID = 0;
GLuint fragmentID = 0;
GLuint geomertyID = 0;
programName = shaderID;
char error[4096];
int result = 0;
// Load the vertex shader.
std::string shaderCode = LoadShader(nomVP.c_str());
// si NULL: le fichier n'est pas lu
if (shaderCode.size() < 1)
{
return false;
}
vertexID = glCreateShaderObjectARB(GL_VERTEX_SHADER);
const char * source = shaderCode.c_str();
glShaderSourceARB(vertexID, 1, (const char**)&source, NULL);
glCompileShaderARB(vertexID);
glGetObjectParameterivARB(vertexID, GL_OBJECT_COMPILE_STATUS_ARB, &result);
// Load the geomerty shader
// le geometry shader est facultatif
shaderCode = LoadShader(nomGP);
if (shaderCode.size() > 1)
{
geomertyID = glCreateShaderObjectARB(GL_GEOMETRY_SHADER_EXT);
source = shaderCode.c_str();
glShaderSourceARB(geomertyID, 1, (const char**)&source, NULL);
glCompileShaderARB(geomertyID);
glGetObjectParameterivARB(geomertyID, GL_OBJECT_COMPILE_STATUS_ARB, &result);
l_bGeometryShader = true;
}
// Load the pixel shader.
shaderCode = LoadShader(nomFP);
if (shaderCode.size() < 1)
{
return false;
}
fragmentID = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
source = shaderCode.c_str();
glShaderSourceARB(fragmentID, 1, (const char**)&source, NULL);
glCompileShaderARB(fragmentID);
glGetObjectParameterivARB(fragmentID, GL_OBJECT_COMPILE_STATUS_ARB, &result);
if (l_bGeometryShader)
{
////Setup Geometry Shader////
//Set POINTS primitives as INPUT
glProgramParameteriEXT(shaderID,GL_GEOMETRY_INPUT_TYPE_EXT , GL_TRIANGLES );
//Set TRIANGLE STRIP as OUTPUT
glProgramParameteriEXT(shaderID,GL_GEOMETRY_OUTPUT_TYPE_EXT , GL_TRIANGLE_STRIP);
//Set maximum number of vertices to be generated by Geometry Shader
//This parameter is very important and have an important impact on Shader performances
//Its value must be chosen closer as possible to real maximum number of vertices
glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT,&(int)m_nNBMaxGeometrieOutVerctice); glProgramParameteriEXT(shaderID,GL_GEOMETRY_VERTICES_OUT_EXT, m_nNBMaxGeometrieOutVerctice);
}
// attachement
glAttachObjectARB(shaderID, vertexID);
if (l_bGeometryShader)
{
glAttachObjectARB(shaderID, geomertyID);
}
glAttachObjectARB(shaderID, fragmentID);
// Link them together
glLinkProgram(shaderID);
glGetObjectParameterivARB(shaderID, GL_OBJECT_LINK_STATUS_ARB, &result);
glGetInfoLogARB(shaderID, sizeof(error), NULL, error); |
Partager