Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5584: ArbitraryMeshVertex is hosting a 4-component colour vector now.
All other geometry except for ParticleNodes are expecting the colour to be set per draw call (glColor), not per vertex (glColorPointer). This will require a few more steps.
  • Loading branch information
codereader committed Dec 16, 2021
1 parent 381ba0c commit 4456273
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 17 deletions.
11 changes: 6 additions & 5 deletions libs/render/ArbitraryMeshVertex.h
Expand Up @@ -3,6 +3,7 @@
#include <cstddef>

#include "math/Vector3.h"
#include "math/Vector4.h"
#include "Vertex3f.h"
#include "TexCoord2f.h"
#include "VertexTraits.h"
Expand All @@ -20,27 +21,27 @@ class ArbitraryMeshVertex
Normal3f bitangent;

// Vertex colour
Vector3 colour;
Vector4 colour;

/// Default constructor.
ArbitraryMeshVertex()
: tangent(0, 0, 0),
bitangent(0, 0, 0),
colour(1.0, 1.0, 1.0)
colour(1.0, 1.0, 1.0, 1.0)
{}

/// Initialising constructor, leaves colour at 1,1,1 and tangent vectors at 0,0,0
/// Initialising constructor, leaves colour at 1,1,1,1 and tangent vectors at 0,0,0
ArbitraryMeshVertex(const Vertex3f& v, const Normal3f& n, const TexCoord2f& t) :
texcoord(t),
normal(n),
vertex(v),
tangent(0, 0, 0),
bitangent(0, 0, 0),
colour(1.0, 1.0, 1.0)
colour(1.0, 1.0, 1.0, 1.0)
{}

/// Initialising constructor, leaves tangent vectors at 0,0,0
ArbitraryMeshVertex(const Vertex3f& v, const Normal3f& n, const TexCoord2f& t, const Vector3& c) :
ArbitraryMeshVertex(const Vertex3f& v, const Normal3f& n, const TexCoord2f& t, const Vector4& c) :
texcoord(t),
normal(n),
vertex(v),
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/StaticModelSurface.cpp
Expand Up @@ -126,7 +126,7 @@ GLuint StaticModelSurface::compileProgramList(bool includeColour)
// Optional vertex colour
if (includeColour)
{
glColor3dv(v.colour);
glColor4dv(v.colour);
}

// Submit the vertex itself
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/export/AseExporter.cpp
Expand Up @@ -210,7 +210,7 @@ void AseExporter::exportToStream(std::ostream& stream)

for (std::size_t v = 0; v < surface.vertices.size(); ++v)
{
const Vector3& vcol = surface.vertices[v].colour;
const auto& vcol = surface.vertices[v].colour.getVector3();

stream << "\t\t\t*MESH_VERTCOL " << v << "\t" << vcol.x() << "\t" << vcol.y() << "\t" << vcol.z() << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/export/Lwo2Exporter.cpp
Expand Up @@ -190,7 +190,7 @@ void Lwo2Exporter::exportToStream(std::ostream& stream)
stream::writeBigEndian<float>(colourVmap->stream, static_cast<float>(vertex.colour.x()));
stream::writeBigEndian<float>(colourVmap->stream, static_cast<float>(vertex.colour.y()));
stream::writeBigEndian<float>(colourVmap->stream, static_cast<float>(vertex.colour.z()));
stream::writeBigEndian<float>(colourVmap->stream, 1.0f);
stream::writeBigEndian<float>(colourVmap->stream, static_cast<float>(vertex.colour.w()));

// Accumulate the BBOX
bounds.includePoint(vertex.vertex);
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/export/ModelExporter.cpp
Expand Up @@ -31,7 +31,7 @@ ArbitraryMeshVertex convertWindingVertex(const WindingVertex& in)
out.texcoord = in.texcoord;
out.bitangent = in.bitangent;
out.tangent = in.tangent;
out.colour.set(1.0, 1.0, 1.0);
out.colour = Vector4(1.0, 1.0, 1.0, 1.0);

return out;
}
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/model/picomodel/PicoModelLoader.cpp
Expand Up @@ -25,14 +25,14 @@ namespace
}

// Convert byte pointers to colour vector
inline Vector3 getColourVector(unsigned char* array)
inline Vector4 getColourVector(unsigned char* array)
{
if (array)
{
return Vector3(array[0] / 255.0f, array[1] / 255.0f, array[2] / 255.0f);
return Vector4(array[0] / 255.0f, array[1] / 255.0f, array[2] / 255.0f, array[3] / 255.0f);
}

return Vector3(1.0f, 1.0f, 1.0f); // white
return Vector4(1.0, 1.0, 1.0, 1.0); // white
}
} // namespace

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/particles/RenderableParticleBunch.cpp
Expand Up @@ -169,7 +169,7 @@ void RenderableParticleBunch::addVertexData(std::vector<ArbitraryMeshVertex>& ve
quad.verts[i].vertex,
quad.verts[i].normal,
quad.verts[i].texcoord,
quad.verts[i].colour.getVector3()) // TODO: 4th colour component
quad.verts[i].colour)
);
}

Expand Down
5 changes: 4 additions & 1 deletion radiantcore/rendersystem/backend/GeometryRenderer.h
Expand Up @@ -33,6 +33,7 @@ class GeometryRenderer :
glVertexPointer(3, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().vertex);
glTexCoordPointer(2, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().texcoord);
glNormalPointer(GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().normal);
glColorPointer(4, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().colour);

glDrawElements(_mode, static_cast<GLsizei>(_indices.size()), GL_UNSIGNED_INT, &_indices.front());
}
Expand All @@ -42,16 +43,18 @@ class GeometryRenderer :
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glFrontFace(GL_CW);

glVertexPointer(3, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().vertex);
glTexCoordPointer(2, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().texcoord);
glNormalPointer(GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().normal);
glColorPointer(4, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &_vertices.front().colour);

glDrawElements(_mode, static_cast<GLsizei>(numIndices), GL_UNSIGNED_INT, &_indices[firstIndex]);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

Expand Down
2 changes: 2 additions & 0 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -136,6 +136,7 @@ void OpenGLShader::drawSurfaces()
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

// Surfaces are using CW culling
glFrontFace(GL_CW);
Expand Down Expand Up @@ -195,6 +196,7 @@ void OpenGLShader::drawSurfaces()
#endif

glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

Expand Down
6 changes: 3 additions & 3 deletions test/ModelExport.cpp
Expand Up @@ -103,9 +103,9 @@ inline bool surfaceHasVertex(const model::IModelSurface& surface, const std::fun
}

const std::string CustomMaterialName = "custom_surface_name";
const Vector3 VertexColour1(0.1, 0.2, 0.3);
const Vector3 VertexColour2(0.4, 0.5, 0.6);
const Vector3 VertexColour3(0.7, 0.8, 0.9);
const Vector4 VertexColour1(0.1, 0.2, 0.3, 0.11);
const Vector4 VertexColour2(0.4, 0.5, 0.6, 0.12);
const Vector4 VertexColour3(0.7, 0.8, 0.9, 0.13);

inline model::ModelNodePtr getChildModelNode(const scene::INodePtr& entity)
{
Expand Down

0 comments on commit 4456273

Please sign in to comment.