• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphia-app / graphia / 40767028424

28 Oct 2026 08:51PM UTC coverage: 69.589% (-1.5%) from 71.111%
40767028424

push

github

timangus
blah

11606 of 18200 branches covered (63.77%)

Branch coverage included in aggregate %.

818 of 2594 new or added lines in 59 files covered. (31.53%)

69 existing lines in 10 files now uncovered.

30070 of 41689 relevant lines covered (72.13%)

167447.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/source/app/rendering/texelbuffer.cpp
1
/* Copyright © 2013-2025 Tim Angus
2
 * Copyright © 2013-2025 Tom Freeman
3
 *
4
 * This file is part of Graphia.
5
 *
6
 * Graphia is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Graphia is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with Graphia.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "texelbuffer.h"
21

22
#include <QtGlobal>
23

24
#ifdef OPENGL_ES
25
#include <algorithm>
26
#include <cmath>
27
#endif
28

29
TexelBuffer::TexelBuffer()
NEW
30
{
×
NEW
31
    resolveOpenGLFunctions();
×
32

NEW
33
    glGenTextures(1, &_texture);
×
NEW
34
    glBindTexture(Target, _texture);
×
35

36
#ifdef OPENGL_ES
37
    // ES 3.0 has no buffer textures, so a 2D texture of roughly square
38
    // dimensions stands in for one, which the shader reads a row at a time
39
    glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
40
    glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
41
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maximumWidth);
42
#else
NEW
43
    glGenBuffers(1, &_buffer);
×
NEW
44
    glBindBuffer(Target, _buffer);
×
NEW
45
    glTexBuffer(Target, GL_RGBA32F, _buffer);
×
NEW
46
    glBindBuffer(Target, 0);
×
NEW
47
#endif
×
48

NEW
49
    glBindTexture(Target, 0);
×
NEW
50
}
×
51

52
TexelBuffer::~TexelBuffer()
NEW
53
{
×
NEW
54
#ifndef OPENGL_ES
×
NEW
55
    glDeleteBuffers(1, &_buffer);
×
NEW
56
#endif
×
57

NEW
58
    glDeleteTextures(1, &_texture);
×
NEW
59
}
×
60

61
void TexelBuffer::upload(std::span<const GLfloat> texels)
NEW
62
{
×
NEW
63
    Q_ASSERT(texels.size() % 4 == 0);
×
64

65
#ifdef OPENGL_ES
66
    const auto numTexels = static_cast<GLint>(texels.size() / 4);
67
    const auto width = std::clamp(static_cast<GLint>(std::ceil(std::sqrt(numTexels))),
68
        1, std::max(1, _maximumWidth));
69
    const auto height = (numTexels + width - 1) / width;
70

71
    glBindTexture(Target, _texture);
72

73
    if(width != _width || height != _height)
74
    {
75
        glTexImage2D(Target, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);
76
        _width = width;
77
        _height = height;
78
    }
79

80
    const auto numFullRows = numTexels / width;
81
    const auto lastRowLength = numTexels % width;
82

83
    if(numFullRows > 0)
84
    {
85
        glTexSubImage2D(Target, 0, 0, 0, width, numFullRows,
86
            GL_RGBA, GL_FLOAT, texels.data());
87
    }
88

89
    if(lastRowLength > 0)
90
    {
91
        glTexSubImage2D(Target, 0, 0, numFullRows, lastRowLength, 1,
92
            GL_RGBA, GL_FLOAT, &texels[static_cast<size_t>(numFullRows * width * 4)]);
93
    }
94

95
    glBindTexture(Target, 0);
96
#else
NEW
97
    glBindBuffer(Target, _buffer);
×
NEW
98
    glBufferData(Target, static_cast<GLsizeiptr>(texels.size_bytes()),
×
NEW
99
        texels.data(), GL_STREAM_DRAW);
×
NEW
100
    glBindBuffer(Target, 0);
×
NEW
101
#endif
×
NEW
102
}
×
103

104
void TexelBuffer::bind(GLenum textureUnit)
NEW
105
{
×
NEW
106
    glActiveTexture(textureUnit);
×
NEW
107
    glBindTexture(Target, _texture);
×
NEW
108
}
×
109

110
void TexelBuffer::release(GLenum textureUnit)
NEW
111
{
×
NEW
112
    glActiveTexture(textureUnit);
×
NEW
113
    glBindTexture(Target, 0);
×
NEW
114
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc