comparison OrthancStone/Sources/OpenGL/OpenGLTexture.cpp @ 2033:23b0a42eea85 deep-learning

added support for floating-point images in OpenGLTexture
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 22 Jan 2023 10:48:22 +0100
parents d10bab7cc396
children 4b24b7533346
comparison
equal deleted inserted replaced
2032:d10bab7cc396 2033:23b0a42eea85
90 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Disable byte-alignment restriction 90 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Disable byte-alignment restriction
91 91
92 if (image.GetPitch() != image.GetBytesPerPixel() * image.GetWidth()) 92 if (image.GetPitch() != image.GetBytesPerPixel() * image.GetWidth())
93 { 93 {
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, 94 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
95 "Unsupported non-zero padding"); 95 "Pitch is not the same as the row size");
96 } 96 }
97 97
98 // Bind it 98 // Bind it
99 glActiveTexture(GL_TEXTURE0); 99 glActiveTexture(GL_TEXTURE0);
100 glBindTexture(GL_TEXTURE_2D, texture_); 100 glBindTexture(GL_TEXTURE_2D, texture_);
117 117
118 case Orthanc::PixelFormat_RGBA32: 118 case Orthanc::PixelFormat_RGBA32:
119 sourceFormat = GL_RGBA; 119 sourceFormat = GL_RGBA;
120 internalFormat = GL_RGBA; 120 internalFormat = GL_RGBA;
121 pixelType = GL_UNSIGNED_BYTE; 121 pixelType = GL_UNSIGNED_BYTE;
122 break;
123
124 case Orthanc::PixelFormat_Float32:
125 sourceFormat = GL_RED;
126 internalFormat = GL_R32F; // Don't use "GL_RED" here, as it clamps to [0,1]
127 pixelType = GL_FLOAT;
122 break; 128 break;
123 129
124 default: 130 default:
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, 131 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
126 "No support for this format in OpenGL textures: " + 132 "No support for this format in OpenGL textures: " +
158 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, 164 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
159 "OpenGL context is lost"); 165 "OpenGL context is lost");
160 } 166 }
161 167
162 std::unique_ptr<Orthanc::ImageAccessor> target(new Orthanc::Image(format, width_, height_, true)); 168 std::unique_ptr<Orthanc::ImageAccessor> target(new Orthanc::Image(format, width_, height_, true));
169 assert(target->GetPitch() == width_ * Orthanc::GetBytesPerPixel(format));
163 170
164 glBindTexture(GL_TEXTURE_2D, texture_); 171 glBindTexture(GL_TEXTURE_2D, texture_);
165 172
166 switch (format) 173 switch (format)
167 { 174 {
175 182
176 case Orthanc::PixelFormat_RGBA32: 183 case Orthanc::PixelFormat_RGBA32:
177 glGetTexImage(GL_TEXTURE_2D, 0 /* base level */, GL_RGBA, GL_UNSIGNED_BYTE, target->GetBuffer()); 184 glGetTexImage(GL_TEXTURE_2D, 0 /* base level */, GL_RGBA, GL_UNSIGNED_BYTE, target->GetBuffer());
178 break; 185 break;
179 186
187 case Orthanc::PixelFormat_Float32:
188 glGetTexImage(GL_TEXTURE_2D, 0 /* base level */, GL_RED, GL_FLOAT, target->GetBuffer());
189 break;
190
180 default: 191 default:
181 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 192 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
182 } 193 }
183 194
184 return target.release(); 195 return target.release();