SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLUniform< T > Class Template Reference

Template for a single GLSL uniform variable. More...

#include <SLGLUniform.h>

Inheritance diagram for SLGLUniform< T >:
[legend]

Public Member Functions

 SLGLUniform (SLUniformType type, const SLchar *name, T value, T inc=0.0f, T min=0.0f, T max=0.0f, SLKey keyInc=K_none)
 Constructs a custom uniform variable. More...
 
 SLGLUniform (const SLchar *name, function< T(void)> getFunc)
 
const SLcharname ()
 
value ()
 
SLbool onKeyPress (const SLKey key, const SLKey mod) override
 Key press event-handler. More...
 
- Public Member Functions inherited from SLEventHandler
 SLEventHandler ()
 
virtual ~SLEventHandler ()
 
virtual SLbool onMouseDown (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseUp (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseMove (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onDoubleClick (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseWheel (const SLint delta, const SLKey mod)
 
virtual SLbool onTouch2Down (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Move (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Up (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch3Down (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Move (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Up (const SLint x1, const SLint y1)
 
virtual SLbool onKeyRelease (const SLKey key, const SLKey mod)
 
virtual SLbool onRotationPYR (const SLfloat pitchRAD, const SLfloat yawRAD, const SLfloat rollRAD)
 
void mouseRotationFactor (SLfloat rf)
 
SLfloat mouseRotationFactor ()
 

Private Attributes

SLstring _name
 Name of the variable. More...
 
_value
 Current value. More...
 
_max
 Max. value for IncInc, IncDec & random types. More...
 
_min
 Min. value for IncInc, IncDec & random types. More...
 
_inc
 Increment value for IncInc, IncDec & Inc types. More...
 
SLUniformType _type
 Uniform1f type. More...
 
SLKey _keyInc
 keyboard key incrementing const values More...
 
function< T(void)> getValue
 lambda getter function More...
 

Additional Inherited Members

- Protected Attributes inherited from SLEventHandler
SLfloat _mouseRotationFactor
 Mouse rotation sensibility. More...
 
SLfloat _keyboardDeltaPos
 Delta dist. for keyboard translation. More...
 

Detailed Description

template<class T>
class SLGLUniform< T >

Template for a single GLSL uniform variable.

Class for GLSL uniform variables that change per frame. An SLGLProgram holds a list of this type of uniform variables that are applied within the beginUse method.

Definition at line 23 of file SLGLUniform.h.

Constructor & Destructor Documentation

◆ SLGLUniform() [1/2]

template<class T >
SLGLUniform< T >::SLGLUniform ( SLUniformType  type,
const SLchar name,
value,
inc = 0.0f,
min = 0.0f,
max = 0.0f,
SLKey  keyInc = K_none 
)
inline

Constructs a custom uniform variable.

Parameters
typeType of uniform variable
nameName of uniform variable
valueCurrent value
incIncrement value
minMinimal value
maxMaximal value
keyIncKey F1-F10 to increment the value decrement with SHIFT key

Definition at line 36 of file SLGLUniform.h.

43  {
44  _name = name;
45  _value = value;
46  _min = min;
47  _max = max;
48  _inc = inc;
49  _type = type;
50  _keyInc = keyInc;
51 
52  if (_keyInc != K_none && !(_keyInc >= K_F1 && _keyInc <= K_F10))
53  SL_EXIT_MSG("Please use keys F1-F10 for uniform variables.");
54  }
#define SL_EXIT_MSG(message)
Definition: SL.h:240
@ K_F1
Definition: SLEnums.h:49
@ K_none
Definition: SLEnums.h:17
@ K_F10
Definition: SLEnums.h:58
T _min
Min. value for IncInc, IncDec & random types.
Definition: SLGLUniform.h:155
SLstring _name
Name of the variable.
Definition: SLGLUniform.h:152
T _max
Max. value for IncInc, IncDec & random types.
Definition: SLGLUniform.h:154
SLKey _keyInc
keyboard key incrementing const values
Definition: SLGLUniform.h:158
T _value
Current value.
Definition: SLGLUniform.h:153
SLUniformType _type
Uniform1f type.
Definition: SLGLUniform.h:157
const SLchar * name()
Definition: SLGLUniform.h:64
T _inc
Increment value for IncInc, IncDec & Inc types.
Definition: SLGLUniform.h:156

◆ SLGLUniform() [2/2]

template<class T >
SLGLUniform< T >::SLGLUniform ( const SLchar name,
function< T(void)>  getFunc 
)
inline

Definition at line 56 of file SLGLUniform.h.

58  {
59  _name = name;
60  _type = UT_lambda;
61  getValue = getFunc;
62  }
@ UT_lambda
lambda getter function
Definition: SLEnums.h:239
function< T(void)> getValue
lambda getter function
Definition: SLGLUniform.h:159

Member Function Documentation

◆ name()

template<class T >
const SLchar* SLGLUniform< T >::name ( )
inline

Definition at line 64 of file SLGLUniform.h.

64 { return _name.c_str(); }

◆ onKeyPress()

template<class T >
SLbool SLGLUniform< T >::onKeyPress ( const SLKey  key,
const SLKey  mod 
)
inlineoverridevirtual

Key press event-handler.

Reimplemented from SLEventHandler.

Definition at line 116 of file SLGLUniform.h.

117  {
118  if (_keyInc != K_none)
119  {
120  if (key == _keyInc)
121  {
122  if (mod == K_none)
123  {
124  if (_value < _max)
125  {
126  _value += _inc;
127  SL_LOG("Uniform: %s = %5.4f", _name.c_str(),(float)_value);
128  return true;
129  }
130  else if (_inc == _max) // Toggle between min & max
131  {
132  _value = _min;
133  SL_LOG("Uniform: %s = %5.4f", _name.c_str(),(float)_value);
134  return true;
135  }
136  }
137  else if (mod == K_shift)
138  {
139  if (_value > _min)
140  {
141  _value -= _inc;
142  SL_LOG("Uniform: %s = %5.4f", _name.c_str(),(float)_value);
143  return true;
144  }
145  }
146  }
147  }
148  return false;
149  }
#define SL_LOG(...)
Definition: SL.h:233
@ K_shift
Definition: SLEnums.h:62
T mod(T a, T b)
Definition: Utils.h:250

◆ value()

template<class T >
T SLGLUniform< T >::value ( )
inline

calculates the current value & returns it. This method is called on every frame.

Definition at line 70 of file SLGLUniform.h.

71  {
72  if (_type == UT_const)
73  return _value;
74 
75  if (_type == UT_lambda)
76  return getValue();
77 
78  if (_type == UT_incDec)
79  {
80  if ((_inc > 0.0f && _value >= _max) ||
81  (_inc < 0.0f && _value <= _min)) _inc *= -1;
82  _value += _inc;
83  return _value;
84  }
85 
86  if (_type == UT_incInc)
87  {
88  if (_inc > 0 && _value >= _max) _value = _min;
89  if (_inc < 0 && _value <= _min) _value = _max;
90  _value += _inc;
91  return _value;
92  }
93 
94  if (_type == UT_inc)
95  {
96  _value += _inc;
97  return _value;
98  }
99 
100  if (_type == UT_random)
101  {
102  _value = _min + ((T)rand() / (T)RAND_MAX) * (_max - _min);
103  return _value;
104  }
105 
106  if (_type == UT_seconds)
107  {
108  _value = (T)clock() / CLOCKS_PER_SEC;
109  return _value;
110  }
111  else
112  return _value;
113  }
@ UT_seconds
seconds since the process has started
Definition: SLEnums.h:238
@ UT_incDec
never ending loop from min to max and max to min
Definition: SLEnums.h:234
@ UT_inc
never ending increment
Definition: SLEnums.h:236
@ UT_incInc
never ending loop from min to max
Definition: SLEnums.h:235
@ UT_random
random values between min and max
Definition: SLEnums.h:237
@ UT_const
constant value
Definition: SLEnums.h:233

Member Data Documentation

◆ _inc

template<class T >
T SLGLUniform< T >::_inc
private

Increment value for IncInc, IncDec & Inc types.

Definition at line 156 of file SLGLUniform.h.

◆ _keyInc

template<class T >
SLKey SLGLUniform< T >::_keyInc
private

keyboard key incrementing const values

Definition at line 158 of file SLGLUniform.h.

◆ _max

template<class T >
T SLGLUniform< T >::_max
private

Max. value for IncInc, IncDec & random types.

Definition at line 154 of file SLGLUniform.h.

◆ _min

template<class T >
T SLGLUniform< T >::_min
private

Min. value for IncInc, IncDec & random types.

Definition at line 155 of file SLGLUniform.h.

◆ _name

template<class T >
SLstring SLGLUniform< T >::_name
private

Name of the variable.

Definition at line 152 of file SLGLUniform.h.

◆ _type

template<class T >
SLUniformType SLGLUniform< T >::_type
private

Uniform1f type.

Definition at line 157 of file SLGLUniform.h.

◆ _value

template<class T >
T SLGLUniform< T >::_value
private

Current value.

Definition at line 153 of file SLGLUniform.h.

◆ getValue

template<class T >
function<T(void)> SLGLUniform< T >::getValue
private

lambda getter function

Definition at line 159 of file SLGLUniform.h.


The documentation for this class was generated from the following file: