annotate OrthancStone/Sources/Scene2D/Internals/OpenGLTextProgram.cpp @ 1739:9ac2a65d4172

upgrade to year 2021
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Jan 2021 17:50:00 +0100
parents 59f95b9ea858
children 3889ae96d2e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1739
9ac2a65d4172 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1624
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "OpenGLTextProgram.h"
611
e3f21a265be5 Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents: 592
diff changeset
24 #include "OpenGLShaderVersionDirective.h"
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../../Fonts/OpenGLTextCoordinates.h"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1624
59f95b9ea858 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
28 #include <Logging.h>
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
29 #include <OrthancException.h>
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static const unsigned int COMPONENTS = 2;
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 static const char* VERTEX_SHADER =
611
e3f21a265be5 Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents: 592
diff changeset
35 ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 "attribute vec2 a_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 "attribute vec4 a_position; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 "uniform mat4 u_matrix; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 "varying vec2 v_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 "void main() \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 "{ \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 " gl_Position = u_matrix * a_position; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 " v_texcoord = a_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 "}";
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 static const char* FRAGMENT_SHADER =
611
e3f21a265be5 Added version directive to GLSL shader code + glew init function in sample code
Benjamin Golinvaux <bgo@osimis.io>
parents: 592
diff changeset
47 ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 "uniform sampler2D u_texture; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 "uniform vec3 u_color; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 "varying vec2 v_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 "void main() \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 "{ \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 " vec4 v = texture2D(u_texture, v_texcoord); \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 " gl_FragColor = vec4(u_color * v.w, v.w); \n" // Premultiplied alpha
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 "}";
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 namespace OrthancStone
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 namespace Internals
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 OpenGLTextProgram::OpenGLTextProgram(OpenGL::IOpenGLContext& context) :
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 context_(context)
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
65 if (!context_.IsContextLost())
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
66 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
67 context_.MakeCurrent();
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
69 program_.reset(new OpenGL::OpenGLProgram(context_));
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
70 program_->CompileShaders(VERTEX_SHADER, FRAGMENT_SHADER);
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
72 positionLocation_ = program_->GetAttributeLocation("a_position");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
73 textureLocation_ = program_->GetAttributeLocation("a_texcoord");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
74 }
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 OpenGLTextProgram::Data::Data(OpenGL::IOpenGLContext& context,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 const GlyphTextureAlphabet& alphabet,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 const TextSceneLayer& layer) :
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 context_(context),
804
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
82 red_(layer.GetColor().GetRedAsFloat()),
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
83 green_(layer.GetColor().GetGreenAsFloat()),
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
84 blue_(layer.GetColor().GetBlueAsFloat()),
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 x_(layer.GetX()),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 y_(layer.GetY()),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 border_(layer.GetBorder()),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 anchor_(layer.GetAnchor())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 OpenGL::OpenGLTextCoordinates coordinates(alphabet, layer.GetText());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 textWidth_ = coordinates.GetTextWidth();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 textHeight_ = coordinates.GetTextHeight();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 if (coordinates.IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 coordinatesCount_ = 0;
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 else
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 coordinatesCount_ = coordinates.GetRenderingCoords().size();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
102 if (!context_.IsContextLost())
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
103 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
104 context_.MakeCurrent();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
105 glGenBuffers(2, buffers_);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
106 ORTHANC_OPENGL_CHECK("glGenBuffers");
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
108 glBindBuffer(GL_ARRAY_BUFFER, buffers_[0]);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
109 ORTHANC_OPENGL_CHECK("glBindBuffer");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
110 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * coordinatesCount_,
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
111 &coordinates.GetRenderingCoords()[0], GL_STATIC_DRAW);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
112 ORTHANC_OPENGL_CHECK("glBufferData");
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
114 glBindBuffer(GL_ARRAY_BUFFER, buffers_[1]);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
115 ORTHANC_OPENGL_CHECK("glBindBuffer");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
116 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * coordinatesCount_,
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
117 &coordinates.GetTextureCoords()[0], GL_STATIC_DRAW);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
118 ORTHANC_OPENGL_CHECK("glBufferData");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
119 }
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 OpenGLTextProgram::Data::~Data()
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
126 if (!context_.IsContextLost() && !IsEmpty())
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
128 try
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
129 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
130 context_.MakeCurrent();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
131 ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT("About to call glDeleteBuffers");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
132 glDeleteBuffers(2, buffers_);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
133 ORTHANC_OPENGL_CHECK("glDeleteBuffers");
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
134 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
135 catch (const Orthanc::OrthancException& e)
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
136 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
137 if (e.HasDetails())
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
138 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
139 LOG(ERROR) << "OrthancException in ~Data: " << e.What() << " Details: " << e.GetDetails();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
140 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
141 else
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
142 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
143 LOG(ERROR) << "OrthancException in ~Data: " << e.What();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
144 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
145 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
146 catch (const std::exception& e)
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
147 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
148 LOG(ERROR) << "std::exception in ~Data: " << e.what();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
149 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
150 catch (...)
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
151 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
152 LOG(ERROR) << "Unknown exception in ~Data";
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
153 }
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 GLuint OpenGLTextProgram::Data::GetSceneLocationsBuffer() const
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 if (IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
162 LOG(ERROR) << "OpenGLTextProgram::Data::GetSceneLocationsBuffer(): (IsEmpty())";
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 else
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 return buffers_[0];
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 GLuint OpenGLTextProgram::Data::GetTextureLocationsBuffer() const
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 if (IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
175 LOG(ERROR) << "OpenGLTextProgram::Data::GetTextureLocationsBuffer(): (IsEmpty())";
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 else
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 return buffers_[1];
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 void OpenGLTextProgram::Apply(OpenGL::OpenGLTexture& fontTexture,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 const Data& data,
1576
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
186 const AffineTransform2D& transform,
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
187 unsigned int canvasWidth,
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
188 unsigned int canvasHeight)
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
190 if (!context_.IsContextLost() && !data.IsEmpty())
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 context_.MakeCurrent();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 program_->Use();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 double dx, dy; // In pixels
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 ComputeAnchorTranslation(dx, dy, data.GetAnchor(),
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 611
diff changeset
197 data.GetTextWidth(), data.GetTextHeight(),
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 611
diff changeset
198 static_cast<unsigned int>(data.GetBorder()));
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 double x = data.GetX();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 double y = data.GetY();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 transform.Apply(x, y);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 const AffineTransform2D t = AffineTransform2D::CreateOffset(x + dx, y + dy);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 float m[16];
1576
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
207 t.ConvertToOpenGLMatrix(m, canvasWidth, canvasHeight);
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 fontTexture.Bind(program_->GetUniformLocation("u_texture"));
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 glUniformMatrix4fv(program_->GetUniformLocation("u_matrix"), 1, GL_FALSE, m);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 glUniform3f(program_->GetUniformLocation("u_color"),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 data.GetRed(), data.GetGreen(), data.GetBlue());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 glBindBuffer(GL_ARRAY_BUFFER, data.GetSceneLocationsBuffer());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 glEnableVertexAttribArray(positionLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 glVertexAttribPointer(positionLocation_, COMPONENTS, GL_FLOAT, GL_FALSE, 0, 0);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 glBindBuffer(GL_ARRAY_BUFFER, data.GetTextureLocationsBuffer());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 glEnableVertexAttribArray(textureLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 glVertexAttribPointer(textureLocation_, COMPONENTS, GL_FLOAT, GL_FALSE, 0, 0);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 glEnable(GL_BLEND);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 611
diff changeset
224 glDrawArrays(GL_TRIANGLES, 0,
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 611
diff changeset
225 static_cast<GLsizei>(data.GetCoordinatesCount() / COMPONENTS));
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 glDisable(GL_BLEND);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 glDisableVertexAttribArray(positionLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 glDisableVertexAttribArray(textureLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }