projectM 2.0 has become an eventuality

git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@1083 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
psperl
2008-07-11 06:06:03 +00:00
parent 49102ef0c6
commit 44762b35a4
3 changed files with 264 additions and 64 deletions

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <algorithm>
#include <cassert>
#include <fstream>
#include "omptl/omptl"
#include "omptl/omptl_algorithm"
@ -20,6 +21,10 @@ Renderer::Renderer(int width, int height, int gx, int gy, int texsize, BeatDetec
{
int x; int y;
#ifdef USE_CG
this->compositeShadersEnabled = false;
this->warpShadersEnabled = false;
#endif
this->totalframes = 1;
this->noSwitch = false;
this->showfps = false;
@ -106,17 +111,100 @@ SetupCg();
#endif
}
void Renderer::SetPipeline(Pipeline &pipeline)
{
#ifdef USE_CG
if(warpShadersEnabled) cgDestroyProgram(myCgWarpProgram);
if(compositeShadersEnabled) cgDestroyProgram(myCgCompositeProgram);
warpShadersEnabled = LoadCgProgram(pipeline.shader.warp, myCgWarpProgram);
compositeShadersEnabled = LoadCgProgram(pipeline.shader.composite, myCgCompositeProgram);
pipeline.shader.warp.clear();
pipeline.shader.composite.clear();
#endif
}
#ifdef USE_CG
bool Renderer::LoadCgProgram(std::string program, CGprogram &p)
{
//if (p != NULL) cgDestroyProgram(p);
//p = NULL;
if (program.length() > 0)
{
std::string temp;
temp.append(cgTemplate);
temp.append(program.substr(11));
temp.append("OUT.color.xyz = ret;return OUT;}");
std::cout<<"Cg: Compilation Results:"<<std::endl<<std::endl;
std::cout<<temp<<std::endl;
p = cgCreateProgram(myCgContext,
CG_SOURCE,
temp.c_str(),//temp.c_str(),
myCgProfile,
"projectm",
NULL);
if (checkForCgCompileError("creating shader program"))
{
//p = NULL;
//return false;
}
if (p==NULL) return false;
cgGLLoadProgram(p);
if (checkForCgCompileError("loading shader program"))
{
p = NULL;
return false;
}
return true;
}
else return false;
}
bool Renderer::checkForCgCompileError(const char *situation)
{
CGerror error;
const char *string = cgGetLastErrorString(&error);
error = cgGetError();
if (error != CG_NO_ERROR) {
std::cout<<"Cg: Compilation Error"<<std::endl;
std::cout<<"Cg: %"<<situation<<" - "<<string<<std::endl;
if (error == CG_COMPILER_ERROR) {
std::cout<<"Cg: "<< cgGetLastListing( myCgContext )<<std::endl;
}
return true;
}
return false;
}
void Renderer::checkForCgError(const char *situation)
{
CGerror error;
const char *string = cgGetLastErrorString(&error);
if (error != CG_NO_ERROR) {
printf("%%s: %s\n",
situation, string);
if (error == CG_COMPILER_ERROR) {
//printf("%s\n", cgGetLastListing( myCgContext ));
std::cout<<"Cg: %"<<situation<<" - "<<string<<std::endl;
if (error == CG_COMPILER_ERROR) {
std::cout<<"Cg: "<< cgGetLastListing( myCgContext )<<std::endl;
}
exit(1);
}
@ -124,12 +212,22 @@ void Renderer::checkForCgError(const char *situation)
void Renderer::SetupCg()
{
std::string line;
std::ifstream myfile ("/home/pete/projectM.cg");
if (myfile.is_open())
{
while (! myfile.eof() )
{
std::getline (myfile,line);
cgTemplate.append(line + "\n");
}
myfile.close();
}
compositeProgram = "composite";
warpProgram = "warp";
shaderFile="/home/pete/test.cg";
else std::cout << "Unable to load shader template" << std::endl;
myCgContext = cgCreateContext();
myCgContext = cgCreateContext();
checkForCgError("creating context");
cgGLSetDebugMode( CG_FALSE );
cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING);
@ -139,31 +237,7 @@ myCgContext = cgCreateContext();
cgGLSetOptimalOptions(myCgProfile);
checkForCgError("selecting fragment profile");
myCgWarpProgram =
cgCreateProgramFromFile(
myCgContext, /* Cg runtime context */
CG_SOURCE, /* Program in human-readable form */
shaderFile.c_str(), /* Name of file containing program */
myCgProfile, /* Profile: OpenGL ARB vertex program */
warpProgram.c_str(), /* Entry function name */
NULL); /* No extra compiler options */
checkForCgError("creating fragment program from file");
cgGLLoadProgram(myCgWarpProgram);
checkForCgError("loading fragment program");
myCgCompositeProgram =
cgCreateProgramFromFile(
myCgContext, /* Cg runtime context */
CG_SOURCE, /* Program in human-readable form */
shaderFile.c_str(), /* Name of file containing program */
myCgProfile, /* Profile: OpenGL ARB vertex program */
compositeProgram.c_str(), /* Entry function name */
NULL); /* No extra compiler options */
checkForCgError("creating fragment program from file");
cgGLLoadProgram(myCgCompositeProgram);
checkForCgError("loading fragment program");
std::cout<<"Cg: Initialized profile: "<<cgGetProfileString(myCgProfile)<<std::endl;
}
@ -188,8 +262,6 @@ void Renderer::SetupCgVariables(CGprogram program, const PipelineContext &contex
cgGLSetParameter4f(cgGetNamedParameter(program, "texsize"), renderTarget->texsize, renderTarget->texsize, 1/(float)renderTarget->texsize,1/(float)renderTarget->texsize);
cgGLSetParameter4f(cgGetNamedParameter(program, "aspect"), aspect,1,1/aspect,1);
}
#endif
@ -269,9 +341,10 @@ void Renderer::FinishPass1()
glPopMatrix();
renderTarget->unlock();
}
void Renderer::Pass2(const Pipeline *pipeline)
void Renderer::Pass2(const Pipeline *pipeline, const PipelineContext &pipelineContext)
{
//BEGIN PASS 2
//
@ -305,7 +378,7 @@ void Renderer::Pass2(const Pipeline *pipeline)
glLineWidth( this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512.0);
CompositeOutput(pipeline);
CompositeOutput(pipeline, pipelineContext);
glMatrixMode(GL_MODELVIEW);
@ -333,47 +406,66 @@ void Renderer::RenderFrame(const Pipeline* pipeline, const PipelineContext &pipe
SetupPass1(pipeline, pipelineContext);
#ifdef USE_CG
cgGLBindProgram(myCgWarpProgram);
checkForCgError("binding warp program");
if (warpShadersEnabled)
{
cgGLEnableProfile(myCgProfile);
checkForCgError("enabling warp profile");
cgGLBindProgram(myCgWarpProgram);
checkForCgError("binding warp program");
SetupCgVariables(myCgWarpProgram, pipelineContext);
}
#endif
Interpolation(pipeline);
#ifdef USE_CG
if (warpShadersEnabled)
{
cgGLUnbindProgram(myCgProfile);
checkForCgError("disabling fragment profile");
cgGLDisableProfile(myCgProfile);
checkForCgError("disabling fragment profile");
}
#endif
RenderItems(pipeline,pipelineContext);
FinishPass1();
Pass2(pipeline);
Pass2(pipeline, pipelineContext);
}
void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs)
{
SetupPass1(presetOutputs, *presetInputs);
#ifdef USE_CG
if (warpShadersEnabled)
{
cgGLEnableProfile(myCgProfile);
checkForCgError("enabling warp profile");
cgGLBindProgram(myCgWarpProgram);
checkForCgError("binding warp program");
cgGLEnableProfile(myCgProfile);
checkForCgError("enabling warp profile");
SetupCgVariables(myCgWarpProgram, *presetInputs);
}
#endif
Interpolation(presetOutputs, presetInputs);
#ifdef USE_CG
if (warpShadersEnabled)
{
cgGLUnbindProgram(myCgProfile);
checkForCgError("disabling fragment profile");
cgGLDisableProfile(myCgProfile);
checkForCgError("disabling fragment profile");
}
#endif
RenderItems(presetOutputs, *presetInputs);
FinishPass1();
Pass2(presetOutputs);
Pass2(presetOutputs, *presetInputs);
}
@ -928,26 +1020,38 @@ void Renderer::draw_stats()
glRasterPos2f(0, -.09+offset);
other_font->FaceSize((unsigned)(18*(this->vh/512.0)));
other_font->FaceSize((unsigned)(18*(vh/512.0)));
sprintf( buffer, " texsize: %d", this->renderTarget->texsize);
sprintf( buffer, " texsize: %d", renderTarget->texsize);
other_font->Render(buffer);
glRasterPos2f(0, -.13+offset);
sprintf( buffer, "viewport: %d x %d", this->vw, this->vh);
sprintf( buffer, " viewport: %d x %d", vw, vh);
other_font->Render(buffer);
glRasterPos2f(0, -.17+offset);
other_font->Render((this->renderTarget->useFBO ? " FBO: on" : " FBO: off"));
other_font->Render((renderTarget->useFBO ? " FBO: on" : " FBO: off"));
glRasterPos2f(0, -.21+offset);
sprintf( buffer, " mesh: %d x %d", mesh.width, mesh.height);
sprintf( buffer, " mesh: %d x %d", mesh.width, mesh.height);
other_font->Render(buffer);
glRasterPos2f(0, -.25+offset);
sprintf( buffer, "textures: %.1fkB", textureManager->getTextureMemorySize() /1000.0f);
sprintf( buffer, " textures: %.1fkB", textureManager->getTextureMemorySize() /1000.0f);
other_font->Render(buffer);
#ifdef USE_CG
glRasterPos2f(0, -.29+offset);
sprintf( buffer, "shader profile: %s", cgGetProfileString(myCgProfile));
other_font->Render(buffer);
glRasterPos2f(0, -.33+offset);
sprintf( buffer, " warp shader: %s", warpShadersEnabled ? "on" : "off");
other_font->Render(buffer);
glRasterPos2f(0, -.37+offset);
sprintf( buffer, " comp shader: %s", compositeShadersEnabled ? "on" : "off");
other_font->Render(buffer);
#endif
glPopMatrix();
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@ -977,7 +1081,7 @@ void Renderer::draw_fps( float realfps )
void Renderer::CompositeOutput(const Pipeline* pipeline)
void Renderer::CompositeOutput(const Pipeline* pipeline, const PipelineContext &pipelineContext)
{
@ -994,11 +1098,17 @@ void Renderer::CompositeOutput(const Pipeline* pipeline)
glEnable(GL_TEXTURE_2D);
#ifdef USE_CG
cgGLBindProgram(myCgCompositeProgram);
checkForCgError("binding warp program");
if (compositeShadersEnabled)
{
cgGLEnableProfile(myCgProfile);
checkForCgError("enabling warp profile");
cgGLBindProgram(myCgCompositeProgram);
checkForCgError("binding warp program");
SetupCgVariables(myCgCompositeProgram, pipelineContext);
}
#endif
@ -1027,10 +1137,13 @@ void Renderer::CompositeOutput(const Pipeline* pipeline)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#ifdef USE_CG
if (compositeShadersEnabled)
{
cgGLUnbindProgram(myCgProfile);
checkForCgError("disabling fragment profile");
cgGLDisableProfile(myCgProfile);
checkForCgError("disabling fragment profile");
}
#endif
for (std::vector<RenderItem*>::const_iterator pos = pipeline->compositeDrawables.begin(); pos != pipeline->compositeDrawables.end(); ++pos)

View File

@ -77,6 +77,7 @@ public:
GLuint initRenderToTexture();
void PerPixelMath(PresetOutputs *presetOutputs, PresetInputs *presetInputs);
void SetPipeline(Pipeline &pipeline);
void setPresetName(const std::string& theValue)
{
@ -118,21 +119,21 @@ private:
#ifdef USE_CG
CGcontext myCgContext;
CGprofile myCgProfile;
std::string cgTemplate;
CGprogram myCgWarpProgram,
bool warpShadersEnabled;
bool compositeShadersEnabled;
CGcontext myCgContext;
CGprofile myCgProfile;
CGprogram myCgWarpProgram,
myCgCompositeProgram;
std::string warpProgram;
std::string compositeProgram;
std::string shaderFile;
bool LoadCgProgram(std::string program, CGprogram &p);
bool checkForCgCompileError(const char *situation);
void checkForCgError(const char *situation);
void SetupCg();
void SetupCgVariables(CGprogram program, const PipelineContext &context);
void SetupCgVariables(CGprogram program, const PipelineContext &pipelineContext);
#endif
#ifdef USE_FTGL
@ -144,11 +145,12 @@ private:
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);
void CompositeOutput(const Pipeline* pipeline, const PipelineContext &pipelineContext);
void FinishPass1();
void Pass2 (const Pipeline* pipeline);
void Pass2 (const Pipeline* pipeline, const PipelineContext &pipelineContext);
inline static Point PerPixel(Point p, PerPixelContext &context)
{

View File

@ -0,0 +1,85 @@
#define M_PI 3.14159265359
#define M_PI_2 6.28318530718
#define M_INV_PI_2 0.159154943091895
#define lum(x) (dot(x,float3(0.32,0.49,0.29)))
#define tex2d tex2D
#define tex3d tex3D
#define getrad sqrt((uv.x-0.5)*2*(uv.x-0.5)*2+(uv.y-0.5)*2*(uv.y-0.5)*2)*.7071067
#define getang atan2(((uv.y-0.5)*2),((uv.x-0.5)*2))
sampler2D sampler_main;
#define GetBlur2 GetBlur1
#define GetBlur3 GetBlur1
#define GetMain(uv) (tex2D(sampler_main,uv).xyz)
#define GetPixel(uv) (tex2D(sampler_main,uv).xyz)
#define uv_orig uv
#define sampler_pw_main sampler_main
#define sampler_pc_main sampler_main
#define sampler_fw_main sampler_main
#define sampler_fc_main sampler_main
#define sampler_noise_lq sampler_main
#define sampler_noise_lq_lite sampler_main
#define sampler_noise_mq sampler_main
#define sampler_noise_hq sampler_main
#define sampler_noisevol_lq sampler_main
#define sampler_noisevol_hq sampler_main
#define texsize_noise_lq texsize
#define texsize_noise_lq_lite texsize
#define texsize_noise_mq texsize
#define texsize_noise_hq texsize
#define texsize_noisevol_lq texsize
#define texsize_noisevol_hq texsize
struct outtype {float4 color : COLOR;};
//float3 lum(float3 a){return dot(a, float3(0.32,0.49,0.29));}
float3 GetBlur1(float2 uv)
{
float3 ret = tex2D(sampler_main, uv).xyz;
ret += tex2D(sampler_main, float2(uv.x-.001, uv.y)).xyz;
ret += tex2D(sampler_main, float2(uv.x+.001, uv.y)).xyz;
ret += tex2D(sampler_main, float2(uv.x, uv.y + .001)).xyz;
ret += tex2D(sampler_main, float2(uv.x, uv.y - .001)).xyz;
return ret * 0.2;
}
outtype projectm (float2 uv : TEXCOORD0,
uniform sampler2D sampler_arg : TEX0,
uniform float time,
uniform float4 rand_preset,
uniform float4 rand_frame,
uniform float progress,
uniform float frame,
uniform float fps,
uniform float bass,
uniform float mid,
uniform float treb,
uniform float vol,
uniform float bass_att,
uniform float mid_att,
uniform float treb_att,
uniform float vol_att,
uniform float4 texsize,
uniform float4 aspect
)
{
outtype OUT;
OUT.color.w=1;
float3 ret;
sampler_main = sampler_arg;
float rad = getrad;
float ang = getang;