00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023 #ifndef H_SPK_GLLINETRAILRENDERER
00024 #define H_SPK_GLLINETRAILRENDERER
00025
00026 #include "RenderingAPIs/OpenGL/SPK_GLRenderer.h"
00027 #include "Core/SPK_Particle.h"
00028 #include "Core/SPK_Model.h"
00029
00030
00031 namespace SPK
00032 {
00033 namespace GL
00034 {
00060 class SPK_GL_PREFIX GLLineTrailRenderer : public GLRenderer
00061 {
00062 SPK_IMPLEMENT_REGISTERABLE(GLLineTrailRenderer)
00063
00064 public :
00065
00067
00069
00071 GLLineTrailRenderer();
00072
00078 static GLLineTrailRenderer* create();
00079
00081
00083
00092 void setNbSamples(size_t nbSamples);
00093
00101 void setWidth(float width);
00102
00111 void setDuration(float duration);
00112
00120 void setDegeneratedLines(float r,float g,float b,float a);
00121
00122 virtual void enableBlending(bool blendingEnabled);
00123
00125
00127
00132 size_t getNbSamples() const;
00133
00138 float getWidth() const;
00139
00144 float getDuration() const;
00145
00147
00149
00150 virtual void createBuffers(const Group& group);
00151 virtual void destroyBuffers(const Group& group);
00152
00162 void init(const Group& group);
00163 virtual void render(const Group& group);
00164
00165 protected :
00166
00167 virtual bool checkBuffers(const Group& group);
00168
00169 private :
00170
00171 size_t nbSamples;
00172
00173 float width;
00174 float duration;
00175
00176 float degeneratedR;
00177 float degeneratedG;
00178 float degeneratedB;
00179 float degeneratedA;
00180
00181
00182 static float* vertexBuffer;
00183 static float* vertexIterator;
00184 static float* colorBuffer;
00185 static float* colorIterator;
00186 static float* valueBuffer;
00187 static float* valueIterator;
00188
00189
00190 static const std::string VERTEX_BUFFER_NAME;
00191 static const std::string COLOR_BUFFER_NAME;
00192 static const std::string VALUE_BUFFER_NAME;
00193
00194 void init(const Particle& particle,float age) const;
00195 };
00196
00197
00198 inline GLLineTrailRenderer* GLLineTrailRenderer::create()
00199 {
00200 GLLineTrailRenderer* obj = new GLLineTrailRenderer;
00201 registerObject(obj);
00202 return obj;
00203 }
00204
00205 inline void GLLineTrailRenderer::enableBlending(bool blendingEnabled)
00206 {
00207 GLRenderer::enableBlending(true);
00208 }
00209
00210 inline void GLLineTrailRenderer::setNbSamples(size_t nbSamples)
00211 {
00212 this->nbSamples = nbSamples;
00213 }
00214
00215 inline void GLLineTrailRenderer::setWidth(float width)
00216 {
00217 this->width = width;
00218 }
00219
00220 inline void GLLineTrailRenderer::setDuration(float duration)
00221 {
00222 this->duration = duration;
00223 }
00224
00225 inline size_t GLLineTrailRenderer::getNbSamples() const
00226 {
00227 return nbSamples;
00228 }
00229
00230 inline float GLLineTrailRenderer::getWidth() const
00231 {
00232 return width;
00233 }
00234
00235 inline float GLLineTrailRenderer::getDuration() const
00236 {
00237 return duration;
00238 }
00239
00240 inline void GLLineTrailRenderer::init(const Particle& particle,float age) const
00241 {
00242
00243 const Vector3D& pos = particle.position();
00244 float r = particle.getR();
00245 float g = particle.getG();
00246 float b = particle.getB();
00247 float a = particle.getParamCurrentValue(PARAM_ALPHA);
00248
00249
00250 for (size_t i = 0; i < nbSamples + 2; ++i)
00251 {
00252 *(vertexIterator++) = pos.x;
00253 *(vertexIterator++) = pos.y;
00254 *(vertexIterator++) = pos.z;
00255 }
00256
00257
00258
00259 *(colorIterator++) = degeneratedR;
00260 *(colorIterator++) = degeneratedG;
00261 *(colorIterator++) = degeneratedB;
00262 *(colorIterator++) = degeneratedA;
00263
00264 for (size_t i = 0; i < nbSamples; ++i)
00265 {
00266 *(colorIterator++) = r;
00267 *(colorIterator++) = g;
00268 *(colorIterator++) = b;
00269 *(colorIterator++) = a;
00270 }
00271
00272
00273 *(colorIterator++) = degeneratedR;
00274 *(colorIterator++) = degeneratedG;
00275 *(colorIterator++) = degeneratedB;
00276 *(colorIterator++) = degeneratedA;
00277
00278
00279 for (size_t i = 0; i < nbSamples; ++i)
00280 *(valueIterator++) = age;
00281 }
00282 }}
00283
00284 #endif