-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyPlugin.h
More file actions
185 lines (157 loc) · 4.98 KB
/
MyPlugin.h
File metadata and controls
185 lines (157 loc) · 4.98 KB
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
//
// Created by Darren Mothersele on 05/09/2016.
//
#ifndef FFGLPLUGIN_MYPLUGIN_H
#define FFGLPLUGIN_MYPLUGIN_H
#include <FFGLPluginSDK.h>
#include <FFGLExtensions.h>
#include <FFGLShader.h>
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>
#include <FFGLLib.h>
#define FFGL_PLUGIN(CLASS,CODE,NAME,TYPE,DESC,ABOUT) \
static CFFGLPluginInfo PluginInfo (MyPlugin<CLASS>::CreateInstance, \
CODE,NAME,1,000,1,000,TYPE,DESC,ABOUT);
char *vertexShaderCode =
"void main()"
"{"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
" gl_TexCoord[1] = gl_MultiTexCoord1;"
" gl_FrontColor = gl_Color;"
"}";
class PluginParamInfo {
public:
std::string name;
DWORD type;
float defaultValue;
PluginParamInfo(std::string n, DWORD t, float d) : name(n), type(t), defaultValue(d) {}
};
class PluginConfig {
public:
std::vector<std::string> inputNames;
std::vector<PluginParamInfo> params;
std::string shaderCode;
};
template <class FX>
class MyPlugin : public CFreeFrameGLPlugin {
FX fx;
PluginConfig config;
std::unordered_map<std::string,DWORD> paramMap;
std::vector<float> paramValues;
DWORD paramCount;
DWORD inputCount;
std::vector<GLint> textureLocations;
public:
MyPlugin() {
fx = FX();
config = fx.getConfig();
SetMinInputs(static_cast<int>(config.inputNames.size()));
SetMaxInputs(static_cast<int>(config.inputNames.size()));
paramCount = 0;
for (auto i : config.params)
{
paramMap.insert({i.name, paramCount});
SetParamInfo(paramCount, i.name.c_str(), i.type, i.defaultValue);
paramCount++;
}
paramValues.reserve(paramCount);
inputCount = config.inputNames.size();
}
~MyPlugin() {}
DWORD ProcessOpenGL(ProcessOpenGLStruct* pGL)
{
if (pGL->numInputTextures < inputCount) return FF_FAIL;
shader.BindShader();
if (inputCount > 0)
{
FFGLTextureStruct &Texture = *(pGL->inputTextures[0]);
extensions.glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Texture.Handle);
FFGLTexCoords maxCoords = GetMaxGLTexCoords(Texture);
fx.process(paramValues, extensions);
// glEnable(GL_TEXTURE_2D);
// glBegin(GL_QUADS);
// glTexCoord2f(0.0, 0.0);
// glVertex2f(-1.0f, -1.0f);
// glTexCoord2f(0.0, 1.0);
// glVertex2f(-1.0f, 1.0);
// glTexCoord2f(1.0, 1.0);
// glVertex2f( 1.0, 1.0);
// glTexCoord2f(1.0, 0.0);
// glVertex2f( 1.0, -1.0f);
// glEnd();
// glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
//lower left
glTexCoord2f(0,0);
glVertex2f(-1,-1);
//upper left
glTexCoord2f(0, maxCoords.t);
glVertex2f(-1,1);
//upper right
glTexCoord2f(maxCoords.s, maxCoords.t);
glVertex2f(1,1);
//lower right
glTexCoord2f(maxCoords.s, 0);
glVertex2f(1,-1);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
}
else
{
fx.process(paramValues, extensions);
glBegin(GL_QUADS);
glVertex2f(-1.0f, -1.0f);
glVertex2f(-1.0f, 1.0);
glVertex2f( 1.0, 1.0);
glVertex2f( 1.0, -1.0f);
glEnd();
}
shader.UnbindShader();
return FF_SUCCESS;
}
DWORD InitGL(const FFGLViewportStruct *vp)
{
extensions.Initialize();
if (extensions.multitexture==0 || extensions.ARB_shader_objects==0)
return FF_FAIL;
shader.SetExtensions(&extensions);
shader.Compile(vertexShaderCode,config.shaderCode.c_str());
shader.BindShader();
for (auto i : config.inputNames)
{
GLint texLoc = shader.FindUniform(i.c_str());
textureLocations.push_back(texLoc);
extensions.glUniform1iARB(texLoc, 0);
}
fx.init(shader);
shader.UnbindShader();
return FF_SUCCESS;
}
DWORD DeInitGL()
{
shader.FreeGLResources();
return FF_SUCCESS;
}
DWORD SetParameter(const SetParameterStruct* pParam) {
if (pParam != NULL) {
if (pParam->ParameterNumber < paramCount) {
paramValues[pParam->ParameterNumber] = *((float *)(unsigned)&(pParam->NewParameterValue));
return FF_SUCCESS;
}
}
return FF_FAIL;
}
static DWORD __stdcall CreateInstance(CFreeFrameGLPlugin **ppOutInstance) {
*ppOutInstance = new MyPlugin();
if (*ppOutInstance != NULL)
return FF_SUCCESS;
return FF_FAIL;
}
FFGLExtensions extensions;
FFGLShader shader;
};
#endif //FFGLPLUGIN_MYPLUGIN_H