Freestyle: time/space optimization in stroke rendering without textures.
When strokes do not have textures assigned, UV coordinates are not computed now. This will save a bit of time and space in stroke rendering.
This commit is contained in:
parent
dfe800b4a8
commit
fe0236be78
|
@ -267,6 +267,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
|
|||
////////////////////
|
||||
|
||||
vector<Strip*>& strips = iStrokeRep->getStrips();
|
||||
const bool hasTex = iStrokeRep->getMTex(0) != NULL;
|
||||
Strip::vertex_container::iterator v[3];
|
||||
StrokeVertexRep *svRep[3];
|
||||
/* Vec3r color[3]; */ /* UNUSED */
|
||||
|
@ -356,7 +357,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
|
|||
MPoly *polys = mesh->mpoly;
|
||||
MLoop *loops = mesh->mloop;
|
||||
MLoopCol *colors = mesh->mloopcol;
|
||||
MLoopUV *loopsuv[2];
|
||||
MLoopUV *loopsuv[2] = {NULL};
|
||||
|
||||
v[0] = strip_vertices.begin();
|
||||
v[1] = v[0] + 1;
|
||||
|
@ -365,23 +366,25 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
|
|||
vertex_index = edge_index = loop_index = 0;
|
||||
visible = false;
|
||||
|
||||
// First UV layer
|
||||
CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, "along_stroke");
|
||||
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke");
|
||||
CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 0);
|
||||
CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0);
|
||||
BKE_mesh_update_customdata_pointers(mesh, true);
|
||||
if (hasTex) {
|
||||
// First UV layer
|
||||
CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, "along_stroke");
|
||||
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke");
|
||||
CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 0);
|
||||
CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0);
|
||||
BKE_mesh_update_customdata_pointers(mesh, true);
|
||||
|
||||
loopsuv[0] = mesh->mloopuv;
|
||||
loopsuv[0] = mesh->mloopuv;
|
||||
|
||||
// Second UV layer
|
||||
CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, "along_stroke_tips");
|
||||
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke_tips");
|
||||
CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 1);
|
||||
CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1);
|
||||
BKE_mesh_update_customdata_pointers(mesh, true);
|
||||
// Second UV layer
|
||||
CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, "along_stroke_tips");
|
||||
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke_tips");
|
||||
CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 1);
|
||||
CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1);
|
||||
BKE_mesh_update_customdata_pointers(mesh, true);
|
||||
|
||||
loopsuv[1] = mesh->mloopuv;
|
||||
loopsuv[1] = mesh->mloopuv;
|
||||
}
|
||||
|
||||
// Note: Mesh generation in the following loop assumes stroke strips
|
||||
// to be triangle strips.
|
||||
|
@ -487,7 +490,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
|
|||
loop_index += 3;
|
||||
|
||||
// UV
|
||||
if (iStrokeRep->getMTex(0)) {
|
||||
if (hasTex) {
|
||||
// First UV layer (loopsuv[0]) has no tips (texCoord(0)).
|
||||
// Second UV layer (loopsuv[1]) has tips: (texCoord(1)).
|
||||
for (int L = 0; L < 2; L++) {
|
||||
|
|
|
@ -652,6 +652,12 @@ public:
|
|||
inline MTex *getMTex(int idx) {
|
||||
return _mtex[idx];}
|
||||
|
||||
/*! Returns true if this Stroke has textures assigned, false otherwise. */
|
||||
inline bool hasTex() const
|
||||
{
|
||||
return _mtex[0] != NULL;
|
||||
}
|
||||
|
||||
/*! Returns true if this Stroke uses a texture with tips, false otherwise. */
|
||||
inline bool hasTips() const
|
||||
{
|
||||
|
|
|
@ -54,13 +54,17 @@ StrokeVertexRep::StrokeVertexRep(const StrokeVertexRep& iBrother)
|
|||
// STRIP
|
||||
/////////////////////////////////////
|
||||
|
||||
Strip::Strip(const vector<StrokeVertex*>& iStrokeVertices, bool hasTips, bool beginTip, bool endTip, float texStep)
|
||||
Strip::Strip(const vector<StrokeVertex*>& iStrokeVertices, bool hasTex, bool beginTip, bool endTip, float texStep)
|
||||
{
|
||||
createStrip(iStrokeVertices);
|
||||
|
||||
// We compute both kinds of coordinates to use different kinds of textures
|
||||
computeTexCoord (iStrokeVertices, texStep);
|
||||
computeTexCoordWithTips (iStrokeVertices, beginTip, endTip, texStep);
|
||||
setVertexColor(iStrokeVertices);
|
||||
|
||||
if (hasTex) {
|
||||
// We compute both kinds of coordinates to use different kinds of textures
|
||||
computeTexCoord(iStrokeVertices, texStep);
|
||||
computeTexCoordWithTips(iStrokeVertices, beginTip, endTip, texStep);
|
||||
}
|
||||
}
|
||||
|
||||
Strip::Strip(const Strip& iBrother)
|
||||
|
@ -483,6 +487,30 @@ void Strip::cleanUpSingularities (const vector<StrokeVertex*>& iStrokeVertices)
|
|||
}
|
||||
|
||||
|
||||
// Vertex color (RGBA)
|
||||
////////////////////////////////
|
||||
|
||||
void Strip::setVertexColor (const vector<StrokeVertex *>& iStrokeVertices)
|
||||
{
|
||||
vector<StrokeVertex *>::const_iterator v, vend;
|
||||
StrokeVertex *sv;
|
||||
int i = 0;
|
||||
for (v = iStrokeVertices.begin(), vend = iStrokeVertices.end(); v != vend; v++) {
|
||||
sv = (*v);
|
||||
_vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB()));
|
||||
_vertices[i]->setAlpha(sv->attribute().getAlpha());
|
||||
i++;
|
||||
_vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB()));
|
||||
_vertices[i]->setAlpha(sv->attribute().getAlpha());
|
||||
i++;
|
||||
#if 0
|
||||
cerr << "col=("<<sv->attribute().getColor()[0] << ", "
|
||||
<< sv->attribute().getColor()[1] << ", " << sv->attribute().getColor()[2] << ")" << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Texture coordinates
|
||||
////////////////////////////////
|
||||
|
||||
|
@ -494,17 +522,9 @@ void Strip::computeTexCoord (const vector<StrokeVertex *>& iStrokeVertices, floa
|
|||
for (v = iStrokeVertices.begin(), vend = iStrokeVertices.end(); v != vend; v++) {
|
||||
sv = (*v);
|
||||
_vertices[i]->setTexCoord(Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), 0));
|
||||
_vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB()));
|
||||
_vertices[i]->setAlpha(sv->attribute().getAlpha());
|
||||
i++;
|
||||
_vertices[i]->setTexCoord(Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), 1));
|
||||
_vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB()));
|
||||
_vertices[i]->setAlpha(sv->attribute().getAlpha());
|
||||
i++;
|
||||
#if 0
|
||||
cerr << "col=("<<sv->attribute().getColor()[0] << ", "
|
||||
<< sv->attribute().getColor()[1] << ", " << sv->attribute().getColor()[2] << ")" << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -788,7 +808,7 @@ void StrokeRep::create()
|
|||
end = true;
|
||||
}
|
||||
if ((!strip.empty()) && (strip.size() > 1)) {
|
||||
_strips.push_back(new Strip(strip, _stroke->hasTips(), first, end, _stroke->getTextureStep()));
|
||||
_strips.push_back(new Strip(strip, _stroke->hasTex(), first, end, _textureStep));
|
||||
strip.clear();
|
||||
}
|
||||
first = false;
|
||||
|
|
|
@ -148,7 +148,7 @@ protected:
|
|||
float _averageThickness;
|
||||
|
||||
public:
|
||||
Strip(const std::vector<StrokeVertex*>& iStrokeVertices, bool hasTips = false,
|
||||
Strip(const std::vector<StrokeVertex*>& iStrokeVertices, bool hasTex = false,
|
||||
bool tipBegin = false, bool tipEnd = false, float texStep = 1.0);
|
||||
Strip(const Strip& iBrother);
|
||||
virtual ~Strip();
|
||||
|
@ -156,6 +156,7 @@ public:
|
|||
protected:
|
||||
void createStrip(const std::vector<StrokeVertex*>& iStrokeVertices);
|
||||
void cleanUpSingularities(const std::vector<StrokeVertex*>& iStrokeVertices);
|
||||
void setVertexColor (const std::vector<StrokeVertex*>& iStrokeVertices);
|
||||
void computeTexCoord (const std::vector<StrokeVertex*>& iStrokeVertices, float texStep);
|
||||
void computeTexCoordWithTips (const std::vector<StrokeVertex*>& iStrokeVertices, bool tipBegin, bool tipEnd, float texStep);
|
||||
|
||||
|
|
Loading…
Reference in New Issue