1 /*
2  * ShaderEngine.hpp
3  *
4  *  Created on: Jul 18, 2008
5  *      Author: pete
6  */
7 
8 #ifndef SHADERENGINE_HPP_
9 #define SHADERENGINE_HPP_
10 
11 #include "Common.hpp"
12 
13 #ifdef USE_GLES1
14 #include <GLES/gl.h>
15 #else
16 #ifdef __APPLE__
17 #include <OpenGL/gl.h>
18 #include <OpenGL/glu.h>
19 #else
20 #include <GL/gl.h>
21 #include <GL/glu.h>
22 #endif
23 #endif
24 
25 
26 #ifdef USE_CG
27 #include <Cg/cg.h>    /* Can't include this?  Is Cg Toolkit installed! */
28 #include <Cg/cgGL.h>
29 #endif
30 
31 
32 #include "Pipeline.hpp"
33 #include "PipelineContext.hpp"
34 class ShaderEngine;
35 #include "TextureManager.hpp"
36 
37 #include <cstdlib>
38 #include <iostream>
39 #include <map>
40 #include "Shader.hpp"
41 class ShaderEngine
42 {
43 #ifdef USE_CG
44 
45 
46   unsigned int mainTextureId;
47   int texsize;
48   float aspect;
49   BeatDetect *beatDetect;
50   TextureManager *textureManager;
51 
52   GLuint noise_texture_lq_lite;
53   GLuint noise_texture_lq;
54   GLuint noise_texture_mq;
55   GLuint noise_texture_hq;
56   GLuint noise_texture_perlin;
57   GLuint noise_texture_lq_vol;
58   GLuint noise_texture_hq_vol;
59 
60   bool blur1_enabled;
61   bool blur2_enabled;
62   bool blur3_enabled;
63   GLuint blur1_tex;
64   GLuint blur2_tex;
65   GLuint blur3_tex;
66 
67   float rand_preset[4];
68 
69   CGcontext   myCgContext;
70   CGprofile myCgProfile;
71   CGprogram   blur1Program;
72   CGprogram   blur2Program;
73 
74   bool enabled;
75 
76   std::map<Shader*,CGprogram> programs;
77 
78    std::string cgTemplate;
79    std::string blurProgram;
80 
81  bool LoadCgProgram(Shader &shader);
82  bool checkForCgCompileError(const char *situation);
83  void checkForCgError(const char *situation);
84 
85  void SetupCg();
86  void SetupCgVariables(CGprogram program, const Pipeline &pipeline, const PipelineContext &pipelineContext);
87  void SetupCgQVariables(CGprogram program, const Pipeline &pipeline);
88 
89  void SetupUserTexture(CGprogram program, const UserTexture* texture);
90  void SetupUserTextureState(const UserTexture* texture);
91 
92 
93 
94 #endif
95 public:
96 	ShaderEngine();
97 	virtual ~ShaderEngine();
98 #ifdef USE_CG
99     void RenderBlurTextures(const Pipeline  &pipeline, const PipelineContext &pipelineContext, const int texsize);
100 	void loadShader(Shader &shader);
101 
102 	void setParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, TextureManager *textureManager);
103 	void enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext);
104 	void disableShader();
105 	void reset();
106 	void setAspect(float aspect);
107     std::string profileName;
108 
109 #endif
110 };
111 
112 #endif /* SHADERENGINE_HPP_ */
113 
114