diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-05-07 18:14:36 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-05-07 18:16:23 +0400 |
commit | fe0236be78bf1ab79037fb238db353d2c6820e98 (patch) | |
tree | 566367a110845925434bddf68130d1f760850cdc /source/blender/freestyle/intern/stroke | |
parent | dfe800b4a80a39e95013b3695db87b5abe587d5f (diff) |
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.
Diffstat (limited to 'source/blender/freestyle/intern/stroke')
-rw-r--r-- | source/blender/freestyle/intern/stroke/Stroke.h | 6 | ||||
-rw-r--r-- | source/blender/freestyle/intern/stroke/StrokeRep.cpp | 38 | ||||
-rw-r--r-- | source/blender/freestyle/intern/stroke/StrokeRep.h | 3 |
3 files changed, 37 insertions, 10 deletions
diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index 27a105bb1cc..d6c8c4f0d07 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -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 { diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index cd5a4bfcbb6..8e84228f37f 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -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,21 +487,19 @@ void Strip::cleanUpSingularities (const vector<StrokeVertex*>& iStrokeVertices) } -// Texture coordinates +// Vertex color (RGBA) //////////////////////////////// -void Strip::computeTexCoord (const vector<StrokeVertex *>& iStrokeVertices, float texStep) +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]->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++; @@ -508,6 +510,24 @@ void Strip::computeTexCoord (const vector<StrokeVertex *>& iStrokeVertices, floa } } + +// Texture coordinates +//////////////////////////////// + +void Strip::computeTexCoord (const vector<StrokeVertex *>& iStrokeVertices, float texStep) +{ + 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]->setTexCoord(Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), 0)); + i++; + _vertices[i]->setTexCoord(Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), 1)); + i++; + } +} + void Strip::computeTexCoordWithTips (const vector<StrokeVertex*>& iStrokeVertices, bool tipBegin, bool tipEnd, float texStep) { vector<StrokeVertex*>::const_iterator v, vend; @@ -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; diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.h b/source/blender/freestyle/intern/stroke/StrokeRep.h index 8bbbd9240cb..61a456cdf42 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.h +++ b/source/blender/freestyle/intern/stroke/StrokeRep.h @@ -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); |