From 2f74d1fb110bc00c285fa650560c25fb2d0a52ae Mon Sep 17 00:00:00 2001 From: psperl Date: Sun, 22 Jun 2008 16:19:54 +0000 Subject: [PATCH] Removed some state from renderitems git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@1046 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/Renderable.cpp | 23 +++++++++++++---------- src/projectM-engine/Renderable.hpp | 16 +++++++++++----- src/projectM-engine/Renderer.cpp | 7 +++++-- src/projectM-engine/Renderer.hpp | 1 + 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/projectM-engine/Renderable.cpp b/src/projectM-engine/Renderable.cpp index c3d24f07a..cd2304f5a 100644 --- a/src/projectM-engine/Renderable.cpp +++ b/src/projectM-engine/Renderable.cpp @@ -15,6 +15,9 @@ #include "Renderable.hpp" #include +RenderContext::RenderContext() + :texsize(512), aspectRatio(1), aspectCorrect(false){}; + Shape::Shape() { std::string imageUrl = ""; @@ -50,7 +53,7 @@ Shape::Shape() } -void Shape::Draw() +void Shape::Draw(RenderContext &context) { float xval, yval; @@ -74,7 +77,7 @@ void Shape::Draw() if (tex != 0) { glBindTexture(GL_TEXTURE_2D, tex); - aspectRatio=1.0; + context.aspectRatio=1.0; } } @@ -110,9 +113,9 @@ void Shape::Draw() colors[i][3]=a2; t = (i-1)/(float) sides; - tex[i][0] =0.5f + 0.5f*cosf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)*(aspectCorrect ? aspectRatio : 1.0)/ tex_zoom; + tex[i][0] =0.5f + 0.5f*cosf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)/ tex_zoom; tex[i][1] = 0.5f + 0.5f*sinf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)/ tex_zoom; - points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(aspectCorrect ? aspectRatio : 1.0)+xval; + points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval; points[i][1]=temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval; @@ -169,7 +172,7 @@ void Shape::Draw() colors[i][2]=b2; colors[i][3]=a2; t = (i-1)/(float) sides; - points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(aspectCorrect ? aspectRatio : 1.0)+xval; + points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval; points[i][1]=temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval; } @@ -182,7 +185,7 @@ void Shape::Draw() //draw first n-1 triangular pieces } - if (thickOutline==1) glLineWidth(texsize < 512 ? 1 : 2*texsize/512); + if (thickOutline==1) glLineWidth(context.texsize < 512 ? 1 : 2*context.texsize/512); glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -194,7 +197,7 @@ void Shape::Draw() for ( int i=0;i< sides;i++) { t = (i-1)/(float) sides; - points[i][0]= temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(aspectCorrect ? aspectRatio : 1.0)+xval; + points[i][0]= temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval; points[i][1]= temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval; } @@ -202,14 +205,14 @@ void Shape::Draw() glVertexPointer(2,GL_FLOAT,0,points); glDrawArrays(GL_LINE_LOOP,0,sides); - if (thickOutline==1) glLineWidth(texsize < 512 ? 1 : texsize/512); + if (thickOutline==1) glLineWidth(context.texsize < 512 ? 1 : context.texsize/512); } -void MotionVectors::Draw() +void MotionVectors::Draw(RenderContext &context) { glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); @@ -247,7 +250,7 @@ void MotionVectors::Draw() } } -void Border::Draw() +void Border::Draw(RenderContext &context) { glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); diff --git a/src/projectM-engine/Renderable.hpp b/src/projectM-engine/Renderable.hpp index dde7d6479..ae4f94979 100644 --- a/src/projectM-engine/Renderable.hpp +++ b/src/projectM-engine/Renderable.hpp @@ -4,14 +4,20 @@ #include #include "TextureManager.hpp" -class RenderItem +class RenderContext { public: int texsize; float aspectRatio; bool aspectCorrect; - virtual void Draw() = 0; + RenderContext(); +}; + +class RenderItem +{ +public: + virtual void Draw(RenderContext &context) = 0; }; class TexturedItem @@ -54,7 +60,7 @@ public: float border_a; /* alpha color value */ Shape(); - void Draw(); + void Draw(RenderContext &context); }; class Text : RenderItem @@ -74,7 +80,7 @@ public: float x_offset; float y_offset; - void Draw(); + void Draw(RenderContext &context); MotionVectors(){} }; @@ -93,7 +99,7 @@ public: float inner_b; float inner_a; - void Draw(); + void Draw(RenderContext &context); Border(){} }; #endif diff --git a/src/projectM-engine/Renderer.cpp b/src/projectM-engine/Renderer.cpp index 4acfd3b9c..8650a9d08 100644 --- a/src/projectM-engine/Renderer.cpp +++ b/src/projectM-engine/Renderer.cpp @@ -149,9 +149,12 @@ void Renderer::RenderFrame(Pipeline* pipeline) Interpolation(pipeline); + renderContext.texsize = texsize; + renderContext.aspectCorrect = correction; + renderContext.aspectRatio = aspect; for (vector::iterator pos = pipeline->drawables.begin(); pos != pipeline->drawables.end(); ++pos) - (*pos)->Draw(); + (*pos)->Draw(renderContext); /** Restore original view state */ glMatrixMode( GL_MODELVIEW ); @@ -1842,7 +1845,7 @@ void Renderer::CompositeOutput(Pipeline* pipeline) glDisableClientState(GL_TEXTURE_COORD_ARRAY); for (vector::iterator pos = pipeline->compositeDrawables.begin(); pos != pipeline->compositeDrawables.end(); ++pos) - (*pos)->Draw(); + (*pos)->Draw(renderContext); } diff --git a/src/projectM-engine/Renderer.hpp b/src/projectM-engine/Renderer.hpp index 0a0434e43..92e733b38 100644 --- a/src/projectM-engine/Renderer.hpp +++ b/src/projectM-engine/Renderer.hpp @@ -90,6 +90,7 @@ private: BeatDetect *beatDetect; TextureManager *textureManager; static Pipeline* currentPipe; + RenderContext renderContext; //per pixel equation variables std::string m_presetName;