# HG changeset patch # User Sebastien Jodogne # Date 1674830604 -3600 # Node ID 4b24b7533346f75b12dd1cdb550faa6978f2b5f3 # Parent 23b0a42eea8577846b917b89d34ae815408f09ba cont diff -r 23b0a42eea85 -r 4b24b7533346 OrthancStone/Sources/OpenGL/OpenGLTexture.cpp --- a/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp Sun Jan 22 10:48:22 2023 +0100 +++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp Fri Jan 27 15:43:24 2023 +0100 @@ -82,26 +82,28 @@ } } - void OpenGLTexture::Load(const Orthanc::ImageAccessor& image, - bool isLinearInterpolation) + void OpenGLTexture::Setup(Orthanc::PixelFormat format, + unsigned int width, + unsigned int height, + bool isLinearInterpolation, + const void* data) { - if (!context_.IsContextLost()) + if (context_.IsContextLost()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, + "OpenGL context has been lost"); + } + else { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Disable byte-alignment restriction - if (image.GetPitch() != image.GetBytesPerPixel() * image.GetWidth()) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, - "Pitch is not the same as the row size"); - } - // Bind it glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture_); GLenum sourceFormat, internalFormat, pixelType; - switch (image.GetFormat()) + switch (format) { case Orthanc::PixelFormat_Grayscale8: sourceFormat = GL_RED; @@ -130,17 +132,17 @@ default: throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, "No support for this format in OpenGL textures: " + - std::string(EnumerationToString(image.GetFormat()))); + std::string(EnumerationToString(format))); } - width_ = image.GetWidth(); - height_ = image.GetHeight(); + width_ = width; + height_ = height; GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST); // Load the texture from the image buffer - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, image.GetWidth(), image.GetHeight(), - 0, sourceFormat, pixelType, image.GetConstBuffer()); + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, + 0, sourceFormat, pixelType, data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, interpolation); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, interpolation); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -148,6 +150,21 @@ } } + void OpenGLTexture::Load(const Orthanc::ImageAccessor& image, + bool isLinearInterpolation) + { + if (image.GetPitch() != image.GetBytesPerPixel() * image.GetWidth()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, + "Pitch is not the same as the row size"); + } + else + { + Setup(image.GetFormat(), image.GetWidth(), image.GetHeight(), + isLinearInterpolation, image.GetConstBuffer()); + } + } + void OpenGLTexture::Bind(GLint location) { diff -r 23b0a42eea85 -r 4b24b7533346 OrthancStone/Sources/OpenGL/OpenGLTexture.h --- a/OrthancStone/Sources/OpenGL/OpenGLTexture.h Sun Jan 22 10:48:22 2023 +0100 +++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.h Fri Jan 27 15:43:24 2023 +0100 @@ -43,11 +43,22 @@ unsigned int height_; OpenGL::IOpenGLContext& context_; + void Setup(Orthanc::PixelFormat format, + unsigned int width, + unsigned int height, + bool isLinearInterpolation, + const void* data); + public: explicit OpenGLTexture(OpenGL::IOpenGLContext& context); ~OpenGLTexture(); + GLuint GetId() const + { + return texture_; + } + unsigned int GetWidth() const { return width_; @@ -58,6 +69,14 @@ return height_; } + void Setup(Orthanc::PixelFormat format, + unsigned int width, + unsigned int height, + bool isLinearInterpolation) + { + Setup(format, width, height, isLinearInterpolation, NULL); + } + void Load(const Orthanc::ImageAccessor& image, bool isLinearInterpolation);