MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / create

Method create

testbed/opengl-framework/src/Shader.cpp:55–206  ·  view source on GitHub ↗

Create the shader

Source from the content-addressed store, hash-verified

53
54// Create the shader
55bool Shader::create(const std::string vertexShaderFilename,
56 const std::string fragmentShaderFilename) {
57
58 // Set the shader filenames
59 mFilenameVertexShader = vertexShaderFilename;
60 mFilenameFragmentShader = fragmentShaderFilename;
61
62 // Check that the needed OpenGL extensions are available
63 /*bool isExtensionOK = checkOpenGLExtensions();
64 if (!isExtensionOK) {
65 cerr << "Error : Impossible to use GLSL vertex or fragment shaders on this platform" << endl;
66 assert(false);
67 return false;
68 }*/
69
70 // Delete the current shader
71 destroy();
72
73 assert(!vertexShaderFilename.empty() && !fragmentShaderFilename.empty());
74
75 // ------------------- Load the vertex shader ------------------- //
76 GLuint vertexShaderID;
77 std::ifstream fileVertexShader;
78 fileVertexShader.open(vertexShaderFilename.c_str(), std::ios::binary);
79
80 if (fileVertexShader.is_open()) {
81
82 // Get the size of the file
83 fileVertexShader.seekg(0, std::ios::end);
84 uint fileSize = (uint) (fileVertexShader.tellg());
85 assert(fileSize != 0);
86
87 // Read the file
88 fileVertexShader.seekg(std::ios::beg);
89 char* bufferVertexShader = new char[fileSize + 1];
90 fileVertexShader.read(bufferVertexShader, fileSize);
91 fileVertexShader.close();
92 bufferVertexShader[fileSize] = '\0';
93
94 // Create the OpenGL vertex shader and compile it
95 vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
96 assert(vertexShaderID != 0);
97 glShaderSource(vertexShaderID, 1, (const char **) (&bufferVertexShader), NULL);
98 glCompileShader(vertexShaderID);
99 delete[] bufferVertexShader;
100
101 // Get the compilation information
102 int compiled;
103 glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &compiled);
104
105 // If the compilation failed
106 if (compiled == 0) {
107
108 // Get the log of the compilation
109 int lengthLog;
110 glGetShaderiv(vertexShaderID, GL_INFO_LOG_LENGTH, &lengthLog);
111 char* str = new char[lengthLog];
112 glGetShaderInfoLog(vertexShaderID, lengthLog, NULL, str);

Callers 15

readTGAPictureMethod · 0.45
readJPEGPictureMethod · 0.45
createVBOAndVAOMethod · 0.45
createQuadVBOMethod · 0.45
createDebugVBOMethod · 0.45
createVBOAndVAOMethod · 0.45
createVBOAndVAOMethod · 0.45
createVBOAndVAOMethod · 0.45
createVBOAndVAOMethod · 0.45
createVBOAndVAOMethod · 0.45
createVBOAndVAOMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected