Skip to content
Merged
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
https://glvis.org


Version 4.2.1 (development)
===========================

- Significantly improved memory usage.


Version 4.2 released on May 23, 2022
====================================

Expand Down
17 changes: 11 additions & 6 deletions lib/gl/attr_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ template<
typename TV, typename TAttr, TAttr TV::*Attrib, typename TAttrInfo>
struct AttrBase
{
constexpr static bool NormalizeAttr =
std::is_integral<typename TAttr::value_type>::value;

constexpr static TAttr* getAttrOffset()
{
return &(((TV*)0)->*Attrib);
Expand All @@ -46,9 +43,9 @@ struct AttrBase
{
glEnableVertexAttribArray(TAttrInfo::ShaderIdx);
glVertexAttribPointer(TAttrInfo::ShaderIdx,
std::tuple_size<TAttr>::value,
TAttrInfo::NumTuples,
TAttrInfo::AttrGLType,
NormalizeAttr,
TAttrInfo::NormalizeAttr,
sizeof(TV),
(void*) getAttrOffset());
}
Expand All @@ -57,7 +54,7 @@ struct AttrBase
static void setupLegacy(TV* buffer)
{
glEnableClientState(TAttrInfo::FFArrayIdx);
TAttrInfo::FFSetupFunc(std::tuple_size<TAttr>::value,
TAttrInfo::FFSetupFunc(TAttrInfo::NumTuples,
TAttrInfo::AttrGLType,
sizeof(TV),
(char*) buffer + (size_t) getAttrOffset());
Expand Down Expand Up @@ -109,6 +106,8 @@ struct AttrCoord<TV, decltype((void)TV::coord, 0)>
: AttrBase<TV, decltype(TV::coord), &TV::coord,
AttrCoord<TV, decltype((void)TV::coord, 0)>>
{
constexpr static bool NormalizeAttr = false;
constexpr static int NumTuples = 3;
const static GLenum AttrGLType = GL_FLOAT;
const static int ShaderIdx = CoreGLDevice::ATTR_VERTEX;
const static GLenum FFArrayIdx = GL_VERTEX_ARRAY;
Expand All @@ -120,6 +119,8 @@ struct AttrNormal<TV, decltype((void)TV::norm, 0)>
: AttrBase<TV, decltype(TV::norm), &TV::norm,
AttrNormal<TV, decltype((void)TV::norm, 0)>>
{
constexpr static bool NormalizeAttr = false;
constexpr static int NumTuples = 3;
const static GLenum AttrGLType = GL_FLOAT;
const static int ShaderIdx = CoreGLDevice::ATTR_NORMAL;
const static GLenum FFArrayIdx = GL_NORMAL_ARRAY;
Expand All @@ -135,6 +136,8 @@ struct AttrColor<TV, decltype((void)TV::color, 0)>
: AttrBase<TV, decltype(TV::color), &TV::color,
AttrColor<TV, decltype((void)TV::color, 0)>>
{
constexpr static bool NormalizeAttr = true;
constexpr static int NumTuples = 4;
const static GLenum AttrGLType = GL_UNSIGNED_BYTE;
const static int ShaderIdx = CoreGLDevice::ATTR_COLOR;
const static GLenum FFArrayIdx = GL_COLOR_ARRAY;
Expand All @@ -146,6 +149,8 @@ struct AttrTexcoord<TV, decltype((void)TV::texCoord, 0)>
: AttrBase<TV, decltype(TV::texCoord), &TV::texCoord,
AttrTexcoord<TV, decltype((void)TV::texCoord, 0)>>
{
constexpr static bool NormalizeAttr = false;
constexpr static int NumTuples = 1;
const static GLenum AttrGLType = GL_FLOAT;
const static int ShaderIdx = CoreGLDevice::ATTR_TEXCOORD0;
const static GLenum FFArrayIdx = GL_TEXTURE_COORD_ARRAY;
Expand Down
32 changes: 27 additions & 5 deletions lib/gl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct alignas(16) VertexColor
struct alignas(16) VertexTex
{
std::array<float, 3> coord;
std::array<float, 2> texCoord;
float texCoord;

static const int layout = LAYOUT_VTX_TEXTURE0;
};
Expand All @@ -248,7 +248,7 @@ struct alignas(16) VertexNormTex
{
std::array<float, 3> coord;
std::array<float, 3> norm;
std::array<float, 2> texCoord;
float texCoord;

static const int layout = LAYOUT_VTX_NORMAL_TEXTURE0;
};
Expand All @@ -275,7 +275,7 @@ class GlBuilder
std::array<float, 3> coords;
std::array<float, 3> norm;
std::array<uint8_t, 4> color;
std::array<float, 2> texcoord;
float texcoord;
};

FFState saved[3];
Expand Down Expand Up @@ -426,14 +426,14 @@ class GlBuilder

void glColor4fv(float * cv) { glColor4f(cv[0], cv[1], cv[2], cv[3]); }

void glTexCoord2f(float coord_u, float coord_v)
void glTexCoord1f(float coord_u)
{
if (count == 0)
{
use_tex = true;
use_color = false;
}
curr.texcoord = { coord_u, coord_v };
curr.texcoord = coord_u;
}
};

Expand Down Expand Up @@ -543,6 +543,19 @@ class IndexedVertexBuffer : public IIndexedBuffer
vertex_indices[i] += index_offset;
}
}

void addVertices(size_t nverts, const T* verts,
size_t ninds, const int* ids)
{
int index_offset = vertex_data.size();
vertex_data.insert(vertex_data.end(), verts, verts+nverts);
int old_end = vertex_indices.size();
vertex_indices.insert(vertex_indices.end(), ids, ids+ninds);
for (size_t i = old_end; i < vertex_indices.size(); i++)
{
vertex_indices[i] += index_offset;
}
}
};

class TextBuffer : public IVertexBuffer
Expand Down Expand Up @@ -707,6 +720,15 @@ class GlDrawable
getIndexedBuffer<Vert>(GL_TRIANGLES)->addVertices(verts, inds);
}

template<typename Vert>
void addTriangleIndexed(size_t nverts,
const Vert* verts,
size_t ninds,
const int* inds)
{
getIndexedBuffer<Vert>(GL_TRIANGLES)->addVertices(nverts, verts, ninds, inds);
}

template<typename Vert>
void addQuadIndexed(const std::vector<Vert>& verts,
const std::vector<int>& inds)
Expand Down
12 changes: 5 additions & 7 deletions lib/openglvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,13 @@ ::DrawTriangle(gl3::GlDrawable& buff,
return;
}

std::array<float, 2> texcoord[3];
float texcoord[3];
std::array<float, 3> fpts[3];
std::array<float, 3> fnorm = {(float) nor[0], (float) nor[1], (float) nor[2]};

for (int i = 0; i < 3; i++)
{
float pal_coord = palette.GetColorCoord(cv[i], minv, maxv);
texcoord[i] = { pal_coord, 1.0 };
texcoord[i] = palette.GetColorCoord(cv[i], minv, maxv);
fpts[i] = {(float) pts[i][0], (float) pts[i][1], (float) pts[i][2]};
}
buff.addTriangle<gl3::VertexNormTex>(
Expand All @@ -288,14 +287,13 @@ ::DrawQuad(gl3::GlDrawable& buff,
return;
}

std::array<float, 2> texcoord[4];
float texcoord[4];
std::array<float, 3> fpts[4];
std::array<float, 3> fnorm = {(float) nor[0], (float) nor[1], (float) nor[2]};

for (int i = 0; i < 4; i++)
{
float pal_coord = palette.GetColorCoord(cv[i], minv, maxv);
texcoord[i] = { pal_coord, 1.0 };
texcoord[i] = palette.GetColorCoord(cv[i], minv, maxv);
fpts[i] = {(float) pts[i][0], (float) pts[i][1], (float) pts[i][2]};
}
buff.addQuad<gl3::VertexNormTex>(
Expand Down Expand Up @@ -350,7 +348,7 @@ ::DrawPatch(gl3::GlDrawable& drawable, const DenseMatrix &pts, Vector &vals,
{
{(float) pts(0, i), (float) pts(1, i), (float) pts(2, i)},
{(float) normals(0, i), (float) normals(1, i), (float) normals(2, i)},
{(float) palette.GetColorCoord(vals(i), minv, maxv), 1.0 }
(float) palette.GetColorCoord(vals(i), minv, maxv)
});
}
if (normals_opt > 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/openglvis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class VisualizationScene
if (val < 0.0) { val = 0.0; }
if (val > 1.0) { val = 1.0; }

builder.glTexCoord2f(val, 1.0);
builder.glTexCoord1f(val);
}

// We only need 3 points, but the array is 4x3
Expand Down
6 changes: 3 additions & 3 deletions lib/palettes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7734,11 +7734,11 @@ void PaletteState::Init()
rgba_internal = GL_RGBA32F;
}
// set alpha texture to 1.0
std::vector<float> alphaTexData(MaxTextureSize * 2);
std::vector<float> alphaTexData(MaxTextureSize);
std::fill(alphaTexData.begin(), alphaTexData.end(), 1.0f);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, alpha_tex);
glTexImage2D(GL_TEXTURE_2D, 0, alpha_internal, MaxTextureSize, 2, 0,
glTexImage2D(GL_TEXTURE_2D, 0, alpha_internal, MaxTextureSize, 1, 0,
alpha_channel, GL_FLOAT, alphaTexData.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Expand Down Expand Up @@ -7850,7 +7850,7 @@ void PaletteState::GenerateAlphaTexture(float matAlpha, float matAlphaCenter)
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, alpha_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 1, MaxTextureSize, 1, alpha_channel,
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, MaxTextureSize, 1, alpha_channel,
GL_FLOAT, alphaTexData.data());
glActiveTexture(GL_TEXTURE0);
}
Expand Down
Loading