-
Notifications
You must be signed in to change notification settings - Fork 31
/
ShaderMaker.h
199 lines (169 loc) · 5.23 KB
/
ShaderMaker.h
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
//
// ShaderMaker.h
//
// ------------------------------------------------------------
// Copyright (C) 2015. Lynn Jarvis, Leading Edge. Pty. Ltd.
// Ported to OSX by Amaury Hazan (amaury@billaboop.com)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You will receive a copy of the GNU Lesser General Public License along
// with this program. If not, see http://www.gnu.org/licenses/.
// --------------------------------------------------------------
//
#pragma once
#ifndef ShaderMaker_H
#define ShaderMaker_H
#include <stdio.h>
#include <string>
#include <time.h> // for date
#include "FFGL.h" // windows : msvc project needs the FFGL folder in its include path
#include "FFGLLib.h"
#include "FFGLShader.h"
#include "FFGLPluginSDK.h"
#if (!(defined(WIN32) || defined(_WIN32) || defined(__WIN32__)))
// posix
typedef uint8_t CHAR;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef int8_t BYTE;
typedef int16_t SHORT;
typedef int32_t LONG;
typedef LONG INT;
typedef INT BOOL;
typedef int64_t __int64;
typedef int64_t LARGE_INTEGER;
#include <ctime>
#include <chrono> // c++11 timer
#endif
#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
#define GL_TEXTURE_WRAP_R 0x8072
class ShaderMaker : public CFreeFrameGLPlugin
{
public:
ShaderMaker();
~ShaderMaker();
///////////////////////////////////////////////////
// FreeFrameGL plugin methods
///////////////////////////////////////////////////
FFResult SetFloatParameter(unsigned int index, float value);
float GetFloatParameter(unsigned int index);
FFResult ProcessOpenGL(ProcessOpenGLStruct* pGL);
FFResult InitGL(const FFGLViewportStruct *vp);
FFResult DeInitGL();
FFResult GetInputStatus(DWORD dwIndex);
char * GetParameterDisplay(DWORD dwIndex);
///////////////////////////////////////////////////
// Factory method
///////////////////////////////////////////////////
static FFResult __stdcall CreateInstance(CFreeFrameGLPlugin **ppOutInstance) {
*ppOutInstance = new ShaderMaker();
if (*ppOutInstance != NULL)
return FF_SUCCESS;
return FF_FAIL;
}
protected:
// FFGL user parameters
char m_DisplayValue[16];
float m_UserSpeed;
float m_UserMouseX;
float m_UserMouseY;
float m_UserMouseLeftX;
float m_UserMouseLeftY;
float m_UserRed;
float m_UserGreen;
float m_UserBlue;
float m_UserAlpha;
// Flags
bool bInitialized;
// Local fbo and texture
GLuint m_glTexture0;
GLuint m_glTexture1;
GLuint m_glTexture2;
GLuint m_glTexture3;
GLuint m_fbo;
// Viewport
float m_vpWidth;
float m_vpHeight;
// Time
double elapsedTime, lastTime;
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
// windows
double PCFreq;
__int64 CounterStart;
#else
// posix c++11
std::chrono::steady_clock::time_point start;
std::chrono::steady_clock::time_point end;
#endif
//
// Shader uniforms
//
// Time
float m_time;
// Date (year, month, day, time in seconds)
float m_dateYear;
float m_dateMonth;
float m_dateDay;
float m_dateTime;
// Channel playback time (in seconds)
// iChannelTime components are always equal to iGlobalTime
float m_channelTime[4];
// Channel resolution in pixels - 4 channels with width, height, depth each
float m_channelResolution[4][3];
// Mouse
float m_mouseX;
float m_mouseY;
// Mouse left and right
float m_mouseLeftX;
float m_mouseLeftY;
float m_mouseRightX;
float m_mouseRightY;
// New ShaderToy uniforms 21-11-17
// iTime - m_time - the same as iGlobalTime
float m_frame; // iFrame - frame number
float m_timedelta; // iTimeDelta - time elapsed since last frame
float m_framerate; // iFrameRate - 1.f / _deltaTime
float m_samplerate;
int m_initResources;
FFGLExtensions m_extensions;
FFGLShader m_shader;
GLint m_inputTextureLocation;
GLint m_inputTextureLocation1;
GLint m_inputTextureLocation2;
GLint m_inputTextureLocation3;
GLint m_timeLocation;
GLint m_dateLocation;
GLint m_channeltimeLocation;
GLint m_channelresolutionLocation;
GLint m_mouseLocation;
GLint m_resolutionLocation;
GLint m_mouseLocationVec4;
GLint m_screenLocation;
GLint m_surfaceSizeLocation;
GLint m_surfacePositionLocation;
GLint m_vertexPositionLocation;
// New ShaderToy uniforms 21-11-17
// iTime - m_timeLocation - the same as iGlobalTime
GLint m_frameLocation; // iFrame - frame number
GLint m_timedeltaLocation; // iTimeDelta - time elapsed since last frame
GLint m_framerateLocation; // iFrameRate - 1.f / _deltaTime
GLint m_samplerateLocation; // iSampleRate - 44100.f default
// Extras
GLint m_inputColourLocation;
void SetDefaults();
void StartCounter();
double GetCounter();
bool LoadShader(std::string shaderString);
void CreateRectangleTexture(FFGLTextureStruct Texture, FFGLTexCoords maxCoords, GLuint &glTexture, GLenum texunit, GLuint &fbo, GLuint hostFbo);
};
#endif