# HG changeset patch # User Sebastien Jodogne # Date 1555682266 -7200 # Node ID 21fd70df3fc9558813bba550db6747459aa3d734 # Parent b098a3aaf6943baf2bf418b85f4ed19d68b77820 starting work on OpenGL diff -r b098a3aaf694 -r 21fd70df3fc9 Framework/Fonts/FontRenderer.h --- 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 + +#include #include diff -r b098a3aaf694 -r 21fd70df3fc9 Framework/OpenGL/IOpenGLContext.h --- /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 . + **/ + + +#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 + + +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; + }; + } +} + diff -r b098a3aaf694 -r 21fd70df3fc9 Framework/OpenGL/OpenGLShader.cpp --- /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 . + **/ + + +#include "OpenGLShader.h" + +#include + +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); + } + } + } +} diff -r b098a3aaf694 -r 21fd70df3fc9 Framework/OpenGL/OpenGLShader.h --- /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 . + **/ + + +#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 + +#include +#include + +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(); + }; + } +} diff -r b098a3aaf694 -r 21fd70df3fc9 Resources/CMake/OrthancStoneConfiguration.cmake --- 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}) diff -r b098a3aaf694 -r 21fd70df3fc9 Resources/CMake/OrthancStoneParameters.cmake --- 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")