Mercurial > hg > orthanc-stone
changeset 594:9807ed3d3e03
OpenGLCompositor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2019 14:45:47 +0200 |
parents | 6bf8f881fcb5 |
children | 6e471e6cf09b |
files | Framework/Scene2D/Internals/OpenGLAdvancedPolylineRenderer.cpp Framework/Scene2D/Internals/OpenGLAdvancedPolylineRenderer.h Framework/Scene2D/Internals/OpenGLColorTextureRenderer.cpp Framework/Scene2D/Internals/OpenGLColorTextureRenderer.h Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.cpp Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.h Framework/Scene2D/Internals/OpenGLInfoPanelRenderer.cpp Framework/Scene2D/Internals/OpenGLInfoPanelRenderer.h Framework/Scene2D/Internals/OpenGLTextRenderer.cpp Framework/Scene2D/Internals/OpenGLTextRenderer.h Framework/Scene2D/OpenGLCompositor.cpp Framework/Scene2D/OpenGLCompositor.h Resources/CMake/OrthancStoneConfiguration.cmake |
diffstat | 13 files changed, 862 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLAdvancedPolylineRenderer.cpp Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,51 @@ +/** + * 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 "OpenGLAdvancedPolylineRenderer.h" + +#include <Core/OrthancException.h> + + +namespace OrthancStone +{ + namespace Internals + { + void OpenGLAdvancedPolylineRenderer::LoadLayer(const PolylineSceneLayer& layer) + { + data_.reset(new OpenGLLinesProgram::Data(context_, layer)); + + if (data_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + } + + + OpenGLAdvancedPolylineRenderer::OpenGLAdvancedPolylineRenderer(OpenGL::IOpenGLContext& context, + OpenGLLinesProgram& program, + const PolylineSceneLayer& layer) : + context_(context), + program_(program) + { + LoadLayer(layer); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLAdvancedPolylineRenderer.h Fri Apr 26 14:45:47 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 + +#include "CompositorHelper.h" +#include "OpenGLLinesProgram.h" + + +namespace OrthancStone +{ + namespace Internals + { + class OpenGLAdvancedPolylineRenderer : public CompositorHelper::ILayerRenderer + { + private: + OpenGL::IOpenGLContext& context_; + OpenGLLinesProgram& program_; + std::auto_ptr<OpenGLLinesProgram::Data> data_; + + void LoadLayer(const PolylineSceneLayer& layer); + + public: + OpenGLAdvancedPolylineRenderer(OpenGL::IOpenGLContext& context, + OpenGLLinesProgram& program, + const PolylineSceneLayer& layer); + + virtual void Render(const AffineTransform2D& transform) + { + program_.Apply(*data_, transform, true, true); + } + + virtual void Update(const ISceneLayer& layer) + { + LoadLayer(dynamic_cast<const PolylineSceneLayer&>(layer)); + } + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLColorTextureRenderer.cpp Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,62 @@ +/** + * 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 "OpenGLColorTextureRenderer.h" + +namespace OrthancStone +{ + namespace Internals + { + void OpenGLColorTextureRenderer::LoadTexture(const ColorTextureSceneLayer& layer) + { + context_.MakeCurrent(); + texture_.reset(new OpenGL::OpenGLTexture); + texture_->Load(layer.GetTexture(), layer.IsLinearInterpolation()); + layerTransform_ = layer.GetTransform(); + } + + + OpenGLColorTextureRenderer::OpenGLColorTextureRenderer(OpenGL::IOpenGLContext& context, + OpenGLColorTextureProgram& program, + const ColorTextureSceneLayer& layer) : + context_(context), + program_(program) + { + LoadTexture(layer); + } + + + void OpenGLColorTextureRenderer::Render(const AffineTransform2D& transform) + { + if (texture_.get() != NULL) + { + program_.Apply(*texture_, AffineTransform2D::Combine(transform, layerTransform_), true); + } + } + + + void OpenGLColorTextureRenderer::Update(const ISceneLayer& layer) + { + // Should never happen (no revisions in color textures) + LoadTexture(dynamic_cast<const ColorTextureSceneLayer&>(layer)); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLColorTextureRenderer.h Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,52 @@ +/** + * 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 + +#include "OpenGLColorTextureProgram.h" +#include "CompositorHelper.h" +#include "../ColorTextureSceneLayer.h" + +namespace OrthancStone +{ + namespace Internals + { + class OpenGLColorTextureRenderer : public CompositorHelper::ILayerRenderer + { + private: + OpenGL::IOpenGLContext& context_; + OpenGLColorTextureProgram& program_; + std::auto_ptr<OpenGL::OpenGLTexture> texture_; + AffineTransform2D layerTransform_; + + void LoadTexture(const ColorTextureSceneLayer& layer); + + public: + OpenGLColorTextureRenderer(OpenGL::IOpenGLContext& context, + OpenGLColorTextureProgram& program, + const ColorTextureSceneLayer& layer); + + virtual void Render(const AffineTransform2D& transform); + + virtual void Update(const ISceneLayer& layer); + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.cpp Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,67 @@ +/** + * 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 "OpenGLFloatTextureRenderer.h" + +namespace OrthancStone +{ + namespace Internals + { + void OpenGLFloatTextureRenderer::UpdateInternal(const FloatTextureSceneLayer& layer, + bool loadTexture) + { + if (loadTexture) + { + context_.MakeCurrent(); + texture_.reset(new OpenGLFloatTextureProgram::Data(layer.GetTexture(), layer.IsLinearInterpolation())); + } + + layerTransform_ = layer.GetTransform(); + layer.GetWindowing(windowCenter_, windowWidth_); + } + + + OpenGLFloatTextureRenderer::OpenGLFloatTextureRenderer(OpenGL::IOpenGLContext& context, + OpenGLFloatTextureProgram& program, + const FloatTextureSceneLayer& layer) : + context_(context), + program_(program) + { + UpdateInternal(layer, true); + } + + + void OpenGLFloatTextureRenderer::Render(const AffineTransform2D& transform) + { + if (texture_.get() != NULL) + { + program_.Apply(*texture_, AffineTransform2D::Combine(transform, layerTransform_), + windowCenter_, windowWidth_); + } + } + + + void OpenGLFloatTextureRenderer::Update(const ISceneLayer& layer) + { + UpdateInternal(dynamic_cast<const FloatTextureSceneLayer&>(layer), false); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.h Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,55 @@ +/** + * 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 + +#include "CompositorHelper.h" +#include "OpenGLFloatTextureProgram.h" +#include "../FloatTextureSceneLayer.h" + +namespace OrthancStone +{ + namespace Internals + { + class OpenGLFloatTextureRenderer : public CompositorHelper::ILayerRenderer + { + private: + OpenGL::IOpenGLContext& context_; + OpenGLFloatTextureProgram& program_; + std::auto_ptr<OpenGLFloatTextureProgram::Data> texture_; + AffineTransform2D layerTransform_; + float windowCenter_; + float windowWidth_; + + void UpdateInternal(const FloatTextureSceneLayer& layer, + bool loadTexture); + + public: + OpenGLFloatTextureRenderer(OpenGL::IOpenGLContext& context, + OpenGLFloatTextureProgram& program, + const FloatTextureSceneLayer& layer); + + virtual void Render(const AffineTransform2D& transform); + + virtual void Update(const ISceneLayer& layer); + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLInfoPanelRenderer.cpp Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,62 @@ +/** + * 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 "OpenGLInfoPanelRenderer.h" + +namespace OrthancStone +{ + namespace Internals + { + void OpenGLInfoPanelRenderer::LoadTexture(const InfoPanelSceneLayer& layer) + { + context_.MakeCurrent(); + texture_.reset(new OpenGL::OpenGLTexture); + texture_->Load(layer.GetTexture(), layer.IsLinearInterpolation()); + anchor_ = layer.GetAnchor(); + } + + + OpenGLInfoPanelRenderer::OpenGLInfoPanelRenderer(OpenGL::IOpenGLContext& context, + OpenGLColorTextureProgram& program, + const InfoPanelSceneLayer& layer) : + context_(context), + program_(program) + { + LoadTexture(layer); + } + + + void OpenGLInfoPanelRenderer::Render(const AffineTransform2D& transform) + { + if (texture_.get() != NULL) + { + int dx, dy; + InfoPanelSceneLayer::ComputeAnchorLocation( + dx, dy, anchor_, texture_->GetWidth(), texture_->GetHeight(), + context_.GetCanvasWidth(), context_.GetCanvasHeight()); + + // The position of this type of layer is layer: Ignore the + // "transform" coming from the scene + program_.Apply(*texture_, AffineTransform2D::CreateOffset(dx, dy), true); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLInfoPanelRenderer.h Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,55 @@ +/** + * 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 + +#include "CompositorHelper.h" +#include "OpenGLColorTextureProgram.h" +#include "../InfoPanelSceneLayer.h" + +namespace OrthancStone +{ + namespace Internals + { + class OpenGLInfoPanelRenderer : public CompositorHelper::ILayerRenderer + { + private: + OpenGL::IOpenGLContext& context_; + OpenGLColorTextureProgram& program_; + std::auto_ptr<OpenGL::OpenGLTexture> texture_; + BitmapAnchor anchor_; + + void LoadTexture(const InfoPanelSceneLayer& layer); + + public: + OpenGLInfoPanelRenderer(OpenGL::IOpenGLContext& context, + OpenGLColorTextureProgram& program, + const InfoPanelSceneLayer& layer); + + virtual void Render(const AffineTransform2D& transform); + + virtual void Update(const ISceneLayer& layer) + { + LoadTexture(dynamic_cast<const InfoPanelSceneLayer&>(layer)); + } + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLTextRenderer.cpp Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,62 @@ +/** + * 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 "OpenGLTextRenderer.h" + +namespace OrthancStone +{ + namespace Internals + { + void OpenGLTextRenderer::LoadLayer(const TextSceneLayer& layer) + { + data_.reset(new OpenGLTextProgram::Data(context_, alphabet_, layer)); + } + + + OpenGLTextRenderer::OpenGLTextRenderer(OpenGL::IOpenGLContext& context, + OpenGLTextProgram& program, + const GlyphTextureAlphabet& alphabet, + OpenGL::OpenGLTexture& texture, + const TextSceneLayer& layer) : + context_(context), + program_(program), + alphabet_(alphabet), + texture_(texture) + { + LoadLayer(layer); + } + + + void OpenGLTextRenderer::Render(const AffineTransform2D& transform) + { + if (data_.get() != NULL) + { + program_.Apply(texture_, *data_, transform); + } + } + + + void OpenGLTextRenderer::Update(const ISceneLayer& layer) + { + LoadLayer(dynamic_cast<const TextSceneLayer&>(layer)); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLTextRenderer.h Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,54 @@ +/** + * 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 + +#include "CompositorHelper.h" +#include "OpenGLTextProgram.h" + +namespace OrthancStone +{ + namespace Internals + { + class OpenGLTextRenderer : public CompositorHelper::ILayerRenderer + { + private: + OpenGL::IOpenGLContext& context_; + OpenGLTextProgram& program_; + const GlyphTextureAlphabet& alphabet_; + OpenGL::OpenGLTexture& texture_; + std::auto_ptr<OpenGLTextProgram::Data> data_; + + void LoadLayer(const TextSceneLayer& layer); + + public: + OpenGLTextRenderer(OpenGL::IOpenGLContext& context, + OpenGLTextProgram& program, + const GlyphTextureAlphabet& alphabet, + OpenGL::OpenGLTexture& texture, + const TextSceneLayer& layer); + + virtual void Render(const AffineTransform2D& transform); + + virtual void Update(const ISceneLayer& layer); + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/OpenGLCompositor.cpp Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,205 @@ +/** + * 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 "OpenGLCompositor.h" + +#include "Internals/OpenGLAdvancedPolylineRenderer.h" +#include "Internals/OpenGLBasicPolylineRenderer.h" +#include "Internals/OpenGLColorTextureRenderer.h" +#include "Internals/OpenGLFloatTextureRenderer.h" +#include "Internals/OpenGLInfoPanelRenderer.h" +#include "Internals/OpenGLTextRenderer.h" + +namespace OrthancStone +{ + class OpenGLCompositor::Font : public boost::noncopyable + { + private: + std::auto_ptr<GlyphTextureAlphabet> alphabet_; + std::auto_ptr<OpenGL::OpenGLTexture> texture_; + + public: + Font(const GlyphBitmapAlphabet& dict) + { + alphabet_.reset(new GlyphTextureAlphabet(dict)); + texture_.reset(new OpenGL::OpenGLTexture); + + std::auto_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture()); + texture_->Load(*bitmap, true /* enable linear interpolation */); + } + + OpenGL::OpenGLTexture& GetTexture() const + { + assert(texture_.get() != NULL); + return *texture_; + } + + const GlyphTextureAlphabet& GetAlphabet() const + { + assert(alphabet_.get() != NULL); + return *alphabet_; + } + }; + + + const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const + { + Fonts::const_iterator found = fonts_.find(fontIndex); + + if (found == fonts_.end()) + { + return NULL; // Unknown font, nothing should be drawn + } + else + { + assert(found->second != NULL); + return found->second; + } + } + + + Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer) + { + switch (layer.GetType()) + { + case ISceneLayer::Type_InfoPanel: + return new Internals::OpenGLInfoPanelRenderer + (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer)); + + case ISceneLayer::Type_ColorTexture: + return new Internals::OpenGLColorTextureRenderer + (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer)); + + case ISceneLayer::Type_FloatTexture: + return new Internals::OpenGLFloatTextureRenderer + (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer)); + + case ISceneLayer::Type_Polyline: + return new Internals::OpenGLAdvancedPolylineRenderer + (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer)); + //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer)); + + case ISceneLayer::Type_Text: + { + const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer); + const Font* font = GetFont(l.GetFontIndex()); + if (font == NULL) + { + return NULL; + } + else + { + return new Internals::OpenGLTextRenderer + (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l); + } + } + + default: + return NULL; + } + } + + + OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context, + Scene2D& scene) : + context_(context), + helper_(scene, *this), + colorTextureProgram_(context), + floatTextureProgram_(context), + linesProgram_(context), + textProgram_(context), + canvasWidth_(0), + canvasHeight_(0) + { + UpdateSize(); + } + + + OpenGLCompositor::~OpenGLCompositor() + { + for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it) + { + assert(it->second != NULL); + delete it->second; + } + } + + + void OpenGLCompositor::UpdateSize() + { + canvasWidth_ = context_.GetCanvasWidth(); + canvasHeight_ = context_.GetCanvasHeight(); + + context_.MakeCurrent(); + glViewport(0, 0, canvasWidth_, canvasHeight_); + } + + + void OpenGLCompositor::Refresh() + { + context_.MakeCurrent(); + + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + + helper_.Refresh(canvasWidth_, canvasHeight_); + + context_.SwapBuffer(); + } + + + void OpenGLCompositor::SetFont(size_t index, + const GlyphBitmapAlphabet& dict) + { + std::auto_ptr<Font> font(new Font(dict)); + + Fonts::iterator found = fonts_.find(index); + + if (found == fonts_.end()) + { + fonts_[index] = font.release(); + } + else + { + assert(found->second != NULL); + delete found->second; + + found->second = font.release(); + } + } + + +#if ORTHANC_ENABLE_LOCALE == 1 + void OpenGLCompositor::SetFont(size_t index, + Orthanc::EmbeddedResources::FileResourceId resource, + unsigned int fontSize, + Orthanc::Encoding codepage) + { + FontRenderer renderer; + renderer.LoadFont(font, fontSize); + + GlyphBitmapAlphabet dict; + dict.LoadCodepage(renderer, codepage); + + SetFont(index, dict); + } +#endif +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/OpenGLCompositor.h Fri Apr 26 14:45:47 2019 +0200 @@ -0,0 +1,74 @@ +/** + * 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 + +#include "Internals/CompositorHelper.h" +#include "Internals/OpenGLColorTextureProgram.h" +#include "Internals/OpenGLFloatTextureProgram.h" +#include "Internals/OpenGLLinesProgram.h" +#include "Internals/OpenGLTextProgram.h" + +namespace OrthancStone +{ + class OpenGLCompositor : protected Internals::CompositorHelper::IRendererFactory + { + private: + class Font; + + typedef std::map<size_t, Font*> Fonts; + + OpenGL::IOpenGLContext& context_; + Fonts fonts_; + Internals::CompositorHelper helper_; + Internals::OpenGLColorTextureProgram colorTextureProgram_; + Internals::OpenGLFloatTextureProgram floatTextureProgram_; + Internals::OpenGLLinesProgram linesProgram_; + Internals::OpenGLTextProgram textProgram_; + unsigned int canvasWidth_; + unsigned int canvasHeight_; + + const Font* GetFont(size_t fontIndex) const; + + protected: + virtual Internals::CompositorHelper::ILayerRenderer* Create(const ISceneLayer& layer); + + public: + OpenGLCompositor(OpenGL::IOpenGLContext& context, + Scene2D& scene); + + ~OpenGLCompositor(); + + void UpdateSize(); + + void Refresh(); + + void SetFont(size_t index, + const GlyphBitmapAlphabet& dict); + +#if ORTHANC_ENABLE_LOCALE == 1 + void SetFont(size_t index, + Orthanc::EmbeddedResources::FileResourceId resource, + unsigned int fontSize, + Orthanc::Encoding codepage); +#endif + }; +}
--- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 26 13:04:56 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 26 14:45:47 2019 +0200 @@ -389,11 +389,17 @@ ${ORTHANC_STONE_ROOT}/Framework/OpenGL/OpenGLProgram.cpp ${ORTHANC_STONE_ROOT}/Framework/OpenGL/OpenGLShader.cpp ${ORTHANC_STONE_ROOT}/Framework/OpenGL/OpenGLTexture.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/OpenGLCompositor.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLAdvancedPolylineRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLBasicPolylineRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLColorTextureProgram.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLColorTextureRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLInfoPanelRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLLinesProgram.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLTextProgram.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLTextRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/OpenGLTextureProgram.cpp ) endif()