summaryrefslogtreecommitdiff
path: root/cad/plugins/QuteMol/qutemol/src/CgUtil.h
blob: 5a6bda5bf75ddb54ad599113b12c40c9eb92b4ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

class GeoSettings {
public:
  typedef enum{ SPACE_FILL, BALL_N_STICKS, LICORICE }  GeoMode;
  
  GeoMode mode;
  
  float stickRadius;
  float ballRadius;
  float licoRadius;

  bool stick_smooth_color;
  bool use_stick_const_color;
  float stick_const_color_R,stick_const_color_G,stick_const_color_B;
  
  bool showHetatm;
  
  void SetDefaults(){
    mode=SPACE_FILL;
    //stickRadius=0.2;
    SetLicoRadiusPercentage(50);
    SetStickRadiusPercentage(100);
    SetBallRadiusPercentage(100);
    //licoRadius=0.6;
    
    stick_smooth_color = false;
    use_stick_const_color = false;
    stick_const_color_R=0.75;
    stick_const_color_G=0.50;
    stick_const_color_B=0.50;
    
    showHetatm = false;

  }  
  
  void Rotate(){
    mode=(GeoMode)((((int)mode)+1)%3);
  }
  
  GeoSettings() {
     SetDefaults();
  }
  
  void Apply();
  void ApplyColor();
  
  void SetLicoRadiusPercentage(int percentage){
    licoRadius = 0.3 + percentage/100.0*0.65;
  }

  int GetLicoRadiusPercentage(){
    return int(100.0*((licoRadius - 0.3)/0.65));
  }

  void SetStickRadiusPercentage(int percentage){
    const float tmp=0.32 * 0.85-0.16;
    stickRadius = 0.16 + percentage/10.0*tmp;
  }

  int GetStickRadiusPercentage(){
    const float tmp=0.32 * 0.85-0.16;
    return int(10.0*((stickRadius - 0.16)/tmp));
  }
  
  void SetBallRadiusPercentage(int percentage){
    const float tmp=0.32 * 0.85-0.16;
    ballRadius = 0.16 + percentage/10.0*tmp;
  }

  int GetBallRadiusPercentage(){
    const float tmp=0.32 * 0.85-0.16;
    return int(10.0*((ballRadius - 0.16)/tmp));
  }
  
};

// drawing settings
class CgUtil {
public:

  
  // RENDERING PARAMETERS:
  // Settarli a piacere e poi chiamare setShaders...
  /////////////////////////////////////////////
  
  /*  SERIALIZE_BEGIN   */

  float P_light_base; // from 0 (dark) to 1 (bright)
  float P_lighting;   // from 0 (no lighting) to 1 (full lighting)
  float P_phong;      // from 0 (no phong lighting) to 1 (full lighting)
  float P_phong_size; // from 0 (POW=100) to 1 (POW=1)
  
  float P_col_atoms_sat;  // base color: saturation
  float P_col_atoms_bri;  // base color: brightness
  
  float P_texture;    // FOR AO! from 0 (no AO) to 1 full AO
  float P_border_inside; // size of antialiased borders inside, in % of atom
  float P_border_outside; // borders outside (pure black), full size
  float P_depth_full;     // size of depth step for a full border

  bool P_sem_effect;   
    
  float P_halo_size;
  float P_halo_col;
  float P_halo_str;
  float P_halo_aware;
  
  float P_fog; 
  
  bool P_capping; // capping
  float P_shadowstrenght; // how much light 

  float P_bg_color_R;
  float P_bg_color_G;
  float P_bg_color_B;

  bool auto_normalize;
  
  bool P_double_shadows;
  
  bool P_border_fixed;
  
  /*  SERIALIZE_END   */

  bool do_use_doubleshadow();
  bool can_use_doubleshadow();
  bool P_use_shadowmap() {return P_shadowstrenght>0; };

  // Save and load the above
  bool Load(const char* filename);
  bool Save(const char* filename);
  
  // Set
  void  Set();
  
  // coming from GeoSettings
  bool P_cyl_smooth_color;
  bool P_cyl_const_color;
  float P_cyl_const_color_R,P_cyl_const_color_G,P_cyl_const_color_B;
  float P_ball_radius;
  
  void setGeoSettings(const GeoSettings &gs);

  // Error messages
  static char lasterr[255];

  enum { USE_OCTA, USE_CUBE } textmode; // textmode
  enum {  PERSPECTIVE, ORTHO } projmode; // projmode
  bool proj_figa;
  
  void SetDefaults();    // set defoult params 
  void SetForOffLine();  // set defoult params for an offscreen rendering
  void SetForShadowMap(bool accurate);// set defoult params for an offscreen rendering
  void MakeShaders();    // activates params 
  void UpdateShaders() {shadersMade=false;};    // activates params 
  void BindShaders();    // binds, loads if necessary
  
  void MakeStickShaders();  
  void BindStickShaders();  
  
  bool BindDrawAOShader();
  bool MakeDrawAOShader();
  
  bool BindDrawAOShaderSticks();
  bool MakeDrawAOShaderSticks();
  
  bool UseHalo();
  
  bool BindHaloShader(int powres); // 1^pow = size of halo texture
  bool MakeHaloShader(int powres);
  
  // questi sono settati automaticamente
  /////////////////////////////////////
  float gap; // gap, % of border texels to be skipped
  int textureSideX,textureSideY;
  bool writeAlpha; // true during probe rendering only
  bool writeCol; // write a color at all?
  
  static bool init();
	static void ShowShaderInfo(int i);
  static bool checkError();
  static bool checkProgramError(char *st);
  static bool shaderHasChanged;
  
  float cyl_radius;

  bool doingAlphaSnapshot; // lots of things change when doing an alpha snapshot  

  CgUtil();
  
  void ResetHalo();
  
private:
  
  enum {MAXPOW=15};

  bool shadersMade;
  
  float norm;
  void Normalize();
  void UndoNormalize();
         
  bool setBallVertexProgram();
  bool setBallFragmentProgram();

  bool setStickVertexProgram();
  bool setStickFragmentProgram();
  
  /*static int loadVertexProgram(const char *str);
  static int loadFragmentProgram(const char *str);*/

  static char *readFile(const char *file);

  bool loaded, loadedStick, loadedVertexHalo;
  GLuint idf, idv, idfStick, idvStick;

  bool loadedHalo[MAXPOW];
  GLuint idfHalo[MAXPOW];
  GLuint idvHalo;
  
  void LoadVertexHaloShader();
  
  void addDirectLightingSnippet(char* fp);
  void addTexturingSnippet(char* fp);
  void addShadowMapComputationFP(char* fp);
  void addDepthAdjustSnippet(char* fp);
  
  float _border_outside();
  float _border_inside();

  bool shadowmapBuilding;
  bool accurateShadowmapBuilding;



};