Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/OpenGL/OpenGLTexture.cpp @ 2037:d81a7157a846 deep-learning
added OpenGLTexture::ConvertToOpenGLFormats()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 28 Jan 2023 12:55:34 +0100 |
parents | 444527d34647 |
children | e0906b7c67b9 |
comparison
equal
deleted
inserted
replaced
2036:444527d34647 | 2037:d81a7157a846 |
---|---|
100 // Bind it | 100 // Bind it |
101 glActiveTexture(GL_TEXTURE0); | 101 glActiveTexture(GL_TEXTURE0); |
102 glBindTexture(GL_TEXTURE_2D, texture_); | 102 glBindTexture(GL_TEXTURE_2D, texture_); |
103 | 103 |
104 GLenum sourceFormat, internalFormat, pixelType; | 104 GLenum sourceFormat, internalFormat, pixelType; |
105 | 105 ConvertToOpenGLFormats(sourceFormat, internalFormat, pixelType, format); |
106 switch (format) | |
107 { | |
108 case Orthanc::PixelFormat_Grayscale8: | |
109 sourceFormat = GL_RED; | |
110 internalFormat = GL_RED; | |
111 pixelType = GL_UNSIGNED_BYTE; | |
112 break; | |
113 | |
114 case Orthanc::PixelFormat_RGB24: | |
115 sourceFormat = GL_RGB; | |
116 internalFormat = GL_RGB; | |
117 pixelType = GL_UNSIGNED_BYTE; | |
118 break; | |
119 | |
120 case Orthanc::PixelFormat_RGBA32: | |
121 sourceFormat = GL_RGBA; | |
122 internalFormat = GL_RGBA; | |
123 pixelType = GL_UNSIGNED_BYTE; | |
124 break; | |
125 | |
126 case Orthanc::PixelFormat_Float32: | |
127 sourceFormat = GL_RED; | |
128 internalFormat = GL_R32F; // Don't use "GL_RED" here, as it clamps to [0,1] | |
129 pixelType = GL_FLOAT; | |
130 break; | |
131 | |
132 default: | |
133 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, | |
134 "No support for this format in OpenGL textures: " + | |
135 std::string(EnumerationToString(format))); | |
136 } | |
137 | 106 |
138 width_ = width; | 107 width_ = width; |
139 height_ = height; | 108 height_ = height; |
140 | 109 |
141 GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST); | 110 GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST); |
233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | 202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); |
234 | 203 |
235 GLfloat colorfv[4] = { 0, 0, 0, 0 }; | 204 GLfloat colorfv[4] = { 0, 0, 0, 0 }; |
236 glTextureParameterfv(texture_, GL_TEXTURE_BORDER_COLOR, colorfv); | 205 glTextureParameterfv(texture_, GL_TEXTURE_BORDER_COLOR, colorfv); |
237 } | 206 } |
207 | |
208 | |
209 void OpenGLTexture::ConvertToOpenGLFormats(GLenum& sourceFormat, | |
210 GLenum& internalFormat, | |
211 GLenum& pixelType, | |
212 Orthanc::PixelFormat format) | |
213 { | |
214 switch (format) | |
215 { | |
216 case Orthanc::PixelFormat_Grayscale8: | |
217 sourceFormat = GL_RED; | |
218 internalFormat = GL_RED; | |
219 pixelType = GL_UNSIGNED_BYTE; | |
220 break; | |
221 | |
222 case Orthanc::PixelFormat_RGB24: | |
223 sourceFormat = GL_RGB; | |
224 internalFormat = GL_RGB; | |
225 pixelType = GL_UNSIGNED_BYTE; | |
226 break; | |
227 | |
228 case Orthanc::PixelFormat_RGBA32: | |
229 sourceFormat = GL_RGBA; | |
230 internalFormat = GL_RGBA; | |
231 pixelType = GL_UNSIGNED_BYTE; | |
232 break; | |
233 | |
234 case Orthanc::PixelFormat_Float32: | |
235 sourceFormat = GL_RED; | |
236 internalFormat = GL_R32F; // Don't use "GL_RED" here, as it clamps to [0,1] | |
237 pixelType = GL_FLOAT; | |
238 break; | |
239 | |
240 default: | |
241 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, | |
242 "No support for this format in OpenGL textures: " + | |
243 std::string(EnumerationToString(format))); | |
244 } | |
245 } | |
238 } | 246 } |
239 } | 247 } |