//[-------------------------------------------------------] //[ Private methods ] //[-------------------------------------------------------] bool Direct3D9RuntimeLinking::loadSharedLibrary() { // Load the shared library mD3D9SharedLibrary = ::LoadLibraryExA("d3d9.dll", nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); if (nullptr == mD3D9SharedLibrary) { RENDERER_OUTPUT_DEBUG_STRING("Direct3D 10 error: Failed to load in the shared library \"d3d9.dll\"\n") } // Done return (nullptr != mD3D9SharedLibrary); }
/** * @brief * Load the shared libraries */ bool CgRuntimeLinking::loadSharedLibraries() { // Load the shared library #ifdef WIN32 mCgSharedLibrary = ::LoadLibraryExA("cg.dll", nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); if (nullptr != mCgSharedLibrary) { mCgGLSharedLibrary = ::LoadLibraryExA("cgGL.dll", nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); if (nullptr == mCgGLSharedLibrary) { RENDERER_OUTPUT_DEBUG_STRING("OpenGL error: Failed to load in the shared library \"cgGL.dll\"\n") } }
/** * @brief * Constructor */ ProgramGlsl::ProgramGlsl(OpenGLES2Renderer &openGLES2Renderer, VertexShaderGlsl *vertexShaderGlsl, FragmentShaderGlsl *fragmentShaderGlsl) : Program(openGLES2Renderer) { // Create the OpenGL ES 2 program mOpenGLES2Program = glCreateProgram(); // Attach the shaders to the program // -> We don't need to keep a reference to the shader, to add and release at once to ensure a nice behaviour if (nullptr != vertexShaderGlsl) { vertexShaderGlsl->addReference(); glAttachShader(mOpenGLES2Program, vertexShaderGlsl->getOpenGLES2Shader()); vertexShaderGlsl->release(); } if (nullptr != fragmentShaderGlsl) { fragmentShaderGlsl->addReference(); glAttachShader(mOpenGLES2Program, fragmentShaderGlsl->getOpenGLES2Shader()); fragmentShaderGlsl->release(); } // Link the program glLinkProgram(mOpenGLES2Program); // Check the link status GLint linked = GL_FALSE; glGetProgramiv(mOpenGLES2Program, GL_LINK_STATUS, &linked); if (GL_TRUE != linked) { // Error, program link failed! #ifdef RENDERER_OUTPUT_DEBUG // Get the length of the information (including a null termination) GLint informationLength = 0; glGetProgramiv(mOpenGLES2Program, GL_INFO_LOG_LENGTH, &informationLength); if (informationLength > 1) { // Allocate memory for the information char *informationLog = new char[static_cast<unsigned int>(informationLength)]; // Get the information glGetProgramInfoLog(mOpenGLES2Program, informationLength, nullptr, informationLog); // Ouput the debug string RENDERER_OUTPUT_DEBUG_STRING(informationLog) // Cleanup information memory delete [] informationLog; } #endif } }
//[-------------------------------------------------------] //[ Public static methods ] //[-------------------------------------------------------] uint32_t ShaderLanguageMonolithic::loadShader(uint32_t shaderType, const char *sourceCode) { // Create the shader object const GLuint openGLShader = glCreateShaderObjectARB(shaderType); // Load the shader source glShaderSourceARB(openGLShader, 1, &sourceCode, nullptr); // Compile the shader glCompileShaderARB(openGLShader); // Check the compile status GLint compiled = GL_FALSE; glGetObjectParameterivARB(openGLShader, GL_OBJECT_COMPILE_STATUS_ARB, &compiled); if (GL_TRUE == compiled) { // All went fine, return the shader return openGLShader; } else { // Error, failed to compile the shader! #ifdef RENDERER_OUTPUT_DEBUG // Get the length of the information GLint informationLength = 0; glGetObjectParameterivARB(openGLShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &informationLength); if (informationLength > 1) { // Allocate memory for the information GLchar *informationLog = new GLchar[static_cast<uint32_t>(informationLength)]; // Get the information glGetInfoLogARB(openGLShader, informationLength, nullptr, informationLog); // Output the debug string RENDERER_OUTPUT_DEBUG_STRING(informationLog) // Cleanup information memory delete [] informationLog; } #endif // Destroy the shader // -> A value of 0 for shader will be silently ignored glDeleteObjectARB(openGLShader); // Error! return 0; } }
//[-------------------------------------------------------] //[ Public static methods ] //[-------------------------------------------------------] uint32_t ShaderLanguageSeparate::loadShader(uint32_t shaderType, const char *sourceCode) { // Create the shader program const GLuint openGLProgram = glCreateShaderProgramv(shaderType, 1, &sourceCode); // Check the link status GLint linked = GL_FALSE; glGetObjectParameterivARB(openGLProgram, GL_LINK_STATUS, &linked); if (GL_TRUE == linked) { // All went fine, return the program return openGLProgram; } else { // Error, failed to compile the shader! #ifdef RENDERER_OUTPUT_DEBUG { // Get the length of the information GLint informationLength = 0; glGetObjectParameterivARB(openGLProgram, GL_OBJECT_INFO_LOG_LENGTH_ARB, &informationLength); if (informationLength > 1) { // Allocate memory for the information GLchar *informationLog = new GLchar[static_cast<uint32_t>(informationLength)]; // Get the information glGetInfoLogARB(openGLProgram, informationLength, nullptr, informationLog); // Output the debug string RENDERER_OUTPUT_DEBUG_STRING(informationLog) // Cleanup information memory delete [] informationLog; } } #endif // Destroy the program // -> A value of 0 for shader will be silently ignored glDeleteProgram(openGLProgram); // Error! return 0; } }
//[-------------------------------------------------------] //[ Private methods ] //[-------------------------------------------------------] bool OpenGLRuntimeLinking::loadSharedLibraries() { // Load the shared library #ifdef WIN32 mOpenGLSharedLibrary = ::LoadLibraryExA("opengl32.dll", nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); if (nullptr == mOpenGLSharedLibrary) { RENDERER_OUTPUT_DEBUG_STRING("OpenGL error: Failed to load in the shared library \"opengl32.dll\"\n") } #elif defined LINUX mOpenGLSharedLibrary = ::dlopen("libGL.so", RTLD_NOW); if (nullptr == mOpenGLSharedLibrary) { std::cout << "OpenGL error: Failed to load in the shared library \"libGL.so\"\n"; // TODO(co) Use "RENDERER_OUTPUT_DEBUG_PRINTF" instead } #else #error "Unsupported platform" #endif // Done return (nullptr != mOpenGLSharedLibrary); }