diff --git a/src/libprojectM/BuiltinParams.cpp b/src/libprojectM/BuiltinParams.cpp index e59b5c400..8889de539 100644 --- a/src/libprojectM/BuiltinParams.cpp +++ b/src/libprojectM/BuiltinParams.cpp @@ -332,13 +332,13 @@ int BuiltinParams::load_all_builtin_param(const PresetInputs & presetInputs, Pre load_builtin_param_float("sy", (void*)&presetOutputs.sy, presetOutputs.sy_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("b1n", (void*)&presetOutputs.warpShader.blur1n, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); - load_builtin_param_float("b2n", (void*)&presetOutputs.warpShader.blur2n, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); - load_builtin_param_float("b3n", (void*)&presetOutputs.warpShader.blur3n, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); - load_builtin_param_float("b1x", (void*)&presetOutputs.warpShader.blur1x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); - load_builtin_param_float("b2x", (void*)&presetOutputs.warpShader.blur2x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); - load_builtin_param_float("b3x", (void*)&presetOutputs.warpShader.blur3x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); - load_builtin_param_float("b1ed", (void*)&presetOutputs.warpShader.blur1ed, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b1n", (void*)&presetOutputs.blur1n, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b2n", (void*)&presetOutputs.blur2n, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b3n", (void*)&presetOutputs.blur3n, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b1x", (void*)&presetOutputs.blur1x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b2x", (void*)&presetOutputs.blur2x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b3x", (void*)&presetOutputs.blur3x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); + load_builtin_param_float("b1ed", (void*)&presetOutputs.blur1ed, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); load_builtin_param_float("wave_r", (void*)&presetOutputs.wave.r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); load_builtin_param_float("wave_g", (void*)&presetOutputs.wave.g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); @@ -396,38 +396,38 @@ int BuiltinParams::load_all_builtin_param(const PresetInputs & presetInputs, Pre load_builtin_param_float("rad", (void*)&presetInputs.rad_per_pixel, presetInputs.rad_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q1", (void*)&presetOutputs.q1, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q2", (void*)&presetOutputs.q2, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q3", (void*)&presetOutputs.q3, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q4", (void*)&presetOutputs.q4, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q5", (void*)&presetOutputs.q5, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q6", (void*)&presetOutputs.q6, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q7", (void*)&presetOutputs.q7, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q8", (void*)&presetOutputs.q8, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q9", (void*)&presetOutputs.q9, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q10", (void*)&presetOutputs.q10, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q11", (void*)&presetOutputs.q11, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q12", (void*)&presetOutputs.q12, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q13", (void*)&presetOutputs.q13, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q14", (void*)&presetOutputs.q14, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q15", (void*)&presetOutputs.q15, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q16", (void*)&presetOutputs.q16, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q17", (void*)&presetOutputs.q17, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q18", (void*)&presetOutputs.q18, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q19", (void*)&presetOutputs.q19, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q20", (void*)&presetOutputs.q20, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q21", (void*)&presetOutputs.q21, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q22", (void*)&presetOutputs.q22, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q23", (void*)&presetOutputs.q23, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q24", (void*)&presetOutputs.q24, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q25", (void*)&presetOutputs.q25, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q26", (void*)&presetOutputs.q26, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q27", (void*)&presetOutputs.q27, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q28", (void*)&presetOutputs.q28, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q29", (void*)&presetOutputs.q29, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q30", (void*)&presetOutputs.q30, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q31", (void*)&presetOutputs.q31, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("q32", (void*)&presetOutputs.q32, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q1", (void*)&presetOutputs.q[0], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q2", (void*)&presetOutputs.q[1], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q3", (void*)&presetOutputs.q[2], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q4", (void*)&presetOutputs.q[3], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q5", (void*)&presetOutputs.q[4], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q6", (void*)&presetOutputs.q[5], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q7", (void*)&presetOutputs.q[6], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q8", (void*)&presetOutputs.q[7], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q9", (void*)&presetOutputs.q[8], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q10", (void*)&presetOutputs.q[6], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q11", (void*)&presetOutputs.q[10], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q12", (void*)&presetOutputs.q[11], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q13", (void*)&presetOutputs.q[12], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q14", (void*)&presetOutputs.q[13], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q15", (void*)&presetOutputs.q[14], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q16", (void*)&presetOutputs.q[15], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q17", (void*)&presetOutputs.q[16], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q18", (void*)&presetOutputs.q[17], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q19", (void*)&presetOutputs.q[18], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q20", (void*)&presetOutputs.q[19], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q21", (void*)&presetOutputs.q[20], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q22", (void*)&presetOutputs.q[21], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q23", (void*)&presetOutputs.q[22], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q24", (void*)&presetOutputs.q[23], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q25", (void*)&presetOutputs.q[24], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q26", (void*)&presetOutputs.q[25], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q27", (void*)&presetOutputs.q[26], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q28", (void*)&presetOutputs.q[27], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q29", (void*)&presetOutputs.q[28], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q30", (void*)&presetOutputs.q[29], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q31", (void*)&presetOutputs.q[30], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); + load_builtin_param_float("q32", (void*)&presetOutputs.q[31], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); //param = Param::new_param_string ( "imageurl", P_FLAG_NONE, &this->imageUrl); diff --git a/src/libprojectM/Pipeline.cpp b/src/libprojectM/Pipeline.cpp index 7d32c6f12..e442d0dc3 100644 --- a/src/libprojectM/Pipeline.cpp +++ b/src/libprojectM/Pipeline.cpp @@ -5,8 +5,45 @@ * Author: pete */ #include "Pipeline.hpp" +#include "wipemalloc.h" + +Pipeline::Pipeline() : staticPerPixel(false),gx(0),gy(0),blur1n(1), blur2n(1), blur3n(1), +blur1x(1), blur2x(1), blur3x(1), +blur1ed(1){} + +void Pipeline::setStaticPerPixel(int gx, int gy) +{ + staticPerPixel = true; + this->gx = gx; + this->gy = gy; + + this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) ); + for ( int x = 0; x < gx; x++ ) + { + this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) ); + } + this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) ); + for ( int x = 0; x < gx; x++ ) + { + this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) ); + } + +} + +Pipeline::~Pipeline() +{ +if (staticPerPixel) +{ + for ( int x = 0; x < this->gx; x++ ) + { + free(this->x_mesh[x]); + free(this->y_mesh[x]); + } + free(x_mesh); + free(y_mesh); +} +} -Pipeline::Pipeline() {} void Pipeline::Render(const BeatDetect &music, const PipelineContext &context){} Point Pipeline::PerPixel(Point p, const PerPixelContext context) {return p;} diff --git a/src/libprojectM/Pipeline.hpp b/src/libprojectM/Pipeline.hpp index ea6d4ed90..1e0ebcfac 100644 --- a/src/libprojectM/Pipeline.hpp +++ b/src/libprojectM/Pipeline.hpp @@ -9,14 +9,38 @@ #include "PipelineContext.hpp" #include "Shader.hpp" - +//This class is the input to projectM's renderer +// +//Most implemenatations should implement PerPixel in order to get multi-threaded +//dynamic PerPixel equations. If you MUST (ie Milkdrop compatability), you can use the +//setStaticPerPixel function and fill in x_mesh and y_mesh yourself. class Pipeline { public: + //static per pixel stuff + bool staticPerPixel; + int gx; + int gy; + + float** x_mesh; + float** y_mesh; + //end static per pixel + bool textureWrap; float screenDecay; + //variables passed to pixel shaders + float q[32]; + + //blur settings n=bias x=scale + float blur1n; + float blur2n; + float blur3n; + float blur1x; + float blur2x; + float blur3x; + float blur1ed; Shader warpShader; Shader compositeShader; @@ -25,6 +49,8 @@ public: std::vector compositeDrawables; Pipeline(); + void setStaticPerPixel(int gx, int gy); + virtual ~Pipeline(); virtual void Render(const BeatDetect &music, const PipelineContext &context); virtual Point PerPixel(Point p, const PerPixelContext context); }; diff --git a/src/libprojectM/Preset.hpp b/src/libprojectM/Preset.hpp index 39a8b881b..fb8df2701 100644 --- a/src/libprojectM/Preset.hpp +++ b/src/libprojectM/Preset.hpp @@ -83,12 +83,12 @@ public: /// @bug encapsulate BuiltinParams builtinParams; - + /// Used by parser to find/create custom waves and shapes. May be refactored template static CustomObject * find_custom_object(int id, std::vector & customObjects); - + int per_pixel_eqn_string_index; int per_frame_eqn_string_index; int per_frame_init_eqn_string_index; @@ -96,13 +96,13 @@ public: int per_frame_eqn_count, per_frame_init_eqn_count; - + /// Used by parser /// @bug refactor int add_per_pixel_eqn( char *name, GenExpr *gen_expr ); /// Accessor method to retrieve the absolute file path of the loaded preset - /// \returns a file path string + /// \returns a file path string std::string absoluteFilePath() const { return m_absoluteFilePath; @@ -128,7 +128,7 @@ public: { m_presetName = theValue; } - + /// Gets the descriptive name for this preset (typically the file name) /// \returns the name of the preset @@ -139,7 +139,7 @@ public: /// @bug encapsulate - + PresetOutputs::cwave_container customWaves; PresetOutputs::cshape_container customShapes; @@ -198,18 +198,18 @@ void Preset::transfer_q_variables(std::vector & customObjects) CustomObject * custom_object; for (typename std::vector::iterator pos = customObjects.begin(); pos != customObjects.end();++pos) { - + custom_object = *pos; - custom_object->q1 = m_presetOutputs.q1; - custom_object->q2 = m_presetOutputs.q2; - custom_object->q3 = m_presetOutputs.q3; - custom_object->q4 = m_presetOutputs.q4; - custom_object->q5 = m_presetOutputs.q5; - custom_object->q6 = m_presetOutputs.q6; - custom_object->q7 = m_presetOutputs.q7; - custom_object->q8 = m_presetOutputs.q8; + custom_object->q1 = m_presetOutputs.q[0]; + custom_object->q2 = m_presetOutputs.q[1]; + custom_object->q3 = m_presetOutputs.q[2]; + custom_object->q4 = m_presetOutputs.q[3]; + custom_object->q5 = m_presetOutputs.q[4]; + custom_object->q6 = m_presetOutputs.q[5]; + custom_object->q7 = m_presetOutputs.q[6]; + custom_object->q8 = m_presetOutputs.q[7]; } - + } diff --git a/src/libprojectM/PresetFrameIO.cpp b/src/libprojectM/PresetFrameIO.cpp index 0b348bef4..d839e4010 100644 --- a/src/libprojectM/PresetFrameIO.cpp +++ b/src/libprojectM/PresetFrameIO.cpp @@ -20,7 +20,7 @@ void PresetInputs::Initialize ( int gx, int gy ) this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) ); } this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) ); - for ( x = 0; x < gx; x++ ) + for ( x = 0; x y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) ); } @@ -80,10 +80,6 @@ PresetOutputs::~PresetOutputs() for ( int x = 0; x < this->gx; x++ ) { - - - free(this->x_mesh[x]); - free(this->y_mesh[x]); free(this->sx_mesh[x]); free(this->sy_mesh[x]); free(this->dy_mesh[x]); @@ -95,11 +91,10 @@ PresetOutputs::~PresetOutputs() free(this->zoom_mesh[x]); free(this->zoomexp_mesh[x]); free(this->rot_mesh[x]); - + free(this->origx2[x]); + free(this->origy2[x]); } - free(this->x_mesh); - free(this->y_mesh); free(this->sx_mesh); free(this->sy_mesh); free(this->dy_mesh); @@ -110,6 +105,9 @@ PresetOutputs::~PresetOutputs() free(this->zoom_mesh); free(this->zoomexp_mesh); free(this->rot_mesh); + free(this->origx2); + free(this->origy2); + } void PresetOutputs::PrepareToRender() @@ -150,12 +148,109 @@ void PresetOutputs::PrepareToRender() compositeDrawables.push_back(&invert); } + +void PresetOutputs::PerPixelMath(PresetInputs &presetInputs) +{ + + int x, y; + float fZoom2, fZoom2Inv; + + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + fZoom2 = powf(this->zoom_mesh[x][y], powf(this->zoomexp_mesh[x][y], + presetInputs.rad_mesh[x][y] * 2.0f - 1.0f)); + fZoom2Inv = 1.0f / fZoom2; + this->x_mesh[x][y] = this->origx2[x][y] * 0.5f * fZoom2Inv + 0.5f; + this->y_mesh[x][y] = this->origy2[x][y] * 0.5f * fZoom2Inv + 0.5f; + } + } + + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + this->x_mesh[x][y] = (this->x_mesh[x][y] - this->cx_mesh[x][y]) + / this->sx_mesh[x][y] + this->cx_mesh[x][y]; + } + } + + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + this->y_mesh[x][y] = (this->y_mesh[x][y] - this->cy_mesh[x][y]) + / this->sy_mesh[x][y] + this->cy_mesh[x][y]; + } + } + + float fWarpTime = presetInputs.time * this->fWarpAnimSpeed; + float fWarpScaleInv = 1.0f / this->fWarpScale; + float f[4]; + f[0] = 11.68f + 4.0f * cosf(fWarpTime * 1.413f + 10); + f[1] = 8.77f + 3.0f * cosf(fWarpTime * 1.113f + 7); + f[2] = 10.54f + 3.0f * cosf(fWarpTime * 1.233f + 3); + f[3] = 11.49f + 4.0f * cosf(fWarpTime * 0.933f + 5); + + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + this->x_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.333f + + fWarpScaleInv * (this->origx2[x][y] * f[0] - this->origy2[x][y] * f[3])); + this->y_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.375f + - fWarpScaleInv * (this->origx2[x][y] * f[2] + this->origy2[x][y] * f[1])); + this->x_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.753f + - fWarpScaleInv * (this->origx2[x][y] * f[1] - this->origy2[x][y] * f[2])); + this->y_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.825f + + fWarpScaleInv * (this->origx2[x][y] * f[0] + this->origy2[x][y] * f[3])); + } + } + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + float u2 = this->x_mesh[x][y] - this->cx_mesh[x][y]; + float v2 = this->y_mesh[x][y] - this->cy_mesh[x][y]; + + float cos_rot = cosf(this->rot_mesh[x][y]); + float sin_rot = sinf(this->rot_mesh[x][y]); + + this->x_mesh[x][y] = u2 * cos_rot - v2 * sin_rot + this->cx_mesh[x][y]; + this->y_mesh[x][y] = u2 * sin_rot + v2 * cos_rot + this->cy_mesh[x][y]; + + } + } + + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + this->x_mesh[x][y] -= this->dx_mesh[x][y]; + } + } + + for (x = 0; x < presetInputs.gx; x++) + { + for (y = 0; y < presetInputs.gy; y++) + { + this->y_mesh[x][y] -= this->dy_mesh[x][y]; + } + } + +} + + void PresetOutputs::Initialize ( int gx, int gy ) { assert(gx > 0); this->gx = gx; this->gy= gy; + + setStaticPerPixel(gx,gy); + assert(this->gx > 0); int x; this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) ); @@ -219,8 +314,29 @@ void PresetOutputs::Initialize ( int gx, int gy ) { this->warp_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) ); } + this->origx2 = (float **) wipemalloc(gx * sizeof(float *)); + for (x = 0; x < gx; x++) + { + this->origx2[x] = (float *) wipemalloc(gy * sizeof(float)); + } + this->origy2 = (float **) wipemalloc(gx * sizeof(float *)); + for (x = 0; x < gx; x++) + { + this->origy2[x] = (float *) wipemalloc(gy * sizeof(float)); + } + //initialize reference grid values + for (x = 0; x < gx; x++) + { + for (int y = 0; y < gy; y++) + { + float origx = x / (float) (gx - 1); + float origy = -((y / (float) (gy - 1)) - 1); + this->origx2[x][y] = (origx - .5) * 2; + this->origy2[x][y] = (origy - .5) * 2; + } + } } PresetInputs::~PresetInputs() diff --git a/src/libprojectM/PresetFrameIO.hpp b/src/libprojectM/PresetFrameIO.hpp index 099e058a2..0e9b9ee26 100644 --- a/src/libprojectM/PresetFrameIO.hpp +++ b/src/libprojectM/PresetFrameIO.hpp @@ -9,123 +9,6 @@ #include "VideoEcho.hpp" -/// Container class for all preset writeable engine variables. This is the important glue -/// between the presets and renderer to facilitate smooth preset switching -/// Every preset object needs a reference to one of these. -class PresetOutputs : public Pipeline{ -public: - typedef std::vector cwave_container; - typedef std::vector cshape_container; - - cwave_container customWaves; - cshape_container customShapes; - - void Initialize(int gx, int gy); - PresetOutputs(); - ~PresetOutputs(); - void PrepareToRender(); - /* PER FRAME VARIABLES BEGIN */ - - float zoom; - float zoomexp; - float rot; - float warp; - - float sx; - float sy; - float dx; - float dy; - float cx; - float cy; - - VideoEcho videoEcho; - - MilkdropWaveform wave; - Border border; - MotionVectors mv; - DarkenCenter darkenCenter; - - Brighten brighten; - Darken darken; - Invert invert; - Solarize solarize; - - - int gy,gx; - /* PER_FRAME VARIABLES END */ - - float fRating; - float fGammaAdj; - - bool bDarkenCenter; - bool bRedBlueStereo; - bool bBrighten; - bool bDarken; - bool bSolarize; - bool bInvert; - bool bMotionVectorsOn; - - float fWarpAnimSpeed; - float fWarpScale; - float fShader; - - /* Q VARIABLES START */ - - float q1; - float q2; - float q3; - float q4; - float q5; - float q6; - float q7; - float q8; - float q9; - float q10; - float q11; - float q12; - float q13; - float q14; - float q15; - float q16; - float q17; - float q18; - float q19; - float q20; - float q21; - float q22; - float q23; - float q24; - float q25; - float q26; - float q27; - float q28; - float q29; - float q30; - float q31; - float q32; - - - - /* Q VARIABLES END */ - - float **zoom_mesh; - float **zoomexp_mesh; - float **rot_mesh; - - float **sx_mesh; - float **sy_mesh; - float **dx_mesh; - float **dy_mesh; - float **cx_mesh; - float **cy_mesh; - float **warp_mesh; - - - float **x_mesh; - float **y_mesh; - -}; - /// Container for all *read only* engine variables a preset requires to /// evaluate milkdrop equations. Every preset object needs a reference to one of these. class PresetInputs : public PipelineContext{ @@ -170,4 +53,84 @@ public: void Initialize(int gx, int gy); }; + +/// Container class for all preset writeable engine variables. This is the important glue +/// between the presets and renderer to facilitate smooth preset switching +/// Every preset object needs a reference to one of these. +class PresetOutputs : public Pipeline{ +public: + typedef std::vector cwave_container; + typedef std::vector cshape_container; + + cwave_container customWaves; + cshape_container customShapes; + + void Initialize(int gx, int gy); + PresetOutputs(); + ~PresetOutputs(); + void PrepareToRender(); + void PerPixelMath( PresetInputs &presetInputs); + /* PER FRAME VARIABLES BEGIN */ + + float zoom; + float zoomexp; + float rot; + float warp; + + float sx; + float sy; + float dx; + float dy; + float cx; + float cy; + + VideoEcho videoEcho; + + MilkdropWaveform wave; + Border border; + MotionVectors mv; + DarkenCenter darkenCenter; + + Brighten brighten; + Darken darken; + Invert invert; + Solarize solarize; + + + int gy,gx; + /* PER_FRAME VARIABLES END */ + + float fRating; + float fGammaAdj; + + bool bDarkenCenter; + bool bRedBlueStereo; + bool bBrighten; + bool bDarken; + bool bSolarize; + bool bInvert; + bool bMotionVectorsOn; + + float fWarpAnimSpeed; + float fWarpScale; + float fShader; + + float **zoom_mesh; + float **zoomexp_mesh; + float **rot_mesh; + + float **sx_mesh; + float **sy_mesh; + float **dx_mesh; + float **dy_mesh; + float **cx_mesh; + float **cy_mesh; + float **warp_mesh; + + float **origx2; //original mesh + float **origy2; + +}; + + #endif diff --git a/src/libprojectM/Renderer.cpp b/src/libprojectM/Renderer.cpp index 83bf6933d..0314b5645 100644 --- a/src/libprojectM/Renderer.cpp +++ b/src/libprojectM/Renderer.cpp @@ -65,45 +65,24 @@ Renderer::Renderer(int width, int height, int gx, int gy, int texsize, BeatDetec #endif /** USE_FTGL */ - this->gridx = (float **) wipemalloc(gx * sizeof(float *)); - for (x = 0; x < gx; x++) + int size = mesh.width * 2; + p = ( float ** ) wipemalloc ( size * sizeof ( float * ) ); + for ( int x = 0; x < size; x++ ) { - this->gridx[x] = (float *) wipemalloc(gy * sizeof(float)); + p[x] = ( float * ) wipemalloc ( 2 * sizeof ( float ) ); } - this->gridy = (float **) wipemalloc(gx * sizeof(float *)); - for (x = 0; x < gx; x++) + t = ( float ** ) wipemalloc ( size * sizeof ( float * ) ); + for (int x = 0; x < size; x++ ) { - this->gridy[x] = (float *) wipemalloc(gy * sizeof(float)); + t[x] = ( float * ) wipemalloc ( 2 * sizeof ( float ) ); } - this->origx2 = (float **) wipemalloc(gx * sizeof(float *)); - for (x = 0; x < gx; x++) - { - this->origx2[x] = (float *) wipemalloc(gy * sizeof(float)); - } - this->origy2 = (float **) wipemalloc(gx * sizeof(float *)); - for (x = 0; x < gx; x++) - { - this->origy2[x] = (float *) wipemalloc(gy * sizeof(float)); - } - //initialize reference grid values - for (x = 0; x < gx; x++) - { - for (y = 0; y < gy; y++) - { - float origx = x / (float) (gx - 1); - float origy = -((y / (float) (gy - 1)) - 1); - this->gridx[x][y] = origx; - this->gridy[x][y] = origy; - this->origx2[x][y] = (origx - .5) * 2; - this->origy2[x][y] = (origy - .5) * 2; - } - } + #ifdef USE_CG - shaderEngine.SetParams(renderTarget->texsize, renderTarget->textureID[1], aspect, beatDetect, textureManager); + shaderEngine.setParams(renderTarget->texsize, renderTarget->textureID[1], aspect, beatDetect, textureManager); #endif } @@ -130,7 +109,7 @@ void Renderer::ResetTextures() textureManager->Preload(); } -void Renderer::SetupPass1(const Pipeline* pipeline, const PipelineContext &pipelineContext) +void Renderer::SetupPass1(const Pipeline &pipeline, const PipelineContext &pipelineContext) { //glMatrixMode(GL_PROJECTION); //glPushMatrix(); @@ -165,7 +144,7 @@ void Renderer::SetupPass1(const Pipeline* pipeline, const PipelineContext &pipel #endif } -void Renderer::RenderItems(const Pipeline* pipeline, const PipelineContext &pipelineContext) +void Renderer::RenderItems(const Pipeline &pipeline, const PipelineContext &pipelineContext) { renderContext.time = pipelineContext.time; renderContext.texsize = texsize; @@ -174,7 +153,7 @@ void Renderer::RenderItems(const Pipeline* pipeline, const PipelineContext &pipe renderContext.textureManager = textureManager; renderContext.beatDetect = beatDetect; - for (std::vector::const_iterator pos = pipeline->drawables.begin(); pos != pipeline->drawables.end(); ++pos) + for (std::vector::const_iterator pos = pipeline.drawables.begin(); pos != pipeline.drawables.end(); ++pos) (*pos)->Draw(renderContext); } @@ -192,7 +171,7 @@ void Renderer::FinishPass1() } -void Renderer::Pass2(const Pipeline *pipeline, const PipelineContext &pipelineContext) +void Renderer::Pass2(const Pipeline &pipeline, const PipelineContext &pipelineContext) { //BEGIN PASS 2 // @@ -251,13 +230,13 @@ void Renderer::Pass2(const Pipeline *pipeline, const PipelineContext &pipelineCo #endif } -void Renderer::RenderFrame(const Pipeline* pipeline, const PipelineContext &pipelineContext) +void Renderer::RenderFrame(const Pipeline &pipeline, const PipelineContext &pipelineContext) { SetupPass1(pipeline, pipelineContext); #ifdef USE_CG - shaderEngine.enableShader(currentPipe->warpShader, pipeline, &pipelineContext); + shaderEngine.enableShader(currentPipe->warpShader, pipeline, pipelineContext); #endif Interpolation(pipeline); #ifdef USE_CG @@ -268,104 +247,27 @@ void Renderer::RenderFrame(const Pipeline* pipeline, const PipelineContext &pipe FinishPass1(); Pass2(pipeline, pipelineContext); } -void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs) +void Renderer::RenderFrame(PresetOutputs &presetOutputs, const PipelineContext &pipelineContext) { - SetupPass1(presetOutputs, *presetInputs); + SetupPass1(presetOutputs, pipelineContext); #ifdef USE_CG - shaderEngine.SetupCgQVariables(presetOutputs->warpShader, *presetOutputs); - shaderEngine.enableShader(presetOutputs->warpShader, presetOutputs, presetInputs); + shaderEngine.enableShader(presetOutputs.warpShader, presetOutputs, pipelineContext); #endif - Interpolation(presetOutputs, presetInputs); + Interpolation(presetOutputs); #ifdef USE_CG shaderEngine.disableShader(); #endif - RenderItems(presetOutputs, *presetInputs); + RenderItems(presetOutputs, pipelineContext); FinishPass1(); -#ifdef USE_CG - shaderEngine.SetupCgQVariables(presetOutputs->compositeShader, *presetOutputs); -#endif - Pass2(presetOutputs, *presetInputs); + Pass2(presetOutputs, pipelineContext); } -void Renderer::Interpolation(PresetOutputs *presetOutputs, PresetInputs *presetInputs) -{ - if (!presetOutputs->warpShader.enabled) - { - if (this->renderTarget->useFBO) - glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[1]); - else - glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[0]); - - //Texture wrapping( clamp vs. wrap) - if (presetOutputs->textureWrap == 0) - { -#ifdef USE_GLES1 - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); -#else - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); -#endif - } - else - { - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } - } - - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - - glBlendFunc(GL_SRC_ALPHA, GL_ZERO); - - glColor4f(1.0, 1.0, 1.0, presetOutputs->screenDecay); - - glEnable(GL_TEXTURE_2D); - - int size = presetInputs->gy; - - float p[size * 2][2]; - float t[size * 2][2]; - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, p); - glTexCoordPointer(2, GL_FLOAT, 0, t); - - for (int x = 0; x < presetInputs->gx - 1; x++) - { - for (int y = 0; y < presetInputs->gy; y++) - { - t[y * 2][0] = presetOutputs->x_mesh[x][y]; - t[y * 2][1] = presetOutputs->y_mesh[x][y]; - - p[y * 2][0] = this->gridx[x][y]; - p[y * 2][1] = this->gridy[x][y]; - - t[(y * 2) + 1][0] = presetOutputs->x_mesh[x + 1][y]; - t[(y * 2) + 1][1] = presetOutputs->y_mesh[x + 1][y]; - - p[(y * 2) + 1][0] = this->gridx[x + 1][y]; - p[(y * 2) + 1][1] = this->gridy[x + 1][y]; - - } - glDrawArrays(GL_TRIANGLE_STRIP, 0, size * 2); - } - - glDisable(GL_TEXTURE_2D); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - -} - -void Renderer::Interpolation(const Pipeline *pipeline) +void Renderer::Interpolation(const Pipeline &pipeline) { if (this->renderTarget->useFBO) glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[1]); @@ -373,7 +275,7 @@ void Renderer::Interpolation(const Pipeline *pipeline) glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[0]); //Texture wrapping( clamp vs. wrap) - if (pipeline->textureWrap == 0) + if (pipeline.textureWrap == 0) { #ifdef USE_GLES1 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -394,25 +296,51 @@ void Renderer::Interpolation(const Pipeline *pipeline) glBlendFunc(GL_SRC_ALPHA, GL_ZERO); - glColor4f(1.0, 1.0, 1.0, pipeline->screenDecay); + glColor4f(1.0, 1.0, 1.0, pipeline.screenDecay); glEnable(GL_TEXTURE_2D); - int size = mesh.width * 2; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); - float p[size][2]; - float t[size][2]; + float p2[mesh.width * 2][2]; + float t2[mesh.width * 2][2]; - glVertexPointer(2, GL_FLOAT, 0, p); - glTexCoordPointer(2, GL_FLOAT, 0, t); + glVertexPointer(2, GL_FLOAT, 0, p2); + glTexCoordPointer(2, GL_FLOAT, 0, t2); - mesh.Reset(); - omptl::transform(mesh.p.begin(), mesh.p.end(), mesh.identity.begin(), mesh.p.begin(), &Renderer::PerPixel); + + if (pipeline.staticPerPixel) + { + for (int j = 0; j < mesh.height - 1; j++) + { + for (int i = 0; i < mesh.width; i++) + { + t2[i * 2][0] = pipeline.x_mesh[i][j]; + t2[i * 2][1] = pipeline.y_mesh[i][j]; + + t2[(i * 2) + 1][0] = pipeline.x_mesh[i][j+1]; + t2[(i * 2) + 1][1] = pipeline.y_mesh[i][j+1]; + + int index = j * mesh.width + i; + int index2 = (j + 1) * mesh.width + i; + + p2[i * 2][0] = mesh.identity[index].x; + p2[i * 2][1] = mesh.identity[index].y; + + p2[(i * 2) + 1][0] = mesh.identity[index2].x; + p2[(i * 2) + 1][1] = mesh.identity[index2].y; + } + glDrawArrays(GL_TRIANGLE_STRIP, 0, mesh.width * 2); + } + } + else + { + mesh.Reset(); + omptl::transform(mesh.p.begin(), mesh.p.end(), mesh.identity.begin(), mesh.p.begin(), &Renderer::PerPixel); for (int j = 0; j < mesh.height - 1; j++) { @@ -421,19 +349,22 @@ void Renderer::Interpolation(const Pipeline *pipeline) int index = j * mesh.width + i; int index2 = (j + 1) * mesh.width + i; - t[i * 2][0] = mesh.p[index].x; - t[i * 2][1] = mesh.p[index].y; - p[i * 2][0] = mesh.identity[index].x; - p[i * 2][1] = mesh.identity[index].y; + t2[i * 2][0] = mesh.p[index].x; + t2[i * 2][1] = mesh.p[index].y; + + t2[(i * 2) + 1][0] = mesh.p[index2].x; + t2[(i * 2) + 1][1] = mesh.p[index2].y; + + p2[i * 2][0] = mesh.identity[index].x; + p2[i * 2][1] = mesh.identity[index].y; + + p2[(i * 2) + 1][0] = mesh.identity[index2].x; + p2[(i * 2) + 1][1] = mesh.identity[index2].y; - t[(i * 2) + 1][0] = mesh.p[index2].x; - t[(i * 2) + 1][1] = mesh.p[index2].y; - p[(i * 2) + 1][0] = mesh.identity[index2].x; - p[(i * 2) + 1][1] = mesh.identity[index2].y; } - glDrawArrays(GL_TRIANGLE_STRIP, 0, size); + glDrawArrays(GL_TRIANGLE_STRIP, 0, mesh.width*2); + } } - glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -453,25 +384,15 @@ Renderer::~Renderer() //std::cerr << "grid assign end" << std::endl; - for (x = 0; x < mesh.width; x++) + + for (int x = 0;xgridx[x]); - free(this->gridy[x]); - free(this->origx2[x]); - free(this->origy2[x]); + free(p[x]); + free(t[x]); } - //std::cerr << "freeing grids" << std::endl; - free(this->origx2); - free(this->origy2); - free(this->gridx); - free(this->gridy); - - //std:cerr << "grid assign begin " << std::endl; - this->origx2 = NULL; - this->origy2 = NULL; - this->gridx = NULL; - this->gridy = NULL; + free(p); + free(t); #ifdef USE_FTGL // std::cerr << "freeing title fonts" << std::endl; @@ -486,98 +407,6 @@ Renderer::~Renderer() // std::cerr << "exiting destructor" << std::endl; } -void Renderer::PerPixelMath(PresetOutputs * presetOutputs, PresetInputs * presetInputs) -{ - - int x, y; - float fZoom2, fZoom2Inv; - - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - fZoom2 = powf(presetOutputs->zoom_mesh[x][y], powf(presetOutputs->zoomexp_mesh[x][y], - presetInputs->rad_mesh[x][y] * 2.0f - 1.0f)); - fZoom2Inv = 1.0f / fZoom2; - presetOutputs->x_mesh[x][y] = this->origx2[x][y] * 0.5f * fZoom2Inv + 0.5f; - presetOutputs->y_mesh[x][y] = this->origy2[x][y] * 0.5f * fZoom2Inv + 0.5f; - } - } - - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - presetOutputs->x_mesh[x][y] = (presetOutputs->x_mesh[x][y] - presetOutputs->cx_mesh[x][y]) - / presetOutputs->sx_mesh[x][y] + presetOutputs->cx_mesh[x][y]; - } - } - - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - presetOutputs->y_mesh[x][y] = (presetOutputs->y_mesh[x][y] - presetOutputs->cy_mesh[x][y]) - / presetOutputs->sy_mesh[x][y] + presetOutputs->cy_mesh[x][y]; - } - } - - float fWarpTime = presetInputs->time * presetOutputs->fWarpAnimSpeed; - float fWarpScaleInv = 1.0f / presetOutputs->fWarpScale; - float f[4]; - f[0] = 11.68f + 4.0f * cosf(fWarpTime * 1.413f + 10); - f[1] = 8.77f + 3.0f * cosf(fWarpTime * 1.113f + 7); - f[2] = 10.54f + 3.0f * cosf(fWarpTime * 1.233f + 3); - f[3] = 11.49f + 4.0f * cosf(fWarpTime * 0.933f + 5); - - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - presetOutputs->x_mesh[x][y] += presetOutputs->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.333f - + fWarpScaleInv * (this->origx2[x][y] * f[0] - this->origy2[x][y] * f[3])); - presetOutputs->y_mesh[x][y] += presetOutputs->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.375f - - fWarpScaleInv * (this->origx2[x][y] * f[2] + this->origy2[x][y] * f[1])); - presetOutputs->x_mesh[x][y] += presetOutputs->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.753f - - fWarpScaleInv * (this->origx2[x][y] * f[1] - this->origy2[x][y] * f[2])); - presetOutputs->y_mesh[x][y] += presetOutputs->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.825f - + fWarpScaleInv * (this->origx2[x][y] * f[0] + this->origy2[x][y] * f[3])); - } - } - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - float u2 = presetOutputs->x_mesh[x][y] - presetOutputs->cx_mesh[x][y]; - float v2 = presetOutputs->y_mesh[x][y] - presetOutputs->cy_mesh[x][y]; - - float cos_rot = cosf(presetOutputs->rot_mesh[x][y]); - float sin_rot = sinf(presetOutputs->rot_mesh[x][y]); - - presetOutputs->x_mesh[x][y] = u2 * cos_rot - v2 * sin_rot + presetOutputs->cx_mesh[x][y]; - presetOutputs->y_mesh[x][y] = u2 * sin_rot + v2 * cos_rot + presetOutputs->cy_mesh[x][y]; - - } - } - - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - presetOutputs->x_mesh[x][y] -= presetOutputs->dx_mesh[x][y]; - } - } - - for (x = 0; x < mesh.width; x++) - { - for (y = 0; y < mesh.height; y++) - { - presetOutputs->y_mesh[x][y] -= presetOutputs->dy_mesh[x][y]; - } - } - -} - void Renderer::reset(int w, int h) { aspect = (float) h / (float) w; @@ -904,7 +733,7 @@ void Renderer::draw_fps(float realfps) #endif /** USE_FTGL */ } -void Renderer::CompositeOutput(const Pipeline* pipeline, const PipelineContext &pipelineContext) +void Renderer::CompositeOutput(const Pipeline &pipeline, const PipelineContext &pipelineContext) { glMatrixMode(GL_TEXTURE); @@ -920,7 +749,7 @@ void Renderer::CompositeOutput(const Pipeline* pipeline, const PipelineContext & glEnable(GL_TEXTURE_2D); #ifdef USE_CG - shaderEngine.enableShader(currentPipe->compositeShader, pipeline, &pipelineContext); + shaderEngine.enableShader(currentPipe->compositeShader, pipeline, pipelineContext); #endif float tex[4][2] = @@ -955,8 +784,8 @@ void Renderer::CompositeOutput(const Pipeline* pipeline, const PipelineContext & shaderEngine.disableShader(); #endif - for (std::vector::const_iterator pos = pipeline->compositeDrawables.begin(); pos - != pipeline->compositeDrawables.end(); ++pos) + for (std::vector::const_iterator pos = pipeline.compositeDrawables.begin(); pos + != pipeline.compositeDrawables.end(); ++pos) ;//(*pos)->Draw(renderContext); } diff --git a/src/libprojectM/Renderer.hpp b/src/libprojectM/Renderer.hpp index ecdb0ccf3..cfd66922f 100644 --- a/src/libprojectM/Renderer.hpp +++ b/src/libprojectM/Renderer.hpp @@ -64,22 +64,15 @@ public: int drawtitle; int texsize; -#ifdef USE_CG - ShaderEngine shaderEngine; -#endif - - PerPixelMesh mesh; - - Renderer( int width, int height, int gx, int gy, int texsize, BeatDetect *beatDetect, std::string presetURL, std::string title_fontURL, std::string menu_fontURL); ~Renderer(); - void RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs); - void RenderFrame(const Pipeline *pipeline, const PipelineContext &pipelineContext); + void RenderFrame(PresetOutputs &PresetOutputs, const PipelineContext &pipelineContext); + void RenderFrame(const Pipeline &pipeline, const PipelineContext &pipelineContext); void ResetTextures(); void reset(int w, int h); GLuint initRenderToTexture(); - void PerPixelMath(PresetOutputs *presetOutputs, PresetInputs *presetInputs); + void SetPipeline(Pipeline &pipeline); @@ -95,22 +88,20 @@ public: private: + PerPixelMesh mesh; RenderTarget *renderTarget; BeatDetect *beatDetect; TextureManager *textureManager; static Pipeline* currentPipe; RenderContext renderContext; //per pixel equation variables - +#ifdef USE_CG + ShaderEngine shaderEngine; +#endif std::string m_presetName; - - float **gridx; //grid containing interpolated mesh - float **gridy; - float **origx2; //original mesh - float **origy2; - - + float** p; + float** t; int vw; int vh; @@ -121,31 +112,24 @@ private: std::string menu_fontURL; std::string presetURL; - - #ifdef USE_FTGL FTGLPixmapFont *title_font; FTGLPixmapFont *other_font; FTGLExtrdFont *poly_font; #endif /** USE_FTGL */ - - - void SetupPass1(const Pipeline* pipeline, const PipelineContext &pipelineContext); - void SetupShaders(const Pipeline* pipeline, const PipelineContext &pipelineContext); - void Interpolation(const Pipeline* pipeline); - void RenderItems(const Pipeline* pipeline, const PipelineContext &pipelineContext); - void CompositeOutput(const Pipeline* pipeline, const PipelineContext &pipelineContext); + void SetupPass1(const Pipeline &pipeline, const PipelineContext &pipelineContext); + void Interpolation(const Pipeline &pipeline); + void RenderItems(const Pipeline &pipeline, const PipelineContext &pipelineContext); void FinishPass1(); - void Pass2 (const Pipeline* pipeline, const PipelineContext &pipelineContext); + void Pass2 (const Pipeline &pipeline, const PipelineContext &pipelineContext); + void CompositeOutput(const Pipeline &pipeline, const PipelineContext &pipelineContext); inline static Point PerPixel(Point p, PerPixelContext &context) { - return currentPipe->PerPixel(p,context); + return currentPipe->PerPixel(p,context); } - void Interpolation(PresetOutputs *presetOutputs, PresetInputs *presetInputs); - void rescale_per_pixel_matrices(); void draw_fps( float realfps ); diff --git a/src/libprojectM/RovastarFractalSpiral.hpp b/src/libprojectM/RovastarFractalSpiral.hpp index a99756b23..83c11de06 100644 --- a/src/libprojectM/RovastarFractalSpiral.hpp +++ b/src/libprojectM/RovastarFractalSpiral.hpp @@ -53,16 +53,16 @@ public: virtual Point PerPixel(Point p, const PerPixelContext context) { - float q1 = 8.05+(sinf(p.x+0.137*time)-cosf(p.y+0.213*time)); - int val1 = abs(p.x*3-0.4*sinf(q1)); - int val2 = abs(p.y*3+0.4*sinf(q1)); + float q1 = 8.05+(sin(p.x+0.137*time)-cos(p.y+0.213*time)); + int val1 = abs(p.x*3-0.4*sin(q1)); + int val2 = abs(p.y*3+0.4*sin(q1)); val1 = val1%2; val2 = val2%2; float box=(1-context.rad)+ 0.5 * val1 + 0.5*val2; float zoom = if_milk(above(box,1),q1*.1,0.998531); - float rot = if_milk(above(box,1),1*sinf(0.385*time),0.02); + float rot = if_milk(above(box,1),1*sin(0.385*time),0.02); Transforms::Zoom(p,context,zoom,1.01); Transforms::Rotate(p,context,rot,cx,cy); diff --git a/src/libprojectM/Shader.cpp b/src/libprojectM/Shader.cpp index 8b1033ced..1ffb11926 100644 --- a/src/libprojectM/Shader.cpp +++ b/src/libprojectM/Shader.cpp @@ -8,6 +8,5 @@ #include "Shader.hpp" Shader::Shader() - : enabled(false),blur1n(1), blur2n(1), blur3n(1), - blur1x(1), blur2x(1), blur3x(1), - blur1ed(1){} + : enabled(false) + {} diff --git a/src/libprojectM/Shader.hpp b/src/libprojectM/Shader.hpp index 27e0591a3..beecb79e9 100644 --- a/src/libprojectM/Shader.hpp +++ b/src/libprojectM/Shader.hpp @@ -18,17 +18,8 @@ public: std::map textures; - bool enabled; - float blur1n; - float blur2n; - float blur3n; - float blur1x; - float blur2x; - float blur3x; - float blur1ed; - std::string programSource; Shader(); diff --git a/src/libprojectM/ShaderEngine.cpp b/src/libprojectM/ShaderEngine.cpp index 0db7cdd1c..d7bf24ae6 100644 --- a/src/libprojectM/ShaderEngine.cpp +++ b/src/libprojectM/ShaderEngine.cpp @@ -22,7 +22,7 @@ ShaderEngine::~ShaderEngine() #ifdef USE_CG -void ShaderEngine::SetParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, +void ShaderEngine::setParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, TextureManager *textureManager) { mainTextureId = texId; @@ -35,7 +35,7 @@ void ShaderEngine::SetParams(const int texsize, const unsigned int texId, const glGenTextures(1, &blur1_tex); glBindTexture(GL_TEXTURE_2D, blur1_tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texsize/2, texsize/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -43,7 +43,7 @@ void ShaderEngine::SetParams(const int texsize, const unsigned int texId, const glGenTextures(1, &blur2_tex); glBindTexture(GL_TEXTURE_2D, blur2_tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texsize / 2, texsize / 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texsize / 4, texsize / 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -51,7 +51,7 @@ void ShaderEngine::SetParams(const int texsize, const unsigned int texId, const glGenTextures(1, &blur3_tex); glBindTexture(GL_TEXTURE_2D, blur3_tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texsize / 4, texsize / 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texsize / 8, texsize / 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -249,7 +249,7 @@ bool ShaderEngine::LoadCgProgram(Shader &shader) { UserTexture* texture = shader.textures[tex]; texture->texsizeDefined = true; - std::cout << "texsize_" << tex << " found" << std::endl; + //std::cout << "texsize_" << tex << " found" << std::endl; } } found = program.find("texsize_", found); @@ -381,7 +381,7 @@ void ShaderEngine::SetupCg() profileName = cgGetProfileString(myCgProfile); std::cout << "Cg: Initialized profile: " << profileName << std::endl; - blur1Program = cgCreateProgram(myCgContext, CG_SOURCE, blurProgram.c_str(), myCgProfile, "blurHoriz", NULL); + blur1Program = cgCreateProgram(myCgContext, CG_SOURCE, blurProgram.c_str(), myCgProfile, "blur1", NULL); checkForCgCompileError("creating blur1 program"); if (blur1Program == NULL) @@ -421,12 +421,12 @@ void ShaderEngine::SetupCgVariables(CGprogram program, const Pipeline &pipeline, cgGLSetParameter1f(cgGetNamedParameter(program, "frame"), context.frame); cgGLSetParameter1f(cgGetNamedParameter(program, "progress"), context.progress); - cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_min"), pipeline.warpShader.blur1n); - cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_max"), pipeline.warpShader.blur1x); - cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_min"), pipeline.warpShader.blur2n); - cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_max"), pipeline.warpShader.blur2x); - cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_min"), pipeline.warpShader.blur3n); - cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_max"), pipeline.warpShader.blur3x); + cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_min"), pipeline.blur1n); + cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_max"), pipeline.blur1x); + cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_min"), pipeline.blur2n); + cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_max"), pipeline.blur2x); + cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_min"), pipeline.blur3n); + cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_max"), pipeline.blur3x); cgGLSetParameter1f(cgGetNamedParameter(program, "bass"), beatDetect->bass); cgGLSetParameter1f(cgGetNamedParameter(program, "mid"), beatDetect->mid); @@ -478,8 +478,6 @@ void ShaderEngine::SetupUserTexture(CGprogram program, const UserTexture* textur / (float) texture->width, 1 / (float) texture->height); checkForCgError("setting parameter texsize"); } - - } void ShaderEngine::SetupUserTextureState( const UserTexture* texture) @@ -491,28 +489,23 @@ void ShaderEngine::SetupUserTextureState( const UserTexture* texture) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrap ? GL_REPEAT : GL_CLAMP); } -void ShaderEngine::SetupCgQVariables(Shader &shader, const PresetOutputs &q) +void ShaderEngine::SetupCgQVariables(CGprogram program, const Pipeline &q) { - CGprogram program = programs[&shader]; - - if (shader.enabled) - { - cgGLSetParameter4f(cgGetNamedParameter(program, "_qa"), q.q1, q.q2, q.q3, q.q4); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qb"), q.q5, q.q6, q.q7, q.q8); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qc"), q.q9, q.q10, q.q11, q.q12); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qd"), q.q13, q.q14, q.q15, q.q16); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qe"), q.q17, q.q18, q.q19, q.q20); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qf"), q.q21, q.q22, q.q23, q.q24); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qg"), q.q25, q.q26, q.q27, q.q28); - cgGLSetParameter4f(cgGetNamedParameter(program, "_qh"), q.q29, q.q30, q.q31, q.q32); - } + cgGLSetParameter4f(cgGetNamedParameter(program, "_qa"), q.q[0], q.q[1], q.q[2], q.q[3]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qb"), q.q[4], q.q[5], q.q[6], q.q[7]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qc"), q.q[8], q.q[9], q.q[10], q.q[11]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qd"), q.q[12], q.q[13], q.q[14], q.q[15]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qe"), q.q[16], q.q[17], q.q[18], q.q[19]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qf"), q.q[20], q.q[21], q.q[22], q.q[23]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qg"), q.q[24], q.q[25], q.q[26], q.q[27]); + cgGLSetParameter4f(cgGetNamedParameter(program, "_qh"), q.q[28], q.q[29], q.q[30], q.q[31]); } void ShaderEngine::setAspect(float aspect) { this->aspect = aspect; } -void ShaderEngine::RenderBlurTextures(const Pipeline *pipeline, const PipelineContext &pipelineContext, +void ShaderEngine::RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext, const int texsize) { if (blur1_enabled || blur2_enabled || blur3_enabled) @@ -540,120 +533,97 @@ void ShaderEngine::RenderBlurTextures(const Pipeline *pipeline, const PipelineCo if (blur1_enabled) { - cgGLSetParameter4f(cgGetNamedParameter(blur1Program, "srctexsize"), texsize, texsize, 1 / (float) texsize, - 1 / (float) texsize); - cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize, texsize, 1 / (float) texsize, - 1 / (float) texsize); + cgGLSetParameter4f(cgGetNamedParameter(blur1Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize, + 2 / (float) texsize); + cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2 , texsize/2, 2 / (float) texsize, + 2 / (float) texsize); - cgGLBindProgram(blur1Program); - checkForCgError("binding blur1 program"); - float points[4][2] = + + float pointsold[4][2] = { { 0, 1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } }; + float points[4][2] = + { + { 0, 0.5 }, + { 0, 0 }, + { 0.5, 0 }, + { 0.5, 0.5 } }; + + cgGLBindProgram(blur1Program); + checkForCgError("binding blur1 program"); glVertexPointer(2, GL_FLOAT, 0, points); -glBlendFunc(GL_ONE,GL_ZERO); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - - - cgGLUnbindProgram(myCgProfile); - checkForCgError("unbinding blur1 program"); - glBindTexture(GL_TEXTURE_2D, blur1_tex); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); - - cgGLBindProgram(blur2Program); - checkForCgError("binding blur2 program"); glBlendFunc(GL_ONE,GL_ZERO); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize); - cgGLUnbindProgram(myCgProfile); - checkForCgError("unbinding blur2 program"); + glBindTexture(GL_TEXTURE_2D, blur1_tex); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/2, texsize/2); + + } if (blur2_enabled) { - cgGLSetParameter4f(cgGetNamedParameter(blur1Program, "srctexsize"), texsize, texsize, 1 / (float) texsize, - 1 / (float) texsize); - cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize, texsize, 1 / (float) texsize, - 1 / (float) texsize); - - cgGLBindProgram(blur1Program); - checkForCgError("binding blur1 program"); - - float points[4][2] = - { - { 0, 0.5 }, - { 0, 0 }, - { 0.5, 0 }, - { 0.5, 0.5 } }; - - glVertexPointer(2, GL_FLOAT, 0, points); - glBlendFunc(GL_ONE,GL_ZERO); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - - cgGLUnbindProgram(myCgProfile); - checkForCgError("unbinding blur1 program"); - - cgGLBindProgram(blur2Program); - checkForCgError("binding blur2 program"); - glBlendFunc(GL_ONE,GL_ONE); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - glBindTexture(GL_TEXTURE_2D, blur2_tex); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/2, texsize/2); - - cgGLUnbindProgram(myCgProfile); - checkForCgError("unbinding blur2 program"); - } - - if (blur3_enabled) - { - cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize, + cgGLSetParameter4f(cgGetNamedParameter(blur1Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize, 2 / (float) texsize); - cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize / 2, texsize / 2, 2 - / (float) texsize, 2 / (float) texsize); + cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize, + 2 / (float) texsize); + + + float points[4][2] = { { 0, 0.25 }, { 0, 0 }, { 0.25, 0 }, { 0.25, 0.25 } }; - cgGLBindProgram(blur1Program); - checkForCgError("binding blur2 program"); + glVertexPointer(2, GL_FLOAT, 0, points); glBlendFunc(GL_ONE,GL_ZERO); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - //glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize / 4, texsize / 4); - cgGLUnbindProgram(myCgProfile); - checkForCgError("unbinding blur1 program"); - cgGLBindProgram(blur2Program); - checkForCgError("binding blur2 program"); - glBlendFunc(GL_ONE,GL_ONE); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - glBindTexture(GL_TEXTURE_2D, blur3_tex); + glBindTexture(GL_TEXTURE_2D, blur2_tex); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/4, texsize/4); - cgGLUnbindProgram(myCgProfile); - checkForCgError("unbinding blur2 program"); + } - if (false && blur2_enabled || blur3_enabled) + if (blur3_enabled) { + cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/4, texsize/4, 4 / (float) texsize, + 4/ (float) texsize); + cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize / 4, texsize / 4, 4 + / (float) texsize, 4 / (float) texsize); + float points[4][2] = + { + { 0, 0.125 }, + { 0, 0 }, + { 0.125, 0 }, + { 0.125, 0.125 } }; + + glVertexPointer(2, GL_FLOAT, 0, points); + glBlendFunc(GL_ONE,GL_ZERO); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + + + glBindTexture(GL_TEXTURE_2D, blur3_tex); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/8, texsize/8); + + + } + + cgGLUnbindProgram(myCgProfile); checkForCgError("unbinding blur2 program"); - } + cgGLDisableProfile(myCgProfile); checkForCgError("disabling blur profile"); @@ -686,14 +656,12 @@ void ShaderEngine::disableShader() enabled = false; } -void ShaderEngine::enableShader(Shader &shader, const Pipeline *pipeline, const PipelineContext *pipelineContext) +void ShaderEngine::enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext) { enabled = false; if (shader.enabled) { - - for (std::map::const_iterator pos = shader.textures.begin(); pos != shader.textures.end(); ++pos) SetupUserTextureState( pos->second); @@ -709,7 +677,8 @@ void ShaderEngine::enableShader(Shader &shader, const Pipeline *pipeline, const cgGLBindProgram(program); checkForCgError("binding warp program"); - SetupCgVariables(program, *pipeline, *pipelineContext); + SetupCgVariables(program, pipeline, pipelineContext); + SetupCgQVariables(program, pipeline); enabled = true; } diff --git a/src/libprojectM/ShaderEngine.hpp b/src/libprojectM/ShaderEngine.hpp index 7b98859a0..df17bee32 100644 --- a/src/libprojectM/ShaderEngine.hpp +++ b/src/libprojectM/ShaderEngine.hpp @@ -85,27 +85,29 @@ class ShaderEngine void SetupCg(); void SetupCgVariables(CGprogram program, const Pipeline &pipeline, const PipelineContext &pipelineContext); + void SetupCgQVariables(CGprogram program, const Pipeline &pipeline); void SetupUserTexture(CGprogram program, const UserTexture* texture); void SetupUserTextureState(const UserTexture* texture); + + #endif - - public: ShaderEngine(); virtual ~ShaderEngine(); +#ifdef USE_CG + void RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext, const int texsize); + void loadShader(Shader &shader); - void SetupCgQVariables(Shader &shader, const PresetOutputs &presetOutputs); - void RenderBlurTextures(const Pipeline* pipeline, const PipelineContext &pipelineContext, const int texsize); - void loadShader(Shader &shader); - - void SetParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, TextureManager *textureManager); - void enableShader(Shader &shader, const Pipeline *pipeline, const PipelineContext *pipelineContext); + void setParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, TextureManager *textureManager); + void enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext); void disableShader(); void reset(); void setAspect(float aspect); std::string profileName; + +#endif }; #endif /* SHADERENGINE_HPP_ */ diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp index d71c6cea7..5d8985d47 100755 --- a/src/libprojectM/projectM.cpp +++ b/src/libprojectM/projectM.cpp @@ -262,7 +262,7 @@ void projectM::evaluateSecondPreset() assert ( m_activePreset2.get() ); m_activePreset2->evaluateFrame(); - renderer->PerPixelMath ( &m_activePreset2->presetOutputs(), &presetInputs2 ); + m_activePreset2->presetOutputs().PerPixelMath ( presetInputs2 ); } void projectM::setupPresetInputs(PresetInputs *inputs) @@ -340,7 +340,7 @@ DLLEXPORT void projectM::renderFrame() pthread_mutex_unlock( &mutex ); #endif m_activePreset->evaluateFrame(); - renderer->PerPixelMath ( &m_activePreset->presetOutputs(), &presetInputs ); + m_activePreset->presetOutputs().PerPixelMath ( presetInputs ); #ifdef USE_THREADS pthread_mutex_lock( &mutex ); @@ -364,7 +364,7 @@ DLLEXPORT void projectM::renderFrame() m_activePreset->evaluateFrame(); - renderer->PerPixelMath ( &m_activePreset->presetOutputs(), &presetInputs ); + m_activePreset->presetOutputs().PerPixelMath (presetInputs ); } @@ -372,7 +372,7 @@ DLLEXPORT void projectM::renderFrame() // std::cout<< m_activePreset->absoluteFilePath()<presetName = m_activePreset->absoluteFilePath(); m_activePreset->presetOutputs().PrepareToRender(); - renderer->RenderFrame ( &m_activePreset->presetOutputs(), &presetInputs ); + renderer->RenderFrame ( m_activePreset->presetOutputs(), presetInputs ); count++; #ifndef WIN32 @@ -538,14 +538,9 @@ void projectM::projectM_initengine() /* Q AND T VARIABLES START */ - this->presetOutputs.q1 = 0; - this->presetOutputs.q2 = 0; - this->presetOutputs.q3 = 0; - this->presetOutputs.q4 = 0; - this->presetOutputs.q5 = 0; - this->presetOutputs.q6 = 0; - this->presetOutputs.q7 = 0; - this->presetOutputs.q8 = 0; + for (int i = 0;i<32;i++) + presetOutputs.q[i] = 0; + /* Q AND T VARIABLES END */ @@ -656,14 +651,8 @@ void projectM::projectM_resetengine() /* Q VARIABLES START */ - this->presetOutputs.q1 = 0; - this->presetOutputs.q2 = 0; - this->presetOutputs.q3 = 0; - this->presetOutputs.q4 = 0; - this->presetOutputs.q5 = 0; - this->presetOutputs.q6 = 0; - this->presetOutputs.q7 = 0; - this->presetOutputs.q8 = 0; + for (int i = 0;i<32;i++) + presetOutputs.q[i] = 0; /* Q VARIABLES END */