annotate Framework/Scene2D/Internals/OpenGLTextProgram.cpp @ 826:2de01660debe

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 29 May 2019 16:48:56 +0200
parents 61ba4b504e9a
children 1091b2adeb5a
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
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
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
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
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
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
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 #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
23 #include "OpenGLShaderVersionDirective.h"
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../../Fonts/OpenGLTextCoordinates.h"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Core/OrthancException.h>
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 static const unsigned int COMPONENTS = 2;
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 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
33 ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 "attribute vec2 a_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 "attribute vec4 a_position; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 "uniform mat4 u_matrix; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 "varying vec2 v_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 "void main() \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 "{ \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 " gl_Position = u_matrix * a_position; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 " v_texcoord = a_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 "}";
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 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
45 ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 "uniform sampler2D u_texture; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 "uniform vec3 u_color; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 "varying vec2 v_texcoord; \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 "void main() \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 "{ \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 " vec4 v = texture2D(u_texture, v_texcoord); \n"
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 " gl_FragColor = vec4(u_color * v.w, v.w); \n" // Premultiplied alpha
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 "}";
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 namespace OrthancStone
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 Internals
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 OpenGLTextProgram::OpenGLTextProgram(OpenGL::IOpenGLContext& context) :
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 context_(context)
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 context_.MakeCurrent();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 program_.reset(new OpenGL::OpenGLProgram);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 program_->CompileShaders(VERTEX_SHADER, FRAGMENT_SHADER);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 positionLocation_ = program_->GetAttributeLocation("a_position");
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 textureLocation_ = program_->GetAttributeLocation("a_texcoord");
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 OpenGLTextProgram::Data::Data(OpenGL::IOpenGLContext& context,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 const GlyphTextureAlphabet& alphabet,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 const TextSceneLayer& layer) :
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 context_(context),
804
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
78 red_(layer.GetColor().GetRedAsFloat()),
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
79 green_(layer.GetColor().GetGreenAsFloat()),
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
80 blue_(layer.GetColor().GetBlueAsFloat()),
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 x_(layer.GetX()),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 y_(layer.GetY()),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 border_(layer.GetBorder()),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 anchor_(layer.GetAnchor())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 OpenGL::OpenGLTextCoordinates coordinates(alphabet, layer.GetText());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 textWidth_ = coordinates.GetTextWidth();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 textHeight_ = coordinates.GetTextHeight();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 if (coordinates.IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 coordinatesCount_ = 0;
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 else
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_ = coordinates.GetRenderingCoords().size();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 context_.MakeCurrent();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 glGenBuffers(2, buffers_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 glBindBuffer(GL_ARRAY_BUFFER, buffers_[0]);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * coordinatesCount_,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 &coordinates.GetRenderingCoords() [0], GL_STATIC_DRAW);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 glBindBuffer(GL_ARRAY_BUFFER, buffers_[1]);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * coordinatesCount_,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 &coordinates.GetTextureCoords() [0], GL_STATIC_DRAW);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 OpenGLTextProgram::Data::~Data()
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (!IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 context_.MakeCurrent();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 glDeleteBuffers(2, buffers_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
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 GLuint OpenGLTextProgram::Data::GetSceneLocationsBuffer() const
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 if (IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 else
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 return buffers_[0];
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 GLuint OpenGLTextProgram::Data::GetTextureLocationsBuffer() const
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 if (IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 else
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 return buffers_[1];
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 void OpenGLTextProgram::Apply(OpenGL::OpenGLTexture& fontTexture,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 const Data& data,
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 const AffineTransform2D& transform)
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 if (!data.IsEmpty())
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 context_.MakeCurrent();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 program_->Use();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 double dx, dy; // In pixels
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 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
159 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
160 static_cast<unsigned int>(data.GetBorder()));
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 double x = data.GetX();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 double y = data.GetY();
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 transform.Apply(x, y);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 const AffineTransform2D t = AffineTransform2D::CreateOffset(x + dx, y + dy);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 float m[16];
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 t.ConvertToOpenGLMatrix(m, context_.GetCanvasWidth(), context_.GetCanvasHeight());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 fontTexture.Bind(program_->GetUniformLocation("u_texture"));
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 glUniformMatrix4fv(program_->GetUniformLocation("u_matrix"), 1, GL_FALSE, m);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 glUniform3f(program_->GetUniformLocation("u_color"),
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 data.GetRed(), data.GetGreen(), data.GetBlue());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 glBindBuffer(GL_ARRAY_BUFFER, data.GetSceneLocationsBuffer());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 glEnableVertexAttribArray(positionLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 glVertexAttribPointer(positionLocation_, COMPONENTS, GL_FLOAT, GL_FALSE, 0, 0);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 glBindBuffer(GL_ARRAY_BUFFER, data.GetTextureLocationsBuffer());
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 glEnableVertexAttribArray(textureLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 glVertexAttribPointer(textureLocation_, COMPONENTS, GL_FLOAT, GL_FALSE, 0, 0);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 glEnable(GL_BLEND);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 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
186 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
187 static_cast<GLsizei>(data.GetCoordinatesCount() / COMPONENTS));
592
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 glDisable(GL_BLEND);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 glDisableVertexAttribArray(positionLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 glDisableVertexAttribArray(textureLocation_);
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
bbe29efd3d1c OpenGLLinesProgram
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }