comparison Framework/OpenGL/OpenGLShader.cpp @ 947:1091b2adeb5a toa2019081001

Fixed animation frame stopping when returning false + big work on the OpenGL objects to make them lost context-safe + debug code to forcefully tag a context as lost + debug macros
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 10 Aug 2019 13:07:31 +0200
parents 58e1faeafb1b
children a7351ad54960
comparison
equal deleted inserted replaced
946:dbe3e1e47019 947:1091b2adeb5a
35 GLint sourceStringLengths[1]; 35 GLint sourceStringLengths[1];
36 36
37 sourceString[0] = source.c_str(); 37 sourceString[0] = source.c_str();
38 sourceStringLengths[0] = static_cast<GLint>(source.length()); 38 sourceStringLengths[0] = static_cast<GLint>(source.length());
39 GLuint shader = glCreateShader(type); 39 GLuint shader = glCreateShader(type);
40 ORTHANC_OPENGL_CHECK("glCreateShader");
40 41
41 if (shader == 0) 42 if (shader == 0)
42 { 43 {
43 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, 44 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
44 "Cannot create an OpenGL shader"); 45 "Cannot create an OpenGL shader");
45 } 46 }
46 else 47 else
47 { 48 {
48 // Assign and compile the source to the shader object 49 // Assign and compile the source to the shader object
49 glShaderSource(shader, 1, sourceString, sourceStringLengths); 50 glShaderSource(shader, 1, sourceString, sourceStringLengths);
51 ORTHANC_OPENGL_CHECK("glShaderSource");
50 glCompileShader(shader); 52 glCompileShader(shader);
53 ORTHANC_OPENGL_CHECK("glCompileShader");
51 54
52 // Check if there were errors 55 // Check if there were errors
53 int infoLen = 0; 56 int infoLen = 0;
54 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); 57 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
58 ORTHANC_OPENGL_CHECK("glGetShaderiv");
55 59
56 if (infoLen > 1) // Might be equal to 1, which amounts to no error 60 if (infoLen > 1) // Might be equal to 1, which amounts to no error
57 { 61 {
58 std::string infoLog; 62 std::string infoLog;
59 infoLog.resize(infoLen + 1); 63 infoLog.resize(infoLen + 1);
60 glGetShaderInfoLog(shader, infoLen, NULL, &infoLog[0]); 64 glGetShaderInfoLog(shader, infoLen, NULL, &infoLog[0]);
65 ORTHANC_OPENGL_CHECK("glGetShaderInfoLog");
66 ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT("About to call glDeleteShader");
61 glDeleteShader(shader); 67 glDeleteShader(shader);
68 ORTHANC_OPENGL_CHECK("glDeleteShader");
62 69
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, 70 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
64 "Error while creating an OpenGL shader: " + infoLog); 71 "Error while creating an OpenGL shader: " + infoLog);
65 } 72 }
66 else 73 else
79 } 86 }
80 87
81 88
82 OpenGLShader::~OpenGLShader() 89 OpenGLShader::~OpenGLShader()
83 { 90 {
84 if (isValid_) 91 try
85 { 92 {
86 glDeleteShader(shader_); 93 if (isValid_)
94 {
95 ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT("About to call glDeleteShader");
96 glDeleteShader(shader_);
97 ORTHANC_OPENGL_CHECK("glDeleteShader");
98 }
99 }
100 catch (const Orthanc::OrthancException& e)
101 {
102 if (e.HasDetails())
103 {
104 LOG(ERROR) << "OrthancException in ~OpenGLShader: " << e.What() << " Details: " << e.GetDetails();
105 }
106 else
107 {
108 LOG(ERROR) << "OrthancException in ~OpenGLShader: " << e.What();
109 }
110 }
111 catch (const std::exception& e)
112 {
113 LOG(ERROR) << "std::exception in ~OpenGLShader: " << e.what();
114 }
115 catch (...)
116 {
117 LOG(ERROR) << "Unknown exception in ~OpenGLShader";
87 } 118 }
88 } 119 }
89
90 120
91 GLuint OpenGLShader::Release() 121 GLuint OpenGLShader::Release()
92 { 122 {
93 if (isValid_) 123 if (isValid_)
94 { 124 {