Mercurial > hg > orthanc-stone
changeset 578:21fd70df3fc9
starting work on OpenGL
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Apr 2019 15:57:46 +0200 |
parents | b098a3aaf694 |
children | fadacfbf5538 |
files | Framework/Fonts/FontRenderer.h Framework/OpenGL/IOpenGLContext.h Framework/OpenGL/OpenGLShader.cpp Framework/OpenGL/OpenGLShader.h Resources/CMake/OrthancStoneConfiguration.cmake Resources/CMake/OrthancStoneParameters.cmake |
diffstat | 6 files changed, 260 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Fonts/FontRenderer.h Fri Apr 19 15:42:57 2019 +0200 +++ b/Framework/Fonts/FontRenderer.h Fri Apr 19 15:57:46 2019 +0200 @@ -24,6 +24,8 @@ #include "Glyph.h" #include <EmbeddedResources.h> + +#include <stdint.h> #include <boost/shared_ptr.hpp>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/OpenGL/IOpenGLContext.h Fri Apr 19 15:57:46 2019 +0200 @@ -0,0 +1,57 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#if !defined(ORTHANC_ENABLE_OPENGL) +# error The macro ORTHANC_ENABLE_OPENGL must be defined +#endif + +#if ORTHANC_ENABLE_OPENGL != 1 +# error Support for OpenGL is disabled +#endif + + +#include <boost/noncopyable.hpp> + + +namespace OrthancStone +{ + namespace OpenGL + { + class IOpenGLContext : public boost::noncopyable + { + public: + virtual ~IOpenGLContext() + { + } + + virtual void MakeCurrent() = 0; + + virtual void SwapBuffer() = 0; + + virtual unsigned int GetCanvasWidth() = 0; + + virtual unsigned int GetCanvasHeight() = 0; + }; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/OpenGL/OpenGLShader.cpp Fri Apr 19 15:57:46 2019 +0200 @@ -0,0 +1,114 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "OpenGLShader.h" + +#include <Core/OrthancException.h> + +namespace OrthancStone +{ + namespace OpenGL + { + static GLuint CompileShader(GLenum type, + const std::string& source) + { + // Create shader object + const GLchar* sourceString[1]; + GLint sourceStringLengths[1]; + + sourceString[0] = source.c_str(); + sourceStringLengths[0] = source.length(); + GLuint shader = glCreateShader(type); + + if (shader == 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, + "Cannot create an OpenGL shader"); + } + else + { + // Assign and compile the source to the shader object + glShaderSource(shader, 1, sourceString, sourceStringLengths); + glCompileShader(shader); + + // Check if there were errors + int infoLen = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); + + if (infoLen > 1) + { + char infoLog[infoLen + 1]; + glGetShaderInfoLog(shader, infoLen, NULL, infoLog); + glDeleteShader(shader); + + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, + "Error while creating an OpenGL shader: " + std::string(infoLog)); + } + else + { + return shader; + } + } + } + + + OpenGLShader::OpenGLShader(GLenum type, + const std::string& source) + { + shader_ = CompileShader(type, source); + isValid_ = true; + } + + + OpenGLShader::OpenGLShader(GLenum type, + Orthanc::EmbeddedResources::FileResourceId resource) + { + std::string content; + Orthanc::EmbeddedResources::GetFileResource(content, resource); + + shader_ = CompileShader(type, content); + isValid_ = true; + } + + + OpenGLShader::~OpenGLShader() + { + if (isValid_) + { + glDeleteShader(shader_); + } + } + + + GLuint OpenGLShader::Release() + { + if (isValid_) + { + isValid_ = false; + return shader_; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/OpenGL/OpenGLShader.h Fri Apr 19 15:57:46 2019 +0200 @@ -0,0 +1,65 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + + +#if !defined(ORTHANC_ENABLE_OPENGL) +# error The macro ORTHANC_ENABLE_OPENGL must be defined +#endif + +#if ORTHANC_ENABLE_OPENGL != 1 +# error Support for OpenGL is disabled +#endif + +#include <EmbeddedResources.h> + +#include <GL/gl.h> +#include <boost/noncopyable.hpp> + +namespace OrthancStone +{ + namespace OpenGL + { + class OpenGLShader : public boost::noncopyable + { + private: + bool isValid_; + GLuint shader_; + + public: + OpenGLShader(GLenum type, + const std::string& source); + + OpenGLShader(GLenum type, + Orthanc::EmbeddedResources::FileResourceId resource); + + ~OpenGLShader(); + + bool IsValid() const + { + return isValid_; + } + + GLuint Release(); + }; + } +}
--- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 19 15:42:57 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 19 15:57:46 2019 +0200 @@ -106,6 +106,16 @@ endif() +if (ENABLE_OPENGL) + add_definitions( + -DGL_GLEXT_PROTOTYPES=1 + -DORTHANC_ENABLE_OPENGL=1 + ) +else() + add_definitions(-DORTHANC_ENABLE_OPENGL=0) +endif() + + ##################################################################### ## Configuration of the C/C++ macros @@ -125,6 +135,8 @@ add_definitions(-DCHECK_OBSERVERS_MESSAGES) endif() + + ##################################################################### ## Embed the colormaps into the binaries ##################################################################### @@ -249,7 +261,6 @@ ${ORTHANC_STONE_ROOT}/Framework/Fonts/GlyphAlphabet.cpp ${ORTHANC_STONE_ROOT}/Framework/Fonts/GlyphBitmapAlphabet.cpp ${ORTHANC_STONE_ROOT}/Framework/Fonts/GlyphTextureAlphabet.cpp - ${ORTHANC_STONE_ROOT}/Framework/Fonts/OpenGLTextCoordinates.cpp ${ORTHANC_STONE_ROOT}/Framework/Fonts/TextBoundingBox.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/CircleMeasureTracker.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/ColorFrameRenderer.cpp @@ -362,6 +373,15 @@ ${BOOST_EXTENDED_SOURCES} ) + +if (ENABLE_OPENGL) + list(APPEND ORTHANC_STONE_SOURCES + ${ORTHANC_STONE_ROOT}/Framework/Fonts/OpenGLTextCoordinates.cpp + ${ORTHANC_STONE_ROOT}/Framework/OpenGL/OpenGLShader.cpp + ) +endif() + + include_directories(${ORTHANC_STONE_ROOT})
--- a/Resources/CMake/OrthancStoneParameters.cmake Fri Apr 19 15:42:57 2019 +0200 +++ b/Resources/CMake/OrthancStoneParameters.cmake Fri Apr 19 15:57:46 2019 +0200 @@ -51,3 +51,4 @@ ## the Stone of Orthanc ##################################################################### +set(ENABLE_OPENGL ON CACHE INTERNAL "Enable support of OpenGL")