├── CMakeLists.txt ├── EmptyEffect.cpp ├── EmptyEffect.h ├── EvilShader.cpp ├── EvilShader.h ├── LICENSE.md ├── MyPlugin.h ├── Noise.cpp ├── Noise.h ├── Plasma.cpp ├── Plasma.h ├── README.md ├── Spiral.cpp ├── Spiral.h ├── Springs.cpp ├── Springs.h ├── UnderwaterLife.cpp ├── UnderwaterLife.h ├── ffgl-host ├── CMakeLists.txt ├── License.txt ├── OSXDebugMessage.cpp ├── OSXPluginInstance.cpp ├── OSXTimer.cpp ├── README.txt ├── lib │ └── ffgl │ │ ├── FFDebugMessage.h │ │ ├── FFGL.cpp │ │ ├── FFGL.h │ │ ├── FFGLExtensions.cpp │ │ ├── FFGLExtensions.h │ │ ├── FFGLFBO.cpp │ │ ├── FFGLFBO.h │ │ ├── FFGLLib.h │ │ ├── FFGLPluginInfo.cpp │ │ ├── FFGLPluginInfo.h │ │ ├── FFGLPluginInfoData.cpp │ │ ├── FFGLPluginInstance.cpp │ │ ├── FFGLPluginInstance.h │ │ ├── FFGLPluginManager.cpp │ │ ├── FFGLPluginManager.h │ │ ├── FFGLPluginManager_inl.h │ │ ├── FFGLPluginSDK.cpp │ │ ├── FFGLPluginSDK.h │ │ ├── FFGLShader.cpp │ │ ├── FFGLShader.h │ │ ├── FreeFrame.h │ │ └── Timer.h └── main.cpp └── img ├── Evil.png ├── Noise-params.png ├── Noise.png ├── Plasma-params.png ├── Plasma.png ├── RGBSource-params.png ├── RGBSource.png ├── Spiral.png ├── Springs.png ├── UnderwaterLife.png └── resolume-config.png /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project(FFGLPlugin) 3 | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTARGET_OS_MAC -std=c++11 -stdlib=libc++ -arch i386") 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-writable-strings") 6 | 7 | find_package(OpenGL REQUIRED) 8 | 9 | add_subdirectory(ffgl-host) 10 | include_directories(ffgl-host/lib/ffgl) 11 | 12 | set(FFGL_PLUGIN_FILES 13 | ffgl-host/lib/ffgl/FFGL.cpp 14 | ffgl-host/lib/ffgl/FFGLPluginInfo.cpp 15 | ffgl-host/lib/ffgl/FFGLPluginInfoData.cpp 16 | ffgl-host/lib/ffgl/FFGLPluginManager.cpp 17 | ffgl-host/lib/ffgl/FFGLPluginSDK.cpp 18 | ffgl-host/lib/ffgl/FFGLShader.cpp 19 | ffgl-host/lib/ffgl/FFGLExtensions.cpp 20 | ) 21 | 22 | add_library(RGBSource MODULE EmptyEffect.cpp MyPlugin.h ${FFGL_PLUGIN_FILES}) 23 | target_link_libraries(RGBSource ${OPENGL_LIBRARIES}) 24 | set_target_properties(RGBSource PROPERTIES BUNDLE true) 25 | 26 | add_library(EvilShader MODULE EvilShader.cpp ${FFGL_PLUGIN_FILES}) 27 | target_link_libraries(EvilShader ${OPENGL_LIBRARIES}) 28 | set_target_properties(EvilShader PROPERTIES BUNDLE true) 29 | 30 | add_library(UnderwaterLife MODULE UnderwaterLife.cpp ${FFGL_PLUGIN_FILES}) 31 | target_link_libraries(UnderwaterLife ${OPENGL_LIBRARIES}) 32 | set_target_properties(UnderwaterLife PROPERTIES BUNDLE true) 33 | 34 | add_library(Spiral MODULE Spiral.cpp ${FFGL_PLUGIN_FILES}) 35 | target_link_libraries(Spiral ${OPENGL_LIBRARIES}) 36 | set_target_properties(Spiral PROPERTIES BUNDLE true) 37 | 38 | add_library(Plasma MODULE Plasma.cpp ${FFGL_PLUGIN_FILES}) 39 | target_link_libraries(Plasma ${OPENGL_LIBRARIES}) 40 | set_target_properties(Plasma PROPERTIES BUNDLE true) 41 | 42 | add_library(Noise MODULE Noise.cpp ${FFGL_PLUGIN_FILES}) 43 | target_link_libraries(Noise ${OPENGL_LIBRARIES}) 44 | set_target_properties(Noise PROPERTIES BUNDLE true) 45 | 46 | add_library(Springs MODULE Springs.cpp ${FFGL_PLUGIN_FILES}) 47 | target_link_libraries(Springs ${OPENGL_LIBRARIES}) 48 | set_target_properties(Springs PROPERTIES BUNDLE true) 49 | -------------------------------------------------------------------------------- /EmptyEffect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #include "EmptyEffect.h" 19 | 20 | 21 | FFGL_PLUGIN(EmptyEffect,"DZ00","RGB Source",FF_SOURCE,"Sample FFGL Plugin", 22 | "by Darren Mothersele - www.darrenmothersele.com") 23 | 24 | 25 | std::string fragmentShaderCode = R"GLSL( 26 | uniform vec3 color; 27 | void main() 28 | { 29 | gl_FragColor = vec4(color,1); 30 | } 31 | )GLSL"; 32 | 33 | PluginConfig EmptyEffect::getConfig() { 34 | PluginConfig pluginConfig; 35 | pluginConfig.shaderCode = fragmentShaderCode; 36 | pluginConfig.params.push_back({"Red", FF_TYPE_STANDARD, 0.5f}); 37 | pluginConfig.params.push_back({"Green", FF_TYPE_STANDARD, 0.5f}); 38 | pluginConfig.params.push_back({"Blue", FF_TYPE_STANDARD, 0.5f}); 39 | return pluginConfig; 40 | } 41 | 42 | void EmptyEffect::init(FFGLShader &shader) { 43 | colorLocation = shader.FindUniform("color"); 44 | } 45 | 46 | void EmptyEffect::process(std::vector ¶mValues, FFGLExtensions &extensions) 47 | { 48 | extensions.glUniform3fARB(colorLocation, paramValues[0], paramValues[1], paramValues[2]); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /EmptyEffect.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #ifndef FFGLPLUGIN_EMPTYEFFECT_H 19 | #define FFGLPLUGIN_EMPTYEFFECT_H 20 | 21 | #include "MyPlugin.h" 22 | 23 | class EmptyEffect { 24 | 25 | float redness = 0.5f; 26 | float greenness = 0.5f; 27 | float blueness = 0.5f; 28 | GLint colorLocation; 29 | 30 | public: 31 | PluginConfig getConfig(); 32 | 33 | void init(FFGLShader &shader); 34 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 35 | 36 | }; 37 | 38 | 39 | #endif //FFGLPLUGIN_EMPTYEFFECT_H 40 | -------------------------------------------------------------------------------- /EvilShader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | #include "EvilShader.h" 18 | 19 | FFGL_PLUGIN(EvilShader,"DZEV","Evil",FF_EFFECT,"Sample FFGL Plugin", 20 | "by Darren Mothersele - www.darrenmothersele.com") 21 | 22 | 23 | std::string fragmentShaderCode = R"GLSL( 24 | // Adapted from https://www.shadertoy.com/view/llS3WG 25 | 26 | uniform vec3 iResolution; 27 | uniform sampler2D iChannel0; 28 | 29 | #define T texture2D(iChannel0,.5+(p.xy*=.98)) 30 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 31 | { 32 | vec3 p=gl_FragCoord.xyz/iResolution-.5, o=T.rbb; 33 | for (float i=0.;i<50.;i++) p.z+=pow(max(0.,.5-length(T.rg)),2.)*exp(-i*.1); 34 | fragColor=vec4(o*o+p.z,1); 35 | } 36 | void main(void) { 37 | mainImage(gl_FragColor, gl_FragCoord.xy); 38 | } 39 | 40 | )GLSL"; 41 | 42 | 43 | PluginConfig EvilShader::getConfig() { 44 | PluginConfig pluginConfig; 45 | pluginConfig.shaderCode = fragmentShaderCode; 46 | pluginConfig.params.push_back({"Speed", FF_TYPE_STANDARD, 0.5f}); 47 | pluginConfig.inputNames.push_back({"iChannel0"}); 48 | return pluginConfig; 49 | } 50 | 51 | void EvilShader::init(FFGLShader &shader) { 52 | resValueLocation = shader.FindUniform("iResolution"); 53 | } 54 | 55 | void EvilShader::process(std::vector ¶mValues, FFGLExtensions &extensions) 56 | { 57 | float vpdim[4]; 58 | glGetFloatv(GL_VIEWPORT, vpdim); 59 | extensions.glUniform3fARB(resValueLocation, vpdim[2], vpdim[3], 1.0); 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /EvilShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #ifndef FFGLPLUGIN_EVILSHADER_H 19 | #define FFGLPLUGIN_EVILSHADER_H 20 | 21 | #include "MyPlugin.h" 22 | 23 | class EvilShader { 24 | 25 | GLint resValueLocation; 26 | GLint inputTextureLocation; 27 | 28 | public: 29 | PluginConfig getConfig(); 30 | 31 | void init(FFGLShader &shader); 32 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 33 | 34 | 35 | }; 36 | 37 | 38 | #endif //FFGLPLUGIN_EVILSHADER_H 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2016 Darren Mothersele 2 | This work is free. You can redistribute it and/or modify it under the 3 | terms of the Do What The Fuck You Want To Public License, Version 2, 4 | as published by Sam Hocevar. 5 | 6 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 7 | Version 2, December 2004 8 | 9 | Copyright (C) 2004 Sam Hocevar 10 | 11 | Everyone is permitted to copy and distribute verbatim or modified 12 | copies of this license document, and changing it is allowed as long 13 | as the name is changed. 14 | 15 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 16 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 17 | 18 | 0. You just DO WHAT THE FUCK YOU WANT TO. 19 | -------------------------------------------------------------------------------- /MyPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | #ifndef FFGLPLUGIN_MYPLUGIN_H 18 | #define FFGLPLUGIN_MYPLUGIN_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define FFGL_PLUGIN(CLASS,CODE,NAME,TYPE,DESC,ABOUT) \ 30 | static CFFGLPluginInfo PluginInfo (MyPlugin::CreateInstance, \ 31 | CODE,NAME,1,000,1,000,TYPE,DESC,ABOUT); 32 | 33 | char *vertexShaderCode = 34 | "void main()" 35 | "{" 36 | " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" 37 | " gl_TexCoord[1] = gl_MultiTexCoord1;" 38 | " gl_FrontColor = gl_Color;" 39 | "}"; 40 | 41 | class PluginParamInfo { 42 | public: 43 | std::string name; 44 | DWORD type; 45 | float defaultValue; 46 | PluginParamInfo(std::string n, DWORD t, float d) : name(n), type(t), defaultValue(d) {} 47 | }; 48 | 49 | class PluginConfig { 50 | public: 51 | std::vector inputNames; 52 | std::vector params; 53 | std::string shaderCode; 54 | }; 55 | 56 | template 57 | class MyPlugin : public CFreeFrameGLPlugin { 58 | FX fx; 59 | PluginConfig config; 60 | std::unordered_map paramMap; 61 | std::vector paramValues; 62 | DWORD paramCount; 63 | DWORD inputCount; 64 | std::vector textureLocations; 65 | 66 | public: 67 | MyPlugin() { 68 | fx = FX(); 69 | config = fx.getConfig(); 70 | SetMinInputs(static_cast(config.inputNames.size())); 71 | SetMaxInputs(static_cast(config.inputNames.size())); 72 | paramCount = 0; 73 | for (auto i : config.params) 74 | { 75 | paramMap.insert({i.name, paramCount}); 76 | SetParamInfo(paramCount, i.name.c_str(), i.type, i.defaultValue); 77 | paramCount++; 78 | } 79 | paramValues.reserve(paramCount); 80 | inputCount = config.inputNames.size(); 81 | } 82 | ~MyPlugin() {} 83 | 84 | DWORD ProcessOpenGL(ProcessOpenGLStruct* pGL) 85 | { 86 | if (pGL->numInputTextures < inputCount) return FF_FAIL; 87 | 88 | shader.BindShader(); 89 | 90 | if (inputCount > 0) 91 | { 92 | FFGLTextureStruct &Texture = *(pGL->inputTextures[0]); 93 | extensions.glActiveTexture(GL_TEXTURE0); 94 | glBindTexture(GL_TEXTURE_2D, Texture.Handle); 95 | FFGLTexCoords maxCoords = GetMaxGLTexCoords(Texture); 96 | 97 | fx.process(paramValues, extensions); 98 | 99 | glEnable(GL_TEXTURE_2D); 100 | 101 | glBegin(GL_QUADS); 102 | 103 | //lower left 104 | glTexCoord2f(0,0); 105 | glVertex2f(-1,-1); 106 | 107 | //upper left 108 | glTexCoord2f(0, maxCoords.t); 109 | glVertex2f(-1,1); 110 | 111 | //upper right 112 | glTexCoord2f(maxCoords.s, maxCoords.t); 113 | glVertex2f(1,1); 114 | 115 | //lower right 116 | glTexCoord2f(maxCoords.s, 0); 117 | glVertex2f(1,-1); 118 | glEnd(); 119 | 120 | glBindTexture(GL_TEXTURE_2D, 0); 121 | } 122 | else 123 | { 124 | fx.process(paramValues, extensions); 125 | glBegin(GL_QUADS); 126 | glVertex2f(-1.0f, -1.0f); 127 | glVertex2f(-1.0f, 1.0); 128 | glVertex2f( 1.0, 1.0); 129 | glVertex2f( 1.0, -1.0f); 130 | glEnd(); 131 | } 132 | 133 | shader.UnbindShader(); 134 | return FF_SUCCESS; 135 | } 136 | DWORD InitGL(const FFGLViewportStruct *vp) 137 | { 138 | extensions.Initialize(); 139 | if (extensions.multitexture==0 || extensions.ARB_shader_objects==0) 140 | return FF_FAIL; 141 | 142 | shader.SetExtensions(&extensions); 143 | shader.Compile(vertexShaderCode,config.shaderCode.c_str()); 144 | shader.BindShader(); 145 | for (auto i : config.inputNames) 146 | { 147 | GLint texLoc = shader.FindUniform(i.c_str()); 148 | textureLocations.push_back(texLoc); 149 | extensions.glUniform1iARB(texLoc, 0); 150 | } 151 | fx.init(shader); 152 | shader.UnbindShader(); 153 | return FF_SUCCESS; 154 | } 155 | DWORD DeInitGL() 156 | { 157 | shader.FreeGLResources(); 158 | return FF_SUCCESS; 159 | } 160 | 161 | DWORD SetParameter(const SetParameterStruct* pParam) { 162 | if (pParam != NULL) { 163 | if (pParam->ParameterNumber < paramCount) { 164 | paramValues[pParam->ParameterNumber] = *((float *)(unsigned)&(pParam->NewParameterValue)); 165 | return FF_SUCCESS; 166 | } 167 | } 168 | return FF_FAIL; 169 | } 170 | 171 | static DWORD __stdcall CreateInstance(CFreeFrameGLPlugin **ppOutInstance) { 172 | *ppOutInstance = new MyPlugin(); 173 | if (*ppOutInstance != NULL) 174 | return FF_SUCCESS; 175 | return FF_FAIL; 176 | } 177 | 178 | FFGLExtensions extensions; 179 | FFGLShader shader; 180 | }; 181 | 182 | 183 | #endif //FFGLPLUGIN_MYPLUGIN_H 184 | 185 | -------------------------------------------------------------------------------- /Noise.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | #include "Noise.h" 18 | 19 | FFGL_PLUGIN(Noise,"DZNZ","Noise",FF_SOURCE,"Sample FFGL Plugin", 20 | "by Darren Mothersele - www.darrenmothersele.com") 21 | 22 | 23 | std::string fragmentShaderCode = R"GLSL( 24 | 25 | uniform float blur; 26 | uniform float voronoi; 27 | uniform vec3 iResolution; 28 | uniform float noiseSize; 29 | 30 | vec3 hash3( vec2 p ) 31 | { 32 | vec3 q = vec3( dot(p,vec2(127.1,311.7)), 33 | dot(p,vec2(269.5,183.3)), 34 | dot(p,vec2(419.2,371.9)) ); 35 | return fract(sin(q)*43758.5453); 36 | } 37 | 38 | float iqnoise( in vec2 x, float u, float v ) 39 | { 40 | vec2 p = floor(x); 41 | vec2 f = fract(x); 42 | 43 | float k = 1.0+63.0*pow(1.0-v,4.0); 44 | 45 | float va = 0.0; 46 | float wt = 0.0; 47 | for( int j=-2; j<=2; j++ ) 48 | for( int i=-2; i<=2; i++ ) 49 | { 50 | vec2 g = vec2( float(i),float(j) ); 51 | vec3 o = hash3( p + g )*vec3(u,u,1.0); 52 | vec2 r = g - f + o.xy; 53 | float d = dot(r,r); 54 | float ww = pow( 1.0-smoothstep(0.0,1.414,sqrt(d)), k ); 55 | va += o.z*ww; 56 | wt += ww; 57 | } 58 | 59 | return va/wt; 60 | } 61 | 62 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 63 | { 64 | vec2 uv = fragCoord.xy / iResolution.xx; 65 | vec2 p = vec2(voronoi, blur); 66 | float f = iqnoise( noiseSize*uv, p.x, p.y ); 67 | fragColor = vec4( f, f, f, 1.0 ); 68 | } 69 | 70 | void main(void) { 71 | mainImage(gl_FragColor, gl_FragCoord.xy); 72 | } 73 | 74 | )GLSL"; 75 | 76 | PluginConfig Noise::getConfig() { 77 | PluginConfig pluginConfig; 78 | pluginConfig.shaderCode = fragmentShaderCode; 79 | pluginConfig.params.push_back({"Voronoi", FF_TYPE_STANDARD, 0.5f}); 80 | pluginConfig.params.push_back({"Blur", FF_TYPE_STANDARD, 0.5f}); 81 | pluginConfig.params.push_back({"Size", FF_TYPE_STANDARD, 0.5f}); 82 | pluginConfig.inputNames.push_back({"iChannel0"}); 83 | return pluginConfig; 84 | } 85 | 86 | void Noise::init(FFGLShader &shader) { 87 | sizeLocation = shader.FindUniform("noiseSize"); 88 | resolutionLocation = shader.FindUniform("iResolution"); 89 | blurLocation = shader.FindUniform("blur"); 90 | voronoiLocation = shader.FindUniform("voronoi"); 91 | } 92 | 93 | void Noise::process(std::vector ¶mValues, FFGLExtensions &extensions) 94 | { 95 | float vpdim[4]; 96 | glGetFloatv(GL_VIEWPORT, vpdim); 97 | extensions.glUniform3fARB(resolutionLocation, vpdim[2], vpdim[3], 1.0); 98 | 99 | extensions.glUniform1fARB(voronoiLocation, paramValues[0]); 100 | extensions.glUniform1fARB(blurLocation, paramValues[1]); 101 | extensions.glUniform1fARB(sizeLocation, paramValues[2] * 128.0f); 102 | 103 | } 104 | 105 | -------------------------------------------------------------------------------- /Noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #ifndef FFGLPLUGIN_NOISE_H 19 | #define FFGLPLUGIN_NOISE_H 20 | 21 | 22 | #include "MyPlugin.h" 23 | #include 24 | 25 | 26 | class Noise { 27 | GLint resolutionLocation; 28 | GLint sizeLocation; 29 | GLint voronoiLocation; 30 | GLint blurLocation; 31 | 32 | public: 33 | PluginConfig getConfig(); 34 | 35 | void init(FFGLShader &shader); 36 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 37 | }; 38 | 39 | 40 | #endif //FFGLPLUGIN_NOISE_H 41 | -------------------------------------------------------------------------------- /Plasma.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | #include "Plasma.h" 18 | 19 | 20 | 21 | FFGL_PLUGIN(Plasma,"DZPL","Plasma Ball",FF_EFFECT,"Sample FFGL Plugin", 22 | "by Darren Mothersele - www.darrenmothersele.com") 23 | 24 | 25 | std::string fragmentShaderCode = R"GLSL( 26 | 27 | uniform vec3 iResolution; 28 | uniform float iGlobalTime; 29 | uniform vec4 iMouse; 30 | uniform sampler2D iChannel0; 31 | 32 | //Plasma Globe by nimitz (twitter: @stormoid) 33 | 34 | //looks best with around 25 rays 35 | #define NUM_RAYS 13. 36 | 37 | #define VOLUMETRIC_STEPS 19 38 | 39 | #define MAX_ITER 35 40 | #define FAR 6. 41 | 42 | #define time iGlobalTime*1.1 43 | 44 | 45 | mat2 mm2(in float a){float c = cos(a), s = sin(a);return mat2(c,-s,s,c);} 46 | float noise( in float x ){return texture2D(iChannel0, vec2(x*.01,1.)).x;} 47 | 48 | 49 | 50 | float hash( float n ){return fract(sin(n)*43758.5453);} 51 | 52 | //iq's ubiquitous 3d noise 53 | float noise(in vec3 p) 54 | { 55 | vec3 ip = floor(p); 56 | vec3 f = fract(p); 57 | f = f*f*(3.0-2.0*f); 58 | 59 | vec2 uv = (ip.xy+vec2(37.0,17.0)*ip.z) + f.xy; 60 | vec2 rg = texture2D( iChannel0, (uv+ 0.5)/256.0, -100.0 ).yx; 61 | return mix(rg.x, rg.y, f.z); 62 | } 63 | 64 | mat3 m3 = mat3( 0.00, 0.80, 0.60, 65 | -0.80, 0.36, -0.48, 66 | -0.60, -0.48, 0.64 ); 67 | 68 | 69 | //See: https://www.shadertoy.com/view/XdfXRj 70 | float flow(in vec3 p, in float t) 71 | { 72 | float z=2.; 73 | float rz = 0.; 74 | vec3 bp = p; 75 | for (float i= 1.;i < 5.;i++ ) 76 | { 77 | p += time*.1; 78 | rz+= (sin(noise(p+t*0.8)*6.)*0.5+0.5) /z; 79 | p = mix(bp,p,0.6); 80 | z *= 2.; 81 | p *= 2.01; 82 | p*= m3; 83 | } 84 | return rz; 85 | } 86 | 87 | //could be improved 88 | float sins(in float x) 89 | { 90 | float rz = 0.; 91 | float z = 2.; 92 | for (float i= 0.;i < 3.;i++ ) 93 | { 94 | rz += abs(fract(x*1.4)-0.5)/z; 95 | x *= 1.3; 96 | z *= 1.15; 97 | x -= time*.65*z; 98 | } 99 | return rz; 100 | } 101 | 102 | float segm( vec3 p, vec3 a, vec3 b) 103 | { 104 | vec3 pa = p - a; 105 | vec3 ba = b - a; 106 | float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1. ); 107 | return length( pa - ba*h )*.5; 108 | } 109 | 110 | vec3 path(in float i, in float d) 111 | { 112 | vec3 en = vec3(0.,0.,1.); 113 | float sns2 = sins(d+i*0.5)*0.22; 114 | float sns = sins(d+i*.6)*0.21; 115 | en.xz *= mm2((hash(i*10.569)-.5)*6.2+sns2); 116 | en.xy *= mm2((hash(i*4.732)-.5)*6.2+sns); 117 | return en; 118 | } 119 | 120 | vec2 map(vec3 p, float i) 121 | { 122 | float lp = length(p); 123 | vec3 bg = vec3(0.); 124 | vec3 en = path(i,lp); 125 | 126 | float ins = smoothstep(0.11,.46,lp); 127 | float outs = .15+smoothstep(.0,.15,abs(lp-1.)); 128 | p *= ins*outs; 129 | float id = ins*outs; 130 | 131 | float rz = segm(p, bg, en)-0.011; 132 | return vec2(rz,id); 133 | } 134 | 135 | float march(in vec3 ro, in vec3 rd, in float startf, in float maxd, in float j) 136 | { 137 | float precis = 0.001; 138 | float h=0.5; 139 | float d = startf; 140 | for( int i=0; imaxd ) break; 143 | d += h*1.2; 144 | float res = map(ro+rd*d, j).x; 145 | h = res; 146 | } 147 | return d; 148 | } 149 | 150 | //volumetric marching 151 | vec3 vmarch(in vec3 ro, in vec3 rd, in float j, in vec3 orig) 152 | { 153 | vec3 p = ro; 154 | vec2 r = vec2(0.); 155 | vec3 sum = vec3(0); 156 | float w = 0.; 157 | for( int i=0; i= FAR)continue; 211 | vec3 pos = ro+rz*rd; 212 | col = max(col,vmarch(pos,rd,j, bro)); 213 | } 214 | #endif 215 | 216 | ro = bro; 217 | rd = brd; 218 | vec2 sph = iSphere2(ro,rd); 219 | 220 | if (sph.x > 0.) 221 | { 222 | vec3 pos = ro+rd*sph.x; 223 | vec3 pos2 = ro+rd*sph.y; 224 | vec3 rf = reflect( rd, pos ); 225 | vec3 rf2 = reflect( rd, pos2 ); 226 | float nz = (-log(abs(flow(rf*1.2,time)-.01))); 227 | float nz2 = (-log(abs(flow(rf2*1.2,-time)-.01))); 228 | col += (0.1*nz*nz* vec3(0.12,0.12,.5) + 0.05*nz2*nz2*vec3(0.55,0.2,.55))*0.8; 229 | } 230 | 231 | fragColor = vec4(col*1.3, 1.0); 232 | } 233 | 234 | void main(void) { 235 | mainImage(gl_FragColor, gl_FragCoord.xy); 236 | } 237 | 238 | )GLSL"; 239 | 240 | 241 | PluginConfig Plasma::getConfig() { 242 | PluginConfig pluginConfig; 243 | pluginConfig.shaderCode = fragmentShaderCode; 244 | pluginConfig.params.push_back({"Speed", FF_TYPE_STANDARD, 0.5f}); 245 | pluginConfig.params.push_back({"Pos X", FF_TYPE_STANDARD, 0.5f}); 246 | pluginConfig.params.push_back({"Pos Y", FF_TYPE_STANDARD, 0.5f}); 247 | pluginConfig.inputNames.push_back({"iChannel0"}); 248 | return pluginConfig; 249 | } 250 | 251 | void Plasma::init(FFGLShader &shader) { 252 | timeLocation = shader.FindUniform("iGlobalTime"); 253 | resolutionLocation = shader.FindUniform("iResolution"); 254 | mouseLocation = shader.FindUniform("iMouse"); 255 | start = std::chrono::steady_clock::now(); 256 | } 257 | 258 | void Plasma::process(std::vector ¶mValues, FFGLExtensions &extensions) 259 | { 260 | float vpdim[4]; 261 | glGetFloatv(GL_VIEWPORT, vpdim); 262 | extensions.glUniform3fARB(resolutionLocation, vpdim[2], vpdim[3], 1.0); 263 | 264 | double lastTime = elapsedTime; 265 | elapsedTime = GetCounter()/1000.0; 266 | globalTime = globalTime + (float)(elapsedTime-lastTime) * (paramValues[0] - 0.5f) * 8.0f; 267 | extensions.glUniform1fARB(timeLocation, globalTime); 268 | 269 | extensions.glUniform4fARB(mouseLocation, paramValues[1] * vpdim[2], paramValues[2] * vpdim[3], 0, 0); 270 | } 271 | 272 | 273 | double Plasma::GetCounter() 274 | { 275 | end = std::chrono::steady_clock::now(); 276 | return std::chrono::duration_cast(end - start).count()/1000.; 277 | } 278 | -------------------------------------------------------------------------------- /Plasma.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #ifndef FFGLPLUGIN_PLASMA_H 19 | #define FFGLPLUGIN_PLASMA_H 20 | 21 | 22 | #include "MyPlugin.h" 23 | #include 24 | 25 | 26 | class Plasma { 27 | GLint resolutionLocation; 28 | GLint timeLocation; 29 | GLint mouseLocation; 30 | 31 | double elapsedTime; 32 | float globalTime; 33 | std::chrono::steady_clock::time_point start; 34 | std::chrono::steady_clock::time_point end; 35 | 36 | public: 37 | PluginConfig getConfig(); 38 | 39 | void init(FFGLShader &shader); 40 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 41 | 42 | double GetCounter(); 43 | }; 44 | 45 | 46 | 47 | #endif //FFGLPLUGIN_PLASMA_H 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #FFGL Plugins 2 | 3 | Framework for creating FFGL plugins for Resolume. 4 | 5 | 6 | ## Usage 7 | 8 | MyPlugin.h abstracts some of the repetative stuff you have to do when 9 | creating FFGL plugins. 10 | 11 | See EmptyEffect for most basic use case. 12 | 13 | Compile as 32-bit for Resolume compatibility. 14 | 15 | ## Installation 16 | 17 | Download from the [Releases page](https://github.com/cyrilcode/ffglplugin-examples/releases). 18 | 19 | Copy the compiled `*.bundle` files into your Resolume plugins folder. 20 | Or preferably, create a new folder and link to it in the Resolume config. 21 | 22 | ![Resolume Plugin Config](/img/resolume-config.png?raw=true) 23 | 24 | ## Examples 25 | 26 | ### Noise 27 | 28 | ![Noise](/img/Noise-params.png?raw=true) 29 | ![Noise](/img/Noise.png?raw=true) 30 | 31 | ### Plasma 32 | 33 | ![Plasma](/img/Plasma-params.png?raw=true) 34 | ![Plasma](/img/Plasma.png?raw=true) 35 | 36 | ### RGB Source 37 | 38 | ![RGB Source](/img/RGBSource-params.png?raw=true) 39 | ![RGB Source](/img/RGBSource.png?raw=true) 40 | 41 | ### Spiral 42 | 43 | ![Spiral](/img/Spiral.png?raw=true) 44 | 45 | ### Springs 46 | 47 | ![Springs](/img/Springs.png?raw=true) 48 | 49 | ### Underwater Life 50 | 51 | ![Underwater Life](/img/UnderwaterLife.png?raw=true) 52 | 53 | ### Evil 54 | 55 | ![EvilShader](/img/Evil.png?raw=true) 56 | 57 | 58 | ## License 59 | 60 | These plugin source code files are licensed under WTFPL. 61 | See LICENSE.md for details. 62 | 63 | The FFGL Plugin code license is in ffgl-host/License.txt 64 | 65 | Some of the plugins have code borrowed from ShaderToy. 66 | See individual plugin source files for more details. 67 | 68 | * Evil Shader adapted from https://www.shadertoy.com/view/llS3WG 69 | * Noise uses voronoise from the amazing Inigo Quilez 70 | (http://www.iquilezles.org/www/articles/voronoise/voronoise.htm) 71 | * Plasma Globe by nimitz (twitter: @stormoid) 72 | * Spiral adapter from https://www.shadertoy.com/view/4st3WX 73 | * Crazy Springs by eiffie https://www.shadertoy.com/view/ld23DG 74 | * Underwater Life adapted from https://www.shadertoy.com/view/Mtf3Rr 75 | -------------------------------------------------------------------------------- /Spiral.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #include "Spiral.h" 19 | 20 | 21 | FFGL_PLUGIN(Spiral,"DZSP","Spiral Source",FF_SOURCE,"Sample FFGL Plugin", 22 | "by Darren Mothersele - www.darrenmothersele.com") 23 | 24 | 25 | std::string fragmentShaderCode = R"GLSL( 26 | 27 | uniform vec3 iResolution; 28 | uniform float iGlobalTime; 29 | 30 | // Original shader by s23b https://www.shadertoy.com/user/s23b 31 | // Adapted from https://www.shadertoy.com/view/4st3WX 32 | #define PI 3.14159265359 33 | 34 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 35 | { 36 | vec2 uv = fragCoord.xy / iResolution.xy / .5 - 1.; 37 | uv.x *= iResolution.x / iResolution.y; 38 | 39 | // make a tube 40 | float f = 1. / length(uv); 41 | 42 | // add the angle 43 | f += atan(uv.x, uv.y) / acos(0.); 44 | 45 | // let's roll 46 | f -= iGlobalTime; 47 | 48 | // make it black and white 49 | // old version without AA: f = floor(fract(f) * 2.); 50 | // new version based on Shane's suggestion: 51 | f = 1. - clamp(sin(f * PI * 2.) * dot(uv, uv) * iResolution.y / 15. + .5, 0., 1.); 52 | 53 | // add the darkness to the end of the tunnel 54 | f *= sin(length(uv) - .1); 55 | 56 | fragColor = vec4(f, f, f, 1.0); 57 | } 58 | 59 | void main(void) { 60 | mainImage(gl_FragColor, gl_FragCoord.xy); 61 | } 62 | 63 | )GLSL"; 64 | 65 | PluginConfig Spiral::getConfig() { 66 | PluginConfig pluginConfig; 67 | pluginConfig.shaderCode = fragmentShaderCode; 68 | pluginConfig.params.push_back({"Speed", FF_TYPE_STANDARD, 0.5f}); 69 | pluginConfig.inputNames.push_back({"iChannel0"}); 70 | return pluginConfig; 71 | } 72 | 73 | void Spiral::init(FFGLShader &shader) { 74 | timeLocation = shader.FindUniform("iGlobalTime"); 75 | resolutionLocation = shader.FindUniform("iResolution"); 76 | start = std::chrono::steady_clock::now(); 77 | } 78 | 79 | void Spiral::process(std::vector ¶mValues, FFGLExtensions &extensions) 80 | { 81 | float vpdim[4]; 82 | glGetFloatv(GL_VIEWPORT, vpdim); 83 | extensions.glUniform3fARB(resolutionLocation, vpdim[2], vpdim[3], 1.0); 84 | 85 | double lastTime = elapsedTime; 86 | elapsedTime = GetCounter()/1000.0; 87 | globalTime = globalTime + (float)(elapsedTime-lastTime) * (paramValues[0] - 0.5f) * 8.0f; 88 | extensions.glUniform1fARB(timeLocation, globalTime); 89 | } 90 | 91 | 92 | double Spiral::GetCounter() 93 | { 94 | end = std::chrono::steady_clock::now(); 95 | return std::chrono::duration_cast(end - start).count()/1000.; 96 | } -------------------------------------------------------------------------------- /Spiral.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #ifndef FFGLPLUGIN_SPIRAL_H 19 | #define FFGLPLUGIN_SPIRAL_H 20 | 21 | #include "MyPlugin.h" 22 | #include 23 | 24 | 25 | class Spiral { 26 | GLint resolutionLocation; 27 | GLint timeLocation; 28 | 29 | double elapsedTime; 30 | float globalTime; 31 | std::chrono::steady_clock::time_point start; 32 | std::chrono::steady_clock::time_point end; 33 | 34 | public: 35 | PluginConfig getConfig(); 36 | 37 | void init(FFGLShader &shader); 38 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 39 | 40 | double GetCounter(); 41 | }; 42 | 43 | 44 | #endif //FFGLPLUGIN_SPIRAL_H 45 | -------------------------------------------------------------------------------- /Springs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #include "Springs.h" 19 | 20 | 21 | FFGL_PLUGIN(Springs,"DZSR","Springs",FF_SOURCE,"Sample FFGL Plugin", 22 | "by Darren Mothersele - www.darrenmothersele.com") 23 | 24 | 25 | std::string fragmentShaderCode = R"GLSL( 26 | 27 | uniform vec3 size; 28 | uniform float time; 29 | 30 | // https://www.shadertoy.com/view/ld23DG 31 | // Crazy Springs by eiffie 32 | // Don't know why there is a seam on the springs. 33 | // Well looking at my code I know why. I just don't know exactly why. :) 34 | 35 | 36 | //#define SHADOWS 37 | float f1,f2,f3; 38 | float DE(vec3 p) 39 | { 40 | vec3 g=floor(p+0.5); 41 | vec3 g1=g+sin(g.yzx*f1+g.zxy*f2+g*f3)*0.25; 42 | vec4 dlt=vec4(sign(p-g1),0.0); 43 | vec3 g2=g+dlt.xww; 44 | vec3 g3=g+dlt.wyw; 45 | vec3 g4=g+dlt.wwz; 46 | g1-=p; 47 | g2+=sin(g2.yzx*f1+g2.zxy*f2+g2*f3)*0.25-p; 48 | g3+=sin(g3.yzx*f1+g3.zxy*f2+g3*f3)*0.25-p; 49 | g4+=sin(g4.yzx*f1+g4.zxy*f2+g4*f3)*0.25-p; 50 | vec3 gD=g2-g1,gDs=gD; 51 | float t1=clamp(dot(-g1,gD)/dot(gD,gD),0.0,1.0); 52 | vec3 p1=mix(g1,g2,t1); 53 | float m1=dot(p1,p1); 54 | gD=g3-g1; 55 | float t2=clamp(dot(-g1,gD)/dot(gD,gD),0.0,1.0); 56 | vec3 p2=mix(g1,g3,t2); 57 | float m2=dot(p2,p2); 58 | if(m2 ¶mValues, FFGLExtensions &extensions) 181 | { 182 | float vpdim[4]; 183 | glGetFloatv(GL_VIEWPORT, vpdim); 184 | extensions.glUniform3fARB(resolutionLocation, vpdim[2], vpdim[3], 1.0); 185 | 186 | double lastTime = elapsedTime; 187 | elapsedTime = GetCounter()/1000.0; 188 | globalTime = globalTime + (float)(elapsedTime-lastTime) * (paramValues[0] - 0.5f) * 8.0f; 189 | extensions.glUniform1fARB(timeLocation, globalTime); 190 | 191 | } 192 | 193 | 194 | double Springs::GetCounter() 195 | { 196 | end = std::chrono::steady_clock::now(); 197 | return std::chrono::duration_cast(end - start).count()/1000.; 198 | } 199 | -------------------------------------------------------------------------------- /Springs.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | 18 | #ifndef FFGLPLUGIN_SPRINGS_H 19 | #define FFGLPLUGIN_SPRINGS_H 20 | 21 | 22 | #include "MyPlugin.h" 23 | #include 24 | 25 | 26 | class Springs { 27 | GLint resolutionLocation; 28 | GLint timeLocation; 29 | 30 | double elapsedTime; 31 | float globalTime; 32 | std::chrono::steady_clock::time_point start; 33 | std::chrono::steady_clock::time_point end; 34 | 35 | public: 36 | PluginConfig getConfig(); 37 | 38 | void init(FFGLShader &shader); 39 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 40 | 41 | double GetCounter(); 42 | }; 43 | 44 | 45 | 46 | 47 | #endif //FFGLPLUGIN_SPRINGS_H 48 | -------------------------------------------------------------------------------- /UnderwaterLife.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | #include "UnderwaterLife.h" 18 | 19 | FFGL_PLUGIN(UnderwaterLife,"DZUL","Underwater Life",FF_SOURCE,"Sample FFGL Plugin", 20 | "by Darren Mothersele - www.darrenmothersele.com") 21 | 22 | 23 | std::string fragmentShaderCode = R"GLSL( 24 | // Shader by Kali https://www.shadertoy.com/user/Kali 25 | // Adapted from https://www.shadertoy.com/view/Mtf3Rr 26 | // http://www.fractalforums.com/movies-showcase-%28rate-my-movie%29/very-rare-deep-sea-fractal-creature/ 27 | 28 | uniform vec3 iResolution; 29 | uniform float iGlobalTime; 30 | 31 | const int Iterations=20; 32 | const float Scale=1.25; 33 | const vec3 Julia=vec3(-3.,-1.5,-0.5); 34 | const vec3 RotVector=vec3(0.5,-0.05,-1.); 35 | const float RotAngle=40.; 36 | const float Speed=1.3; 37 | const float Amplitude=0.6; 38 | const float detail=.025; 39 | const vec3 lightdir=-vec3(0.,1.,0.); 40 | 41 | mat2 rot; 42 | 43 | float de(vec3 p); 44 | vec3 color(vec3 p); 45 | 46 | vec3 normal(vec3 p) { 47 | vec3 e = vec3(0.0,detail,0.0); 48 | 49 | return normalize(vec3( 50 | de(p+e.yxx)-de(p-e.yxx), 51 | de(p+e.xyx)-de(p-e.xyx), 52 | de(p+e.xxy)-de(p-e.xxy) 53 | ) 54 | ); 55 | } 56 | 57 | float calcAO( const vec3 pos, const vec3 nor ) { 58 | float aodet=detail*3.; 59 | float totao = 0.0; 60 | float sca = 1.0; 61 | for( int aoi=0; aoi<5; aoi++ ) { 62 | float hr = aodet*float(aoi*aoi); 63 | vec3 aopos = nor * hr + pos; 64 | float dd = de( aopos ); 65 | totao += -(dd-hr)*sca; 66 | sca *= 0.7; 67 | } 68 | return clamp( 1.0 - 5.0*totao, 0., 1.0 ); 69 | } 70 | 71 | 72 | float softshadow( in vec3 ro, in vec3 rd, float mint, float k ) 73 | { 74 | float res = 1.0; 75 | float t = mint; 76 | for( int i=0; i<48; i++ ) 77 | { 78 | float h = de(ro + rd*t); 79 | h = max( h, 0.0 ); 80 | res = min( res, k*h/t ); 81 | t += clamp( h, 0.01, 0.5 ); 82 | } 83 | return clamp(res,0.0,1.0); 84 | } 85 | 86 | 87 | 88 | 89 | vec3 light(in vec3 p, in vec3 dir) { 90 | vec3 ldir=normalize(lightdir); 91 | vec3 n=normal(p); 92 | float sh=softshadow(p,-ldir,1.,20.); 93 | float diff=max(0.,dot(ldir,-n)); 94 | vec3 r = reflect(ldir,n); 95 | float spec=max(0.,dot(dir,-r)); 96 | vec3 colo=color(p); 97 | return (diff*sh+.15*max(0.,dot(normalize(dir),-n))*calcAO(p,n))*colo+pow(spec,30.)*.5*sh; 98 | } 99 | 100 | 101 | float kaliset(vec3 p) { 102 | p.y-=iGlobalTime; 103 | p.y=abs(2.-mod(p.y,4.)); 104 | for (int i=0;i<18;i++) p=abs(p)/dot(p,p)-.8; 105 | return length(p); 106 | } 107 | 108 | 109 | vec3 raymarch(in vec3 from, in vec3 dir, vec2 fragCoord) 110 | { 111 | vec3 col=vec3(0.); 112 | float st; float d=1.0; float totdist=st=0.; 113 | vec3 p; 114 | float k; 115 | for (int i=0; i<70; i++) { 116 | if (d>detail && totdist<50.) 117 | { 118 | k+=kaliset(p)*exp(-.002*totdist*totdist)*max(0.,totdist-3.)*(1.-step(0.,.2-d)); 119 | p=from+totdist*dir; 120 | d=de(p); 121 | totdist+=d; 122 | } 123 | } 124 | vec3 backg=vec3(.4,.5,.55)*(1.+fragCoord.y/iResolution.y*1.5); 125 | if (d ¶mValues, FFGLExtensions &extensions) 231 | { 232 | float vpdim[4]; 233 | glGetFloatv(GL_VIEWPORT, vpdim); 234 | extensions.glUniform3fARB(resolutionLocation, vpdim[2], vpdim[3], 1.0); 235 | 236 | double lastTime = elapsedTime; 237 | elapsedTime = GetCounter()/1000.0; 238 | globalTime = globalTime + (float)(elapsedTime-lastTime)*paramValues[0]*2.0f; 239 | extensions.glUniform1fARB(timeLocation, globalTime); 240 | } 241 | 242 | 243 | double UnderwaterLife::GetCounter() 244 | { 245 | end = std::chrono::steady_clock::now(); 246 | return std::chrono::duration_cast(end - start).count()/1000.; 247 | } 248 | -------------------------------------------------------------------------------- /UnderwaterLife.h: -------------------------------------------------------------------------------- 1 | /* 2 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 3 | Version 2, December 2004 4 | 5 | Copyright (C) 2016 Darren Mothersele 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified 8 | copies of this license document, and changing it is allowed as long 9 | as the name is changed. 10 | 11 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 12 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 13 | 14 | 0. You just DO WHAT THE FUCK YOU WANT TO. 15 | */ 16 | 17 | #ifndef FFGLPLUGIN_UNDERWATERLIFE_H 18 | #define FFGLPLUGIN_UNDERWATERLIFE_H 19 | 20 | #include "MyPlugin.h" 21 | #include 22 | 23 | class UnderwaterLife 24 | { 25 | GLint resolutionLocation; 26 | GLint timeLocation; 27 | double elapsedTime; 28 | float globalTime; 29 | std::chrono::steady_clock::time_point start; 30 | std::chrono::steady_clock::time_point end; 31 | 32 | public: 33 | PluginConfig getConfig(); 34 | 35 | void init(FFGLShader &shader); 36 | void process(std::vector ¶mValues, FFGLExtensions &extensions); 37 | 38 | double GetCounter(); 39 | }; 40 | 41 | 42 | #endif //FFGLPLUGIN_UNDERWATERLIFE_H 43 | -------------------------------------------------------------------------------- /ffgl-host/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project(FFGLHost) 3 | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTARGET_OS_MAC -std=c++11 -stdlib=libc++ -arch i386") 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-writable-strings") 7 | 8 | find_package(OpenGL REQUIRED) 9 | find_package(Glut REQUIRED) 10 | 11 | include_directories(lib/ffgl) 12 | 13 | set(FFGL_SOURCE_FILES 14 | lib/ffgl/FFGLExtensions.cpp 15 | lib/ffgl/FFGLFBO.cpp 16 | lib/ffgl/FFGLExtensions.cpp 17 | lib/ffgl/FFGLPluginInstance.cpp 18 | lib/ffgl/FFGLShader.cpp 19 | ) 20 | 21 | set(SOURCE_FILES 22 | main.cpp 23 | OSXDebugMessage.cpp 24 | OSXPluginInstance.cpp 25 | OSXTimer.cpp 26 | ) 27 | add_executable(FFGLHost ${SOURCE_FILES} ${FFGL_SOURCE_FILES}) 28 | target_link_libraries(FFGLHost ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} "-framework CoreFoundation") 29 | -------------------------------------------------------------------------------- /ffgl-host/License.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/ffgl-host/License.txt -------------------------------------------------------------------------------- /ffgl-host/OSXDebugMessage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void FFDebugMessage(const char *msg) 4 | { 5 | fprintf(stderr, msg); 6 | } -------------------------------------------------------------------------------- /ffgl-host/OSXPluginInstance.cpp: -------------------------------------------------------------------------------- 1 | #include "FFGLPluginInstance.h" 2 | #include 3 | #include 4 | #include 5 | 6 | class OSXPluginInstance : 7 | public FFGLPluginInstance 8 | { 9 | public: 10 | OSXPluginInstance(); 11 | 12 | DWORD Load(const char *filename); 13 | DWORD Unload(); 14 | 15 | virtual ~OSXPluginInstance(); 16 | 17 | protected: 18 | NSObjectFileImage m_ffImage; 19 | NSModule m_ffModule; 20 | }; 21 | 22 | FFGLPluginInstance *FFGLPluginInstance::New() 23 | { 24 | return new OSXPluginInstance(); 25 | } 26 | 27 | OSXPluginInstance::OSXPluginInstance() 28 | :m_ffImage(NULL), 29 | m_ffModule(NULL) 30 | { 31 | } 32 | 33 | DWORD OSXPluginInstance::Load(const char *fname) 34 | { 35 | if (fname==NULL || fname[0]==0) 36 | return FF_FAIL; 37 | 38 | Unload(); 39 | 40 | if (NSCreateObjectFileImageFromFile(fname, &m_ffImage)!=NSObjectFileImageSuccess) 41 | return FF_FAIL; 42 | 43 | NSModule m_ffModule = 44 | NSLinkModule( 45 | m_ffImage, 46 | fname, 47 | NSLINKMODULE_OPTION_NONE); 48 | 49 | if (m_ffModule==NULL) 50 | { 51 | Unload(); //to undo NSCreateObjectFileImageFromFile 52 | return FF_FAIL; 53 | } 54 | 55 | NSSymbol s = NSLookupSymbolInModule(m_ffModule, "_plugMain"); 56 | if (s==NULL) 57 | { 58 | Unload();//to undo NSLinkModule and NSCreateObjectFileImageFromFile 59 | return FF_FAIL; 60 | } 61 | 62 | FF_Main_FuncPtr pFreeFrameMain = (FF_Main_FuncPtr)NSAddressOfSymbol(s); 63 | 64 | if (pFreeFrameMain==NULL) 65 | { 66 | Unload(); //to undo same 67 | return FF_FAIL; 68 | } 69 | 70 | m_ffPluginMain = pFreeFrameMain; 71 | 72 | DWORD rval = InitPluginLibrary(); 73 | if (rval!=FF_SUCCESS) 74 | return rval; 75 | 76 | return FF_SUCCESS; 77 | } 78 | 79 | DWORD OSXPluginInstance::Unload() 80 | { 81 | if (m_ffInstanceID!=INVALIDINSTANCE) 82 | { 83 | FFDebugMessage("Failed to call DeInstantiateGL before Unload()"); 84 | return FF_FAIL; 85 | } 86 | 87 | DeinitPluginLibrary(); 88 | 89 | if (m_ffModule != NULL) 90 | { 91 | if (NSUnLinkModule(m_ffModule, NSUNLINKMODULE_OPTION_NONE)) 92 | { 93 | m_ffModule = NULL; 94 | } 95 | else 96 | { 97 | FFDebugMessage("couldn't free dynamic library"); 98 | } 99 | } 100 | 101 | if (m_ffImage != NULL) 102 | { 103 | if (NSDestroyObjectFileImage(m_ffImage)) 104 | { 105 | m_ffImage = NULL; 106 | } 107 | else 108 | { 109 | FFDebugMessage("couldn't destroy object file image"); 110 | } 111 | } 112 | 113 | return FF_SUCCESS; 114 | } 115 | 116 | OSXPluginInstance::~OSXPluginInstance() 117 | { 118 | if (m_ffModule!=NULL) 119 | { 120 | FFDebugMessage("plugin deleted without calling Unload()"); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ffgl-host/OSXTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | #include 3 | #include 4 | 5 | class OSXTimer : 6 | public Timer 7 | { 8 | public: 9 | 10 | OSXTimer() 11 | :m_startTime(0) 12 | { 13 | //make sure we query the timebase before doing any timing 14 | if (g_firstTime==0) 15 | { 16 | g_firstTime = 1; 17 | 18 | mach_timebase_info_data_t timebase; 19 | 20 | mach_timebase_info(&timebase); 21 | 22 | g_conversion = (1.0 / 1000000000.0) * ((double)timebase.numer / (double)timebase.denom ); 23 | } 24 | 25 | //start the timer now 26 | m_startTime = mach_absolute_time(); 27 | } 28 | 29 | static int g_firstTime; 30 | static double g_conversion; 31 | 32 | uint64_t m_startTime; 33 | 34 | void Reset() 35 | { 36 | //restart the timer now 37 | m_startTime = mach_absolute_time(); 38 | } 39 | 40 | double GetElapsedTime() 41 | { 42 | //whats the current time? 43 | uint64_t curTime = mach_absolute_time(); 44 | 45 | uint64_t elapsed = curTime - m_startTime; 46 | 47 | return g_conversion * (double)elapsed; 48 | } 49 | 50 | virtual ~OSXTimer() 51 | {} 52 | }; 53 | 54 | int OSXTimer::g_firstTime = 0; 55 | double OSXTimer::g_conversion = 0.0; 56 | 57 | Timer *Timer::New() 58 | { 59 | return new OSXTimer(); 60 | } 61 | -------------------------------------------------------------------------------- /ffgl-host/README.txt: -------------------------------------------------------------------------------- 1 | FFGL Host Application 2 | 3 | Modified to compile on OSX with CMake. 4 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFDebugMessage.h: -------------------------------------------------------------------------------- 1 | #ifndef FFDEBUGMESSAGE_H 2 | #define FFDEBUGMESSAGE_H 3 | 4 | void FFDebugMessage(const char *msg); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGL.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // FFGL.cpp 3 | // 4 | // FreeFrame is an open-source cross-platform real-time video effects plugin system. 5 | // It provides a framework for developing video effects plugins and hosts on Windows, 6 | // Linux and Mac OSX. 7 | // 8 | // FreeFrameGL (FFGL) is an extension to the FreeFrame spec to support video processing 9 | // with OpenGL on Windows, Linux, and Mac OSX. 10 | // 11 | // Copyright (c) 2002, 2003, 2004, 2006 www.freeframe.org 12 | // All rights reserved. 13 | // 14 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 15 | 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Redistribution and use in source and binary forms, with or without modification, 19 | // are permitted provided that the following conditions are met: 20 | // 21 | // * Redistributions of source code must retain the above copyright 22 | // notice, this list of conditions and the following disclaimer. 23 | // * Redistributions in binary form must reproduce the above copyright 24 | // notice, this list of conditions and the following disclaimer in 25 | // the documentation and/or other materials provided with the 26 | // distribution. 27 | // * Neither the name of FreeFrame nor the names of its 28 | // contributors may be used to endorse or promote products derived 29 | // from this software without specific prior written permission. 30 | // 31 | // 32 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 33 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 35 | // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 36 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 37 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 39 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 40 | // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 41 | // OF THE POSSIBILITY OF SUCH DAMAGE. 42 | // 43 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 44 | 45 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | // 47 | // First version, Marcus Clements (marcus@freeframe.org) 48 | // www.freeframe.org 49 | // 50 | // FreeFrame 1.0 upgrade by Russell Blakeborough 51 | // email: boblists@brightonart.org 52 | // 53 | // FreeFrame 1.0 - 03 upgrade 54 | // and implementation of FreeFrame SDK methods by Gualtiero Volpe 55 | // email: Gualtiero.Volpe@poste.it 56 | // 57 | // FFGL upgrade by Trey Harrison 58 | // email: trey@harrisondigitalmedia.com 59 | // 60 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 61 | 62 | 63 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 64 | // Includes 65 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 66 | 67 | #include "FFGLPluginSDK.h" 68 | #include 69 | 70 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 71 | // Static and extern variables used in the FreeFrame SDK 72 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 73 | 74 | extern CFFGLPluginInfo* g_CurrPluginInfo; 75 | 76 | static CFreeFrameGLPlugin* s_pPrototype = NULL; 77 | 78 | 79 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 80 | // FreeFrame SDK default implementation of the FreeFrame global functions. 81 | // Such function are called by the plugMain function, the only function a plugin exposes. 82 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 83 | 84 | void *getInfo() 85 | { 86 | return (void *)(g_CurrPluginInfo->GetPluginInfo()); 87 | } 88 | 89 | DWORD initialise() 90 | { 91 | if (g_CurrPluginInfo==NULL) 92 | return FF_FAIL; 93 | 94 | if (s_pPrototype==NULL) 95 | { 96 | //get the instantiate function pointer 97 | FPCREATEINSTANCEGL *pInstantiate = g_CurrPluginInfo->GetFactoryMethod(); 98 | 99 | //call the instantiate function 100 | DWORD dwRet = pInstantiate(&s_pPrototype); 101 | 102 | //make sure the instantiate call worked 103 | if ((dwRet == FF_FAIL) || (s_pPrototype == NULL)) 104 | return FF_FAIL; 105 | 106 | return FF_SUCCESS; 107 | } 108 | 109 | return FF_SUCCESS; 110 | } 111 | 112 | DWORD deInitialise() 113 | { 114 | if (s_pPrototype != NULL) { 115 | delete s_pPrototype; 116 | s_pPrototype = NULL; 117 | } 118 | return FF_SUCCESS; 119 | } 120 | 121 | DWORD getNumParameters() 122 | { 123 | if (s_pPrototype == NULL) { 124 | DWORD dwRet = initialise(); 125 | if (dwRet == FF_FAIL) return FF_FAIL; 126 | } 127 | 128 | return (DWORD) s_pPrototype->GetNumParams(); 129 | } 130 | 131 | char* getParameterName(DWORD index) 132 | { 133 | if (s_pPrototype == NULL) { 134 | DWORD dwRet = initialise(); 135 | if (dwRet == FF_FAIL) return NULL; 136 | } 137 | 138 | return s_pPrototype->GetParamName(index); 139 | } 140 | 141 | DWORD getParameterDefault(DWORD index) 142 | { 143 | if (s_pPrototype == NULL) { 144 | DWORD dwRet = initialise(); 145 | if (dwRet == FF_FAIL) return FF_FAIL; 146 | } 147 | 148 | void* pValue = s_pPrototype->GetParamDefault(index); 149 | if (pValue == NULL) return FF_FAIL; 150 | else { 151 | DWORD dwRet; 152 | memcpy(&dwRet, pValue, 4); 153 | return dwRet; 154 | } 155 | } 156 | 157 | DWORD getPluginCaps(DWORD index) 158 | { 159 | int MinInputs = -1; 160 | int MaxInputs = -1; 161 | 162 | if (s_pPrototype == NULL) { 163 | DWORD dwRet = initialise(); 164 | if (dwRet == FF_FAIL) return FF_FAIL; 165 | } 166 | 167 | switch (index) { 168 | 169 | case FF_CAP_16BITVIDEO: 170 | return FF_FALSE; 171 | 172 | case FF_CAP_24BITVIDEO: 173 | return FF_FALSE; 174 | 175 | case FF_CAP_32BITVIDEO: 176 | return FF_FALSE; 177 | 178 | case FF_CAP_PROCESSFRAMECOPY: 179 | return FF_FALSE; 180 | 181 | case FF_CAP_PROCESSOPENGL: 182 | return FF_TRUE; 183 | 184 | case FF_CAP_SETTIME: 185 | if (s_pPrototype->GetTimeSupported()) 186 | return FF_TRUE; 187 | else 188 | return FF_FALSE; 189 | 190 | case FF_CAP_MINIMUMINPUTFRAMES: 191 | MinInputs = s_pPrototype->GetMinInputs(); 192 | if (MinInputs < 0) return FF_FALSE; 193 | return DWORD(MinInputs); 194 | 195 | case FF_CAP_MAXIMUMINPUTFRAMES: 196 | MaxInputs = s_pPrototype->GetMaxInputs(); 197 | if (MaxInputs < 0) return FF_FALSE; 198 | return DWORD(MaxInputs); 199 | 200 | case FF_CAP_COPYORINPLACE: 201 | return FF_FALSE; 202 | 203 | default: 204 | return FF_FALSE; 205 | } 206 | 207 | return FF_FAIL; 208 | } 209 | 210 | void *getExtendedInfo() 211 | { 212 | return (void *)(g_CurrPluginInfo->GetPluginExtendedInfo()); 213 | } 214 | 215 | DWORD getParameterType(DWORD index) 216 | { 217 | if (s_pPrototype == NULL) { 218 | DWORD dwRet = initialise(); 219 | if (dwRet == FF_FAIL) return FF_FAIL; 220 | } 221 | 222 | return s_pPrototype->GetParamType(index); 223 | } 224 | 225 | DWORD instantiateGL(const FFGLViewportStruct *pGLViewport) 226 | { 227 | if (g_CurrPluginInfo==NULL || pGLViewport==NULL) 228 | return FF_FAIL; 229 | 230 | // If the plugin is not initialized, initialize it 231 | if (s_pPrototype == NULL) 232 | { 233 | DWORD dwRet = initialise(); 234 | 235 | if ((dwRet == FF_FAIL) || (s_pPrototype == NULL)) 236 | return FF_FAIL; 237 | } 238 | 239 | //get the instantiate function pointer 240 | FPCREATEINSTANCEGL *pInstantiate = g_CurrPluginInfo->GetFactoryMethod(); 241 | 242 | CFreeFrameGLPlugin *pInstance = NULL; 243 | 244 | //call the instantiate function 245 | DWORD dwRet = pInstantiate(&pInstance); 246 | 247 | //make sure the instantiate call worked 248 | if ((dwRet == FF_FAIL) || (pInstance == NULL)) 249 | return FF_FAIL; 250 | 251 | pInstance->m_pPlugin = pInstance; 252 | 253 | // Initializing instance with default values 254 | for (int i = 0; i < s_pPrototype->GetNumParams(); ++i) 255 | { 256 | //DWORD dwType = s_pPrototype->GetParamType(DWORD(i)); 257 | void* pValue = s_pPrototype->GetParamDefault(DWORD(i)); 258 | SetParameterStruct ParamStruct; 259 | ParamStruct.ParameterNumber = DWORD(i); 260 | memcpy(&ParamStruct.NewParameterValue, pValue, 4); 261 | dwRet = pInstance->SetParameter(&ParamStruct); 262 | if (dwRet == FF_FAIL) 263 | { 264 | //SetParameter failed, delete the instance 265 | delete pInstance; 266 | return FF_FAIL; 267 | } 268 | } 269 | 270 | //call the InitGL method 271 | if (pInstance->InitGL(pGLViewport)==FF_SUCCESS) 272 | { 273 | //succes? we're done. 274 | return (DWORD)pInstance; 275 | } 276 | 277 | //InitGL failed, delete the instance 278 | pInstance->DeInitGL(); 279 | delete pInstance; 280 | 281 | return FF_FAIL; 282 | } 283 | 284 | DWORD deInstantiateGL(void *instanceID) 285 | { 286 | CFreeFrameGLPlugin *p = (CFreeFrameGLPlugin *)instanceID; 287 | 288 | if (p != NULL) 289 | { 290 | p->DeInitGL(); 291 | delete p; 292 | 293 | return FF_SUCCESS; 294 | } 295 | 296 | return FF_FAIL; 297 | } 298 | 299 | 300 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 301 | // Implementation of plugMain, the one and only exposed function 302 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 303 | 304 | #ifdef WIN32 305 | 306 | plugMainUnion __stdcall plugMain(DWORD functionCode, DWORD inputValue, DWORD instanceID) 307 | 308 | #elif TARGET_OS_MAC 309 | 310 | plugMainUnion plugMain(DWORD functionCode, DWORD inputValue, DWORD instanceID) 311 | 312 | #elif __linux__ 313 | 314 | plugMainUnion plugMain(DWORD functionCode, DWORD inputValue, DWORD instanceID) 315 | 316 | #endif 317 | 318 | { 319 | plugMainUnion retval; 320 | 321 | // declare pPlugObj - pointer to this instance 322 | CFreeFrameGLPlugin* pPlugObj; 323 | 324 | // typecast DWORD into pointer to a CFreeFrameGLPlugin 325 | pPlugObj = (CFreeFrameGLPlugin*) instanceID; 326 | 327 | switch (functionCode) { 328 | 329 | case FF_GETINFO: 330 | retval.PISvalue = (PluginInfoStruct*)getInfo(); 331 | break; 332 | 333 | case FF_INITIALISE: 334 | retval.ivalue = initialise(); 335 | break; 336 | 337 | case FF_DEINITIALISE: 338 | retval.ivalue = deInitialise(); 339 | break; 340 | 341 | case FF_GETNUMPARAMETERS: 342 | retval.ivalue = getNumParameters(); 343 | break; 344 | 345 | case FF_GETPARAMETERNAME: 346 | retval.svalue = getParameterName(inputValue); 347 | break; 348 | 349 | case FF_GETPARAMETERDEFAULT: 350 | retval.ivalue = getParameterDefault(inputValue); 351 | break; 352 | 353 | case FF_GETPLUGINCAPS: 354 | retval.ivalue = getPluginCaps(inputValue); 355 | break; 356 | 357 | case FF_GETEXTENDEDINFO: 358 | retval.ivalue = (DWORD) getExtendedInfo(); 359 | break; 360 | 361 | case FF_GETPARAMETERTYPE: 362 | retval.ivalue = getParameterType(inputValue); 363 | break; 364 | 365 | case FF_GETPARAMETERDISPLAY: 366 | if (pPlugObj != NULL) 367 | retval.svalue = pPlugObj->GetParameterDisplay(inputValue); 368 | else 369 | retval.svalue = (char*)FF_FAIL; 370 | break; 371 | 372 | case FF_SETPARAMETER: 373 | if (pPlugObj != NULL) 374 | retval.ivalue = pPlugObj->SetParameter((const SetParameterStruct*) inputValue); 375 | else 376 | retval.ivalue = FF_FAIL; 377 | break; 378 | 379 | case FF_GETPARAMETER: 380 | if (pPlugObj != NULL) 381 | retval.ivalue = pPlugObj->GetParameter(inputValue); 382 | else 383 | retval.ivalue = FF_FAIL; 384 | break; 385 | 386 | case FF_INSTANTIATEGL: 387 | retval.ivalue = (DWORD)instantiateGL((const FFGLViewportStruct *)inputValue); 388 | break; 389 | 390 | case FF_DEINSTANTIATEGL: 391 | if (pPlugObj != NULL) 392 | retval.ivalue = deInstantiateGL(pPlugObj); 393 | else 394 | retval.ivalue = FF_FAIL; 395 | break; 396 | 397 | case FF_GETIPUTSTATUS: 398 | if (pPlugObj != NULL) 399 | retval.ivalue = pPlugObj->GetInputStatus(inputValue); 400 | else 401 | retval.ivalue = FF_FAIL; 402 | break; 403 | 404 | case FF_PROCESSOPENGL: 405 | if (pPlugObj != NULL) 406 | { 407 | ProcessOpenGLStruct *pogls = (ProcessOpenGLStruct *)inputValue; 408 | if (pogls!=NULL) 409 | retval.ivalue = pPlugObj->ProcessOpenGL(pogls); 410 | else 411 | retval.ivalue = FF_FAIL; 412 | } 413 | else 414 | retval.ivalue = FF_FAIL; 415 | break; 416 | 417 | case FF_SETTIME: 418 | if (pPlugObj != NULL) 419 | { 420 | double *inputTime = (double *)inputValue; 421 | if (inputTime!=NULL) 422 | retval.ivalue = pPlugObj->SetTime(*inputTime); 423 | else 424 | retval.ivalue = FF_FAIL; 425 | } 426 | else 427 | retval.ivalue = FF_FAIL; 428 | break; 429 | 430 | //these old FF functions must always fail for FFGL plugins 431 | case FF_INSTANTIATE: 432 | case FF_DEINSTANTIATE: 433 | case FF_PROCESSFRAME: 434 | case FF_PROCESSFRAMECOPY: 435 | default: 436 | retval.ivalue = FF_FAIL; 437 | break; 438 | } 439 | 440 | return retval; 441 | } 442 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGL.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // FFGL.h 3 | // 4 | // FreeFrame is an open-source cross-platform real-time video effects plugin system. 5 | // It provides a framework for developing video effects plugins and hosts on Windows, 6 | // Linux and Mac OSX. 7 | // 8 | // Copyright (c) 2006 www.freeframe.org 9 | // All rights reserved. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 14 | // FFGL.h by Trey Harrison 15 | // www.harrisondigitalmedia.com 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 19 | // 20 | // Redistribution and use in source and binary forms, with or without modification, 21 | // are permitted provided that the following conditions are met: 22 | // 23 | // * Redistributions of source code must retain the above copyright 24 | // notice, this list of conditions and the following disclaimer. 25 | // * Redistributions in binary form must reproduce the above copyright 26 | // notice, this list of conditions and the following disclaimer in 27 | // the documentation and/or other materials provided with the 28 | // distribution. 29 | // * Neither the name of FreeFrame nor the names of its 30 | // contributors may be used to endorse or promote products derived 31 | // from this software without specific prior written permission. 32 | // 33 | // 34 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 35 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 36 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 37 | // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 39 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 40 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 41 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 42 | // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 43 | // OF THE POSSIBILITY OF SUCH DAMAGE. 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | 47 | #ifndef __FFGL_H__ 48 | #define __FFGL_H__ 49 | 50 | ////////////////////////////////////////////////////////////////////////////////////// 51 | // Includes 52 | ///////////////////////////////////////////////////////////////////////////////////// 53 | 54 | //include the appropriate OpenGL headers for the compiler 55 | 56 | #ifdef _WIN32 57 | 58 | #include 59 | #include 60 | 61 | #else 62 | 63 | #ifdef TARGET_OS_MAC 64 | //on osx, auto-includes gl_ext.h for OpenGL extensions, which will interfere 65 | //with the FFGL SDK's own FFGLExtensions headers (included below). this #define disables 66 | //the auto-inclusion of gl_ext.h in OpenGl.h on OSX 67 | #define GL_GLEXT_LEGACY 68 | #include 69 | 70 | #else 71 | #ifdef __linux__ 72 | 73 | #include 74 | 75 | #else 76 | 77 | #error define this for your OS 78 | 79 | #endif 80 | #endif 81 | #endif 82 | 83 | ///////////////////////////////////////////////////////////////////////////// 84 | //FreeFrameGL defines numerically extend FreeFrame defines (see FreeFrame.h) 85 | ///////////////////////////////////////////////////////////////////////////// 86 | #include "FreeFrame.h" 87 | 88 | // new function codes for FFGL 89 | #define FF_PROCESSOPENGL 17 90 | #define FF_INSTANTIATEGL 18 91 | #define FF_DEINSTANTIATEGL 19 92 | #define FF_SETTIME 20 93 | 94 | // new plugin capabilities for FFGL 95 | #define FF_CAP_PROCESSOPENGL 4 96 | #define FF_CAP_SETTIME 5 97 | 98 | //FFGLViewportStruct (for InstantiateGL) 99 | typedef struct FFGLViewportStructTag 100 | { 101 | GLuint x,y,width,height; 102 | } FFGLViewportStruct; 103 | 104 | //FFGLTextureStruct (for ProcessOpenGLStruct) 105 | typedef struct FFGLTextureStructTag 106 | { 107 | DWORD Width, Height; 108 | DWORD HardwareWidth, HardwareHeight; 109 | GLuint Handle; //the actual texture handle, from glGenTextures() 110 | } FFGLTextureStruct; 111 | 112 | // ProcessOpenGLStruct 113 | typedef struct ProcessOpenGLStructTag { 114 | DWORD numInputTextures; 115 | FFGLTextureStruct **inputTextures; 116 | 117 | //if the host calls ProcessOpenGL with a framebuffer object actively bound 118 | //(as is the case when the host is capturing the plugins output to an offscreen texture) 119 | //the host must provide the GL handle to its EXT_framebuffer_object 120 | //so that the plugin can restore that binding if the plugin 121 | //makes use of its own FBO's for intermediate rendering 122 | GLuint HostFBO; 123 | } ProcessOpenGLStruct; 124 | 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLExtensions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #ifdef TARGET_OS_MAC 7 | //for the NS* calls in GetProcAddress 8 | #include 9 | #endif 10 | 11 | #ifdef __linux__ 12 | #include 13 | #endif 14 | 15 | FFGLExtensions::FFGLExtensions() 16 | { 17 | memset(this, 0, sizeof(FFGLExtensions)); 18 | } 19 | 20 | void FFGLExtensions::Initialize() 21 | { 22 | #ifdef _WIN32 23 | InitWGLEXTSwapControl(); 24 | #endif 25 | 26 | InitMultitexture(); 27 | InitARBShaderObjects(); 28 | InitEXTFramebufferObject(); 29 | } 30 | 31 | void *FFGLExtensions::GetProcAddress(char *name) 32 | { 33 | 34 | #ifdef _WIN32 35 | 36 | void *result = wglGetProcAddress(name); 37 | 38 | if (result!=NULL) 39 | return result; 40 | 41 | #else 42 | 43 | #ifdef TARGET_OS_MAC 44 | 45 | // Prepend a '_' for the Unix C symbol mangling convention 46 | int symbolLength = strlen(name) + 2; //1 for the _, another for the trailing null 47 | char symbolName[1024]; 48 | if (symbolLength>sizeof(symbolName)) 49 | { 50 | //symbol name too long; 51 | throw; 52 | return NULL; 53 | } 54 | 55 | strcpy(symbolName + 1, name); 56 | symbolName[0] = '_'; 57 | 58 | NSSymbol symbol = NULL; 59 | 60 | if (NSIsSymbolNameDefined(symbolName)) 61 | symbol = NSLookupAndBindSymbol(symbolName); 62 | 63 | if (symbol!=NULL) 64 | { 65 | return NSAddressOfSymbol(symbol); 66 | } 67 | 68 | #else 69 | 70 | #ifdef __linux__ 71 | 72 | void *result = (void *)(unsigned)glXGetProcAddress((const GLubyte *)name); 73 | 74 | if (result!=NULL) 75 | return result; 76 | 77 | #else 78 | 79 | #error Define this for your OS 80 | 81 | #endif 82 | #endif 83 | #endif 84 | throw;//this will be caught by one of the Init() functions below 85 | return NULL; 86 | } 87 | 88 | void FFGLExtensions::InitMultitexture() 89 | { 90 | try 91 | { 92 | glActiveTexture = (glActiveTexturePROC)(unsigned)GetProcAddress("glActiveTexture"); 93 | glClientActiveTexture = (glClientActiveTexturePROC)(unsigned)GetProcAddress("glClientActiveTexture"); 94 | 95 | glMultiTexCoord1d = (glMultiTexCoord1dPROC)(unsigned)GetProcAddress("glMultiTexCoord1d"); 96 | glMultiTexCoord1dv = (glMultiTexCoord1dvPROC)(unsigned)GetProcAddress("glMultiTexCoord1dv"); 97 | glMultiTexCoord1f = (glMultiTexCoord1fPROC)(unsigned)GetProcAddress("glMultiTexCoord1f"); 98 | glMultiTexCoord1fv = (glMultiTexCoord1fvPROC)(unsigned)GetProcAddress("glMultiTexCoord1fv"); 99 | glMultiTexCoord1i = (glMultiTexCoord1iPROC)(unsigned)GetProcAddress("glMultiTexCoord1i"); 100 | glMultiTexCoord1iv = (glMultiTexCoord1ivPROC)(unsigned)GetProcAddress("glMultiTexCoord1iv"); 101 | glMultiTexCoord1s = (glMultiTexCoord1sPROC)(unsigned)GetProcAddress("glMultiTexCoord1s"); 102 | glMultiTexCoord1sv = (glMultiTexCoord1svPROC)(unsigned)GetProcAddress("glMultiTexCoord1sv"); 103 | 104 | glMultiTexCoord2d = (glMultiTexCoord2dPROC)(unsigned)GetProcAddress("glMultiTexCoord2d"); 105 | glMultiTexCoord2dv = (glMultiTexCoord2dvPROC)(unsigned)GetProcAddress("glMultiTexCoord2dv"); 106 | glMultiTexCoord2f = (glMultiTexCoord2fPROC)(unsigned)GetProcAddress("glMultiTexCoord2f"); 107 | glMultiTexCoord2fv = (glMultiTexCoord2fvPROC)(unsigned)GetProcAddress("glMultiTexCoord2fv"); 108 | glMultiTexCoord2i = (glMultiTexCoord2iPROC)(unsigned)GetProcAddress("glMultiTexCoord2i"); 109 | glMultiTexCoord2iv = (glMultiTexCoord2ivPROC)(unsigned)GetProcAddress("glMultiTexCoord2iv"); 110 | glMultiTexCoord2s = (glMultiTexCoord2sPROC)(unsigned)GetProcAddress("glMultiTexCoord2s"); 111 | glMultiTexCoord2sv = (glMultiTexCoord2svPROC)(unsigned)GetProcAddress("glMultiTexCoord2sv"); 112 | 113 | glMultiTexCoord3d = (glMultiTexCoord3dPROC)(unsigned)GetProcAddress("glMultiTexCoord3d"); 114 | glMultiTexCoord3dv = (glMultiTexCoord3dvPROC)(unsigned)GetProcAddress("glMultiTexCoord3dv"); 115 | glMultiTexCoord3f = (glMultiTexCoord3fPROC)(unsigned)GetProcAddress("glMultiTexCoord3f"); 116 | glMultiTexCoord3fv = (glMultiTexCoord3fvPROC)(unsigned)GetProcAddress("glMultiTexCoord3fv"); 117 | glMultiTexCoord3i = (glMultiTexCoord3iPROC)(unsigned)GetProcAddress("glMultiTexCoord3i"); 118 | glMultiTexCoord3iv = (glMultiTexCoord3ivPROC)(unsigned)GetProcAddress("glMultiTexCoord3iv"); 119 | glMultiTexCoord3s = (glMultiTexCoord3sPROC)(unsigned)GetProcAddress("glMultiTexCoord3s"); 120 | glMultiTexCoord3sv = (glMultiTexCoord3svPROC)(unsigned)GetProcAddress("glMultiTexCoord3sv"); 121 | 122 | glMultiTexCoord4d = (glMultiTexCoord4dPROC)(unsigned)GetProcAddress("glMultiTexCoord4d"); 123 | glMultiTexCoord4dv = (glMultiTexCoord4dvPROC)(unsigned)GetProcAddress("glMultiTexCoord4dv"); 124 | glMultiTexCoord4f = (glMultiTexCoord4fPROC)(unsigned)GetProcAddress("glMultiTexCoord4f"); 125 | glMultiTexCoord4fv = (glMultiTexCoord4fvPROC)(unsigned)GetProcAddress("glMultiTexCoord4fv"); 126 | glMultiTexCoord4i = (glMultiTexCoord4iPROC)(unsigned)GetProcAddress("glMultiTexCoord4i"); 127 | glMultiTexCoord4iv = (glMultiTexCoord4ivPROC)(unsigned)GetProcAddress("glMultiTexCoord4iv"); 128 | glMultiTexCoord4s = (glMultiTexCoord4sPROC)(unsigned)GetProcAddress("glMultiTexCoord4s"); 129 | glMultiTexCoord4sv = (glMultiTexCoord4svPROC)(unsigned)GetProcAddress("glMultiTexCoord4sv"); 130 | } 131 | catch (...) 132 | { 133 | //not supported 134 | multitexture = 0; 135 | return; 136 | } 137 | 138 | //if we get this far w/no exceptions, ARB_shader_objects shoudl be fully 139 | //supported 140 | multitexture = 1; 141 | } 142 | 143 | void FFGLExtensions::InitARBShaderObjects() 144 | { 145 | try 146 | { 147 | 148 | glDeleteObjectARB = (glDeleteObjectARBPROC)(unsigned)GetProcAddress("glDeleteObjectARB"); 149 | glGetHandleARB = (glGetHandleARBPROC)(unsigned)GetProcAddress("glGetHandleARB"); 150 | glDetachObjectARB = (glDetachObjectARBPROC)(unsigned)GetProcAddress("glDetachObjectARB"); 151 | glCreateShaderObjectARB = (glCreateShaderObjectARBPROC)(unsigned)GetProcAddress("glCreateShaderObjectARB"); 152 | glShaderSourceARB = (glShaderSourceARBPROC)(unsigned)GetProcAddress("glShaderSourceARB"); 153 | glCompileShaderARB = (glCompileShaderARBPROC)(unsigned)GetProcAddress("glCompileShaderARB"); 154 | glCreateProgramObjectARB = (glCreateProgramObjectARBPROC)(unsigned)GetProcAddress("glCreateProgramObjectARB"); 155 | glAttachObjectARB = (glAttachObjectARBPROC)(unsigned)GetProcAddress("glAttachObjectARB"); 156 | glLinkProgramARB = (glLinkProgramARBPROC)(unsigned)GetProcAddress("glLinkProgramARB"); 157 | glUseProgramObjectARB = (glUseProgramObjectARBPROC)(unsigned)GetProcAddress("glUseProgramObjectARB"); 158 | glValidateProgramARB = (glValidateProgramARBPROC)(unsigned)GetProcAddress("glValidateProgramARB"); 159 | glUniform1fARB = (glUniform1fARBPROC)(unsigned)GetProcAddress("glUniform1fARB"); 160 | glUniform2fARB = (glUniform2fARBPROC)(unsigned)GetProcAddress("glUniform2fARB"); 161 | glUniform3fARB = (glUniform3fARBPROC)(unsigned)GetProcAddress("glUniform3fARB"); 162 | glUniform4fARB = (glUniform4fARBPROC)(unsigned)GetProcAddress("glUniform4fARB"); 163 | glUniform1iARB = (glUniform1iARBPROC)(unsigned)GetProcAddress("glUniform1iARB"); 164 | glUniform2iARB = (glUniform2iARBPROC)(unsigned)GetProcAddress("glUniform2iARB"); 165 | glUniform3iARB = (glUniform3iARBPROC)(unsigned)GetProcAddress("glUniform3iARB"); 166 | glUniform4iARB = (glUniform4iARBPROC)(unsigned)GetProcAddress("glUniform4iARB"); 167 | glUniform1fvARB = (glUniform1fvARBPROC)(unsigned)GetProcAddress("glUniform1fvARB"); 168 | glUniform2fvARB = (glUniform2fvARBPROC)(unsigned)GetProcAddress("glUniform2fvARB"); 169 | glUniform3fvARB = (glUniform3fvARBPROC)(unsigned)GetProcAddress("glUniform3fvARB"); 170 | glUniform4fvARB = (glUniform4fvARBPROC)(unsigned)GetProcAddress("glUniform4fvARB"); 171 | glUniform1ivARB = (glUniform1ivARBPROC)(unsigned)GetProcAddress("glUniform1ivARB"); 172 | glUniform2ivARB = (glUniform2ivARBPROC)(unsigned)GetProcAddress("glUniform2ivARB"); 173 | glUniform3ivARB = (glUniform3ivARBPROC)(unsigned)GetProcAddress("glUniform3ivARB"); 174 | glUniform4ivARB = (glUniform4ivARBPROC)(unsigned)GetProcAddress("glUniform4ivARB"); 175 | glUniformMatrix2fvARB = (glUniformMatrix2fvARBPROC)(unsigned)GetProcAddress("glUniformMatrix2fvARB"); 176 | glUniformMatrix3fvARB = (glUniformMatrix3fvARBPROC)(unsigned)GetProcAddress("glUniformMatrix3fvARB"); 177 | glUniformMatrix4fvARB = (glUniformMatrix4fvARBPROC)(unsigned)GetProcAddress("glUniformMatrix4fvARB"); 178 | glGetObjectParameterfvARB = (glGetObjectParameterfvARBPROC)(unsigned)GetProcAddress("glGetObjectParameterfvARB"); 179 | glGetObjectParameterivARB = (glGetObjectParameterivARBPROC)(unsigned)GetProcAddress("glGetObjectParameterivARB"); 180 | glGetInfoLogARB = (glGetInfoLogARBPROC)(unsigned)GetProcAddress("glGetInfoLogARB"); 181 | glGetAttachedObjectsARB = (glGetAttachedObjectsARBPROC)(unsigned)GetProcAddress("glGetAttachedObjectsARB"); 182 | glGetUniformLocationARB = (glGetUniformLocationARBPROC)(unsigned)GetProcAddress("glGetUniformLocationARB"); 183 | glGetActiveUniformARB = (glGetActiveUniformARBPROC)(unsigned)GetProcAddress("glGetActiveUniformARB"); 184 | glGetUniformfvARB = (glGetUniformfvARBPROC)(unsigned)GetProcAddress("glGetUniformfvARB"); 185 | glGetUniformivARB = (glGetUniformivARBPROC)(unsigned)GetProcAddress("glGetUniformivARB"); 186 | glGetShaderSourceARB = (glGetShaderSourceARBPROC)(unsigned)GetProcAddress("glGetShaderSourceARB"); 187 | 188 | } 189 | catch (...) 190 | { 191 | //not supported 192 | ARB_shader_objects = 0; 193 | return; 194 | } 195 | 196 | //if we get this far w/no exceptions, ARB_shader_objects shoudl be fully 197 | //supported 198 | ARB_shader_objects = 1; 199 | } 200 | 201 | void FFGLExtensions::InitEXTFramebufferObject() 202 | { 203 | try 204 | { 205 | 206 | glBindFramebufferEXT = (glBindFramebufferEXTPROC)(unsigned)GetProcAddress("glBindFramebufferEXT"); 207 | glBindRenderbufferEXT = (glBindRenderbufferEXTPROC)(unsigned)GetProcAddress("glBindRenderbufferEXT"); 208 | glCheckFramebufferStatusEXT = (glCheckFramebufferStatusEXTPROC)(unsigned)GetProcAddress("glCheckFramebufferStatusEXT"); 209 | glDeleteFramebuffersEXT = (glDeleteFramebuffersEXTPROC)(unsigned)GetProcAddress("glDeleteFramebuffersEXT"); 210 | glDeleteRenderBuffersEXT = (glDeleteRenderBuffersEXTPROC)(unsigned)GetProcAddress("glDeleteRenderbuffersEXT"); 211 | glFramebufferRenderbufferEXT = (glFramebufferRenderbufferEXTPROC)(unsigned)GetProcAddress("glFramebufferRenderbufferEXT"); 212 | glFramebufferTexture1DEXT = (glFramebufferTexture1DEXTPROC)(unsigned)GetProcAddress("glFramebufferTexture1DEXT"); 213 | glFramebufferTexture2DEXT = (glFramebufferTexture2DEXTPROC)(unsigned)GetProcAddress("glFramebufferTexture2DEXT"); 214 | glFramebufferTexture3DEXT = (glFramebufferTexture3DEXTPROC)(unsigned)GetProcAddress("glFramebufferTexture3DEXT"); 215 | glGenFramebuffersEXT = (glGenFramebuffersEXTPROC)(unsigned)GetProcAddress("glGenFramebuffersEXT"); 216 | glGenRenderbuffersEXT = (glGenRenderbuffersEXTPROC)(unsigned)GetProcAddress("glGenRenderbuffersEXT"); 217 | glGenerateMipmapEXT = (glGenerateMipmapEXTPROC)(unsigned)GetProcAddress("glGenerateMipmapEXT"); 218 | glGetFramebufferAttachmentParameterivEXT = (glGetFramebufferAttachmentParameterivEXTPROC)(unsigned)GetProcAddress("glGetFramebufferAttachmentParameterivEXT"); 219 | glGetRenderbufferParameterivEXT = (glGetRenderbufferParameterivEXTPROC)(unsigned)GetProcAddress("glGetRenderbufferParameterivEXT"); 220 | glIsFramebufferEXT = (glIsFramebufferEXTPROC)(unsigned)GetProcAddress("glIsFramebufferEXT"); 221 | glIsRenderbufferEXT = (glIsRenderbufferEXTPROC)(unsigned)GetProcAddress("glIsRenderbufferEXT"); 222 | glRenderbufferStorageEXT = (glRenderbufferStorageEXTPROC)(unsigned)GetProcAddress("glRenderbufferStorageEXT"); 223 | 224 | } 225 | catch (...) 226 | { 227 | //not supported 228 | EXT_framebuffer_object = 0; 229 | return; 230 | } 231 | 232 | EXT_framebuffer_object = 1; 233 | } 234 | 235 | #ifdef _WIN32 236 | void FFGLExtensions::InitWGLEXTSwapControl() 237 | { 238 | try 239 | { 240 | wglSwapIntervalEXT = (wglSwapIntervalEXTPROC) GetProcAddress("wglSwapIntervalEXT"); 241 | wglGetSwapIntervalEXT = (wglGetSwapIntervalEXTPROC) GetProcAddress("wglGetSwapIntervalEXT"); 242 | } 243 | catch (...) 244 | { 245 | //not supported 246 | WGL_EXT_swap_control = 0; 247 | return; 248 | } 249 | 250 | WGL_EXT_swap_control = 1; 251 | } 252 | #endif 253 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLExtensions.h: -------------------------------------------------------------------------------- 1 | #ifndef FFGLEXTENSIONS_H 2 | #define FFGLEXTENSIONS_H 3 | 4 | //originally this file came from SGI. 5 | //Lev Povalahev extended it with his great library "GLew". 6 | 7 | //The GLew headers have been reduced to a minimal set of extensions 8 | //required by the sample host and plugins in the FFGL SDK by 9 | //Trey Harrison - www.harrisondigitalmedia.com 10 | 11 | /* 12 | ** License Applicability. Except to the extent portions of this file are 13 | ** made subject to an alternative license as permitted in the SGI Free 14 | ** Software License B, Version 1.1 (the "License"), the contents of this 15 | ** file are subject only to the provisions of the License. You may not use 16 | ** this file except in compliance with the License. You may obtain a copy 17 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 18 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 19 | ** 20 | ** http://oss.sgi.com/projects/FreeB 21 | ** 22 | ** Note that, as provided in the License, the Software is distributed on an 23 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 24 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 25 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 26 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 27 | ** 28 | ** Original Code. The Original Code is: OpenGL Sample Implementation, 29 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 30 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 31 | ** Copyright in any portions created by third parties is as indicated 32 | ** elsewhere herein. All Rights Reserved. 33 | ** 34 | ** Additional Notice Provisions: This software was created using the 35 | ** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has 36 | ** not been independently verified as being compliant with the OpenGL(R) 37 | ** version 1.2.1 Specification. 38 | */ 39 | 40 | /* Most parts copyright (c) 2001-2002 Lev Povalahev under this lisence: */ 41 | 42 | /* ---------------------------------------------------------------------------- 43 | Copyright (c) 2002, Lev Povalahev 44 | All rights reserved. 45 | 46 | Redistribution and use in source and binary forms, with or without modification, 47 | are permitted provided that the following conditions are met: 48 | 49 | * Redistributions of source code must retain the above copyright notice, 50 | this list of conditions and the following disclaimer. 51 | * Redistributions in binary form must reproduce the above copyright notice, 52 | this list of conditions and the following disclaimer in the documentation 53 | and/or other materials provided with the distribution. 54 | * The name of the author may be used to endorse or promote products 55 | derived from this software without specific prior written permission. 56 | 57 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 58 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 59 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 60 | IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 61 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 62 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 63 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 64 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 65 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 66 | THE POSSIBILITY OF SUCH DAMAGE. 67 | ------------------------------------------------------------------------------*/ 68 | 69 | #ifdef _WIN32 70 | 71 | #ifndef APIENTRY 72 | #define APIENTRY __stdcall 73 | #endif 74 | 75 | #else 76 | 77 | #ifdef TARGET_OS_MAC 78 | 79 | #define APIENTRY 80 | 81 | #else 82 | #ifdef __linux__ 83 | 84 | // APIENTRY is defined in gl.h 85 | 86 | #else 87 | 88 | #error #define APIENTRY for your platform 89 | 90 | #endif 91 | #endif 92 | #endif 93 | 94 | /////////////// 95 | // OpenGL 1.2 96 | /////////////// 97 | 98 | #define GL_CLAMP_TO_EDGE 0x812F 99 | #define GL_TEXTURE_3D 0x806F 100 | 101 | /////////////// 102 | // OpenGL 1.3 Multitexture 103 | /////////////// 104 | 105 | #define GL_TEXTURE0 0x84C0 106 | #define GL_TEXTURE1 0x84C1 107 | #define GL_TEXTURE2 0x84C2 108 | #define GL_TEXTURE3 0x84C3 109 | #define GL_TEXTURE4 0x84C4 110 | #define GL_TEXTURE5 0x84C5 111 | #define GL_TEXTURE6 0x84C6 112 | #define GL_TEXTURE7 0x84C7 113 | #define GL_TEXTURE8 0x84C8 114 | #define GL_TEXTURE9 0x84C9 115 | #define GL_TEXTURE10 0x84CA 116 | #define GL_TEXTURE11 0x84CB 117 | #define GL_TEXTURE12 0x84CC 118 | #define GL_TEXTURE13 0x84CD 119 | #define GL_TEXTURE14 0x84CE 120 | #define GL_TEXTURE15 0x84CF 121 | #define GL_TEXTURE16 0x84D0 122 | #define GL_TEXTURE17 0x84D1 123 | #define GL_TEXTURE18 0x84D2 124 | #define GL_TEXTURE19 0x84D3 125 | #define GL_TEXTURE20 0x84D4 126 | #define GL_TEXTURE21 0x84D5 127 | #define GL_TEXTURE22 0x84D6 128 | #define GL_TEXTURE23 0x84D7 129 | #define GL_TEXTURE24 0x84D8 130 | #define GL_TEXTURE25 0x84D9 131 | #define GL_TEXTURE26 0x84DA 132 | #define GL_TEXTURE27 0x84DB 133 | #define GL_TEXTURE28 0x84DC 134 | #define GL_TEXTURE29 0x84DD 135 | #define GL_TEXTURE30 0x84DE 136 | #define GL_TEXTURE31 0x84DF 137 | #define GL_ACTIVE_TEXTURE 0x84E0 138 | #define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 139 | #define GL_MAX_TEXTURE_UNITS 0x84E2 140 | 141 | typedef void (APIENTRY *glActiveTexturePROC) (GLenum texture ); 142 | typedef void (APIENTRY *glClientActiveTexturePROC) (GLenum texture ); 143 | typedef void (APIENTRY *glMultiTexCoord1dPROC) (GLenum target, GLdouble s ); 144 | typedef void (APIENTRY *glMultiTexCoord1dvPROC) (GLenum target, const GLdouble *v ); 145 | typedef void (APIENTRY *glMultiTexCoord1fPROC) (GLenum target, GLfloat s ); 146 | typedef void (APIENTRY *glMultiTexCoord1fvPROC) (GLenum target, const GLfloat *v ); 147 | typedef void (APIENTRY *glMultiTexCoord1iPROC) (GLenum target, GLint s ); 148 | typedef void (APIENTRY *glMultiTexCoord1ivPROC) (GLenum target, const GLint *v ); 149 | typedef void (APIENTRY *glMultiTexCoord1sPROC) (GLenum target, GLshort s ); 150 | typedef void (APIENTRY *glMultiTexCoord1svPROC) (GLenum target, const GLshort *v ); 151 | typedef void (APIENTRY *glMultiTexCoord2dPROC) (GLenum target, GLdouble s, GLdouble t ); 152 | typedef void (APIENTRY *glMultiTexCoord2dvPROC) (GLenum target, const GLdouble *v ); 153 | typedef void (APIENTRY *glMultiTexCoord2fPROC) (GLenum target, GLfloat s, GLfloat t ); 154 | typedef void (APIENTRY *glMultiTexCoord2fvPROC) (GLenum target, const GLfloat *v ); 155 | typedef void (APIENTRY *glMultiTexCoord2iPROC) (GLenum target, GLint s, GLint t ); 156 | typedef void (APIENTRY *glMultiTexCoord2ivPROC) (GLenum target, const GLint *v ); 157 | typedef void (APIENTRY *glMultiTexCoord2sPROC) (GLenum target, GLshort s, GLshort t ); 158 | typedef void (APIENTRY *glMultiTexCoord2svPROC) (GLenum target, const GLshort *v ); 159 | typedef void (APIENTRY *glMultiTexCoord3dPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r ); 160 | typedef void (APIENTRY *glMultiTexCoord3dvPROC) (GLenum target, const GLdouble *v ); 161 | typedef void (APIENTRY *glMultiTexCoord3fPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r ); 162 | typedef void (APIENTRY *glMultiTexCoord3fvPROC) (GLenum target, const GLfloat *v ); 163 | typedef void (APIENTRY *glMultiTexCoord3iPROC) (GLenum target, GLint s, GLint t, GLint r ); 164 | typedef void (APIENTRY *glMultiTexCoord3ivPROC) (GLenum target, const GLint *v ); 165 | typedef void (APIENTRY *glMultiTexCoord3sPROC) (GLenum target, GLshort s, GLshort t, GLshort r ); 166 | typedef void (APIENTRY *glMultiTexCoord3svPROC) (GLenum target, const GLshort *v ); 167 | typedef void (APIENTRY *glMultiTexCoord4dPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q ); 168 | typedef void (APIENTRY *glMultiTexCoord4dvPROC) (GLenum target, const GLdouble *v ); 169 | typedef void (APIENTRY *glMultiTexCoord4fPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); 170 | typedef void (APIENTRY *glMultiTexCoord4fvPROC) (GLenum target, const GLfloat *v ); 171 | typedef void (APIENTRY *glMultiTexCoord4iPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q ); 172 | typedef void (APIENTRY *glMultiTexCoord4ivPROC) (GLenum target, const GLint *v ); 173 | typedef void (APIENTRY *glMultiTexCoord4sPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q ); 174 | typedef void (APIENTRY *glMultiTexCoord4svPROC) (GLenum target, const GLshort *v ); 175 | 176 | ////////////// 177 | //OpenGL 1.4 178 | /////////////// 179 | 180 | #define GL_GENERATE_MIPMAP 0x8191 181 | #define GL_GENERATE_MIPMAP_HINT 0x8192 182 | #define GL_DEPTH_COMPONENT16 0x81A5 183 | #define GL_DEPTH_COMPONENT24 0x81A6 184 | #define GL_DEPTH_COMPONENT32 0x81A7 185 | 186 | ////////////////// 187 | //EXT_framebuffer_object 188 | ////////////////// 189 | 190 | #define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 191 | #define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 192 | #define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 193 | #define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 194 | #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 195 | #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 196 | #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 197 | #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 198 | #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 199 | #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 200 | #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 201 | #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 202 | #define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8 203 | #define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 204 | #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA 205 | #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB 206 | #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC 207 | #define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD 208 | #define GL_FRAMEBUFFER_STATUS_ERROR_EXT 0x8CDE 209 | #define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF 210 | #define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 211 | #define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 212 | #define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 213 | #define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 214 | #define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 215 | #define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 216 | #define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 217 | #define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 218 | #define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 219 | #define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 220 | #define GL_COLOR_ATTACHMENT10_EXT 0x8CEA 221 | #define GL_COLOR_ATTACHMENT11_EXT 0x8CEB 222 | #define GL_COLOR_ATTACHMENT12_EXT 0x8CEC 223 | #define GL_COLOR_ATTACHMENT13_EXT 0x8CED 224 | #define GL_COLOR_ATTACHMENT14_EXT 0x8CEE 225 | #define GL_COLOR_ATTACHMENT15_EXT 0x8CEF 226 | #define GL_DEPTH_ATTACHMENT_EXT 0x8D00 227 | #define GL_STENCIL_ATTACHMENT_EXT 0x8D20 228 | #define GL_FRAMEBUFFER_EXT 0x8D40 229 | #define GL_RENDERBUFFER_EXT 0x8D41 230 | #define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 231 | #define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 232 | #define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 233 | #define GL_STENCIL_INDEX_EXT 0x8D45 234 | #define GL_STENCIL_INDEX1_EXT 0x8D46 235 | #define GL_STENCIL_INDEX4_EXT 0x8D47 236 | #define GL_STENCIL_INDEX8_EXT 0x8D48 237 | #define GL_STENCIL_INDEX16_EXT 0x8D49 238 | 239 | typedef void (APIENTRY *glBindFramebufferEXTPROC) (GLenum target, GLuint framebuffer); 240 | typedef void (APIENTRY *glBindRenderbufferEXTPROC) (GLenum target, GLuint renderbuffer); 241 | typedef GLenum (APIENTRY *glCheckFramebufferStatusEXTPROC) (GLenum target); 242 | typedef void (APIENTRY *glDeleteFramebuffersEXTPROC) (GLsizei n, const GLuint* framebuffers); 243 | typedef void (APIENTRY *glDeleteRenderBuffersEXTPROC) (GLsizei n, const GLuint* renderbuffers); 244 | typedef void (APIENTRY *glFramebufferRenderbufferEXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); 245 | typedef void (APIENTRY *glFramebufferTexture1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); 246 | typedef void (APIENTRY *glFramebufferTexture2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); 247 | typedef void (APIENTRY *glFramebufferTexture3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); 248 | typedef void (APIENTRY *glGenFramebuffersEXTPROC) (GLsizei n, GLuint* framebuffers); 249 | typedef void (APIENTRY *glGenRenderbuffersEXTPROC) (GLsizei n, GLuint* renderbuffers); 250 | typedef void (APIENTRY *glGenerateMipmapEXTPROC) (GLenum target); 251 | typedef void (APIENTRY *glGetFramebufferAttachmentParameterivEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint* params); 252 | typedef void (APIENTRY *glGetRenderbufferParameterivEXTPROC) (GLenum target, GLenum pname, GLint* params); 253 | typedef GLboolean (APIENTRY *glIsFramebufferEXTPROC) (GLuint framebuffer); 254 | typedef GLboolean (APIENTRY *glIsRenderbufferEXTPROC) (GLuint renderbuffer); 255 | typedef void (APIENTRY *glRenderbufferStorageEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); 256 | 257 | 258 | ////////////////////// 259 | //EXT_TEXTURE_RECTANGLE 260 | //(#'s are the same as NV_TEXTURE_RECTANGLE and ARB_TEXTURE_RECTANGLE) 261 | /////////////////////// 262 | #define GL_TEXTURE_RECTANGLE_EXT 0x84F5 263 | #define GL_TEXTURE_BINDING_RECTANGLE_EXT 0x84F6 264 | #define GL_PROXY_TEXTURE_RECTANGLE_EXT 0x84F7 265 | #define GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT 0x84F8 266 | 267 | 268 | /////////////////////// 269 | // GL_ARB_shader_objects 270 | /////////////////////// 271 | #define GL_FRAGMENT_SHADER_ARB 0x8B30 272 | #define GL_VERTEX_SHADER_ARB 0x8B31 273 | #define GL_PROGRAM_OBJECT_ARB 0x8B40 274 | #define GL_SHADER_OBJECT_ARB 0x8B48 275 | #define GL_OBJECT_TYPE_ARB 0x8B4E 276 | #define GL_OBJECT_SUBTYPE_ARB 0x8B4F 277 | #define GL_FLOAT_VEC2_ARB 0x8B50 278 | #define GL_FLOAT_VEC3_ARB 0x8B51 279 | #define GL_FLOAT_VEC4_ARB 0x8B52 280 | #define GL_INT_VEC2_ARB 0x8B53 281 | #define GL_INT_VEC3_ARB 0x8B54 282 | #define GL_INT_VEC4_ARB 0x8B55 283 | #define GL_BOOL_ARB 0x8B56 284 | #define GL_BOOL_VEC2_ARB 0x8B57 285 | #define GL_BOOL_VEC3_ARB 0x8B58 286 | #define GL_BOOL_VEC4_ARB 0x8B59 287 | #define GL_FLOAT_MAT2_ARB 0x8B5A 288 | #define GL_FLOAT_MAT3_ARB 0x8B5B 289 | #define GL_FLOAT_MAT4_ARB 0x8B5C 290 | #define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 291 | #define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 292 | #define GL_OBJECT_LINK_STATUS_ARB 0x8B82 293 | #define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 294 | #define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 295 | #define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 296 | #define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 297 | #define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 298 | #define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 299 | 300 | /* GL types for handling shader object handles and characters */ 301 | typedef char GLcharARB; /* native character */ 302 | //typedef unsigned int GLhandleARB; /* shader object handle */ 303 | 304 | typedef void (APIENTRY * glDeleteObjectARBPROC) (GLhandleARB); 305 | typedef GLhandleARB (APIENTRY * glGetHandleARBPROC) (GLenum); 306 | typedef void (APIENTRY * glDetachObjectARBPROC) (GLhandleARB, GLhandleARB); 307 | typedef GLhandleARB (APIENTRY * glCreateShaderObjectARBPROC) (GLenum); 308 | typedef void (APIENTRY * glShaderSourceARBPROC) (GLhandleARB, GLsizei, const GLcharARB* *, const GLint *); 309 | typedef void (APIENTRY * glCompileShaderARBPROC) (GLhandleARB); 310 | typedef GLhandleARB (APIENTRY * glCreateProgramObjectARBPROC) (void); 311 | typedef void (APIENTRY * glAttachObjectARBPROC) (GLhandleARB, GLhandleARB); 312 | typedef void (APIENTRY * glLinkProgramARBPROC) (GLhandleARB); 313 | typedef void (APIENTRY * glUseProgramObjectARBPROC) (GLhandleARB); 314 | typedef void (APIENTRY * glValidateProgramARBPROC) (GLhandleARB); 315 | typedef void (APIENTRY * glUniform1fARBPROC) (GLint, GLfloat); 316 | typedef void (APIENTRY * glUniform2fARBPROC) (GLint, GLfloat, GLfloat); 317 | typedef void (APIENTRY * glUniform3fARBPROC) (GLint, GLfloat, GLfloat, GLfloat); 318 | typedef void (APIENTRY * glUniform4fARBPROC) (GLint, GLfloat, GLfloat, GLfloat, GLfloat); 319 | typedef void (APIENTRY * glUniform1iARBPROC) (GLint, GLint); 320 | typedef void (APIENTRY * glUniform2iARBPROC) (GLint, GLint, GLint); 321 | typedef void (APIENTRY * glUniform3iARBPROC) (GLint, GLint, GLint, GLint); 322 | typedef void (APIENTRY * glUniform4iARBPROC) (GLint, GLint, GLint, GLint, GLint); 323 | typedef void (APIENTRY * glUniform1fvARBPROC) (GLint, GLsizei, const GLfloat *); 324 | typedef void (APIENTRY * glUniform2fvARBPROC) (GLint, GLsizei, const GLfloat *); 325 | typedef void (APIENTRY * glUniform3fvARBPROC) (GLint, GLsizei, const GLfloat *); 326 | typedef void (APIENTRY * glUniform4fvARBPROC) (GLint, GLsizei, const GLfloat *); 327 | typedef void (APIENTRY * glUniform1ivARBPROC) (GLint, GLsizei, const GLint *); 328 | typedef void (APIENTRY * glUniform2ivARBPROC) (GLint, GLsizei, const GLint *); 329 | typedef void (APIENTRY * glUniform3ivARBPROC) (GLint, GLsizei, const GLint *); 330 | typedef void (APIENTRY * glUniform4ivARBPROC) (GLint, GLsizei, const GLint *); 331 | typedef void (APIENTRY * glUniformMatrix2fvARBPROC) (GLint, GLsizei, GLboolean, const GLfloat *); 332 | typedef void (APIENTRY * glUniformMatrix3fvARBPROC) (GLint, GLsizei, GLboolean, const GLfloat *); 333 | typedef void (APIENTRY * glUniformMatrix4fvARBPROC) (GLint, GLsizei, GLboolean, const GLfloat *); 334 | typedef void (APIENTRY * glGetObjectParameterfvARBPROC) (GLhandleARB, GLenum, GLfloat *); 335 | typedef void (APIENTRY * glGetObjectParameterivARBPROC) (GLhandleARB, GLenum, GLint *); 336 | typedef void (APIENTRY * glGetInfoLogARBPROC) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); 337 | typedef void (APIENTRY * glGetAttachedObjectsARBPROC) (GLhandleARB, GLsizei, GLsizei *, GLhandleARB *); 338 | typedef GLint (APIENTRY * glGetUniformLocationARBPROC) (GLhandleARB, const GLcharARB *); 339 | typedef void (APIENTRY * glGetActiveUniformARBPROC) (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); 340 | typedef void (APIENTRY * glGetUniformfvARBPROC) (GLhandleARB, GLint, GLfloat *); 341 | typedef void (APIENTRY * glGetUniformivARBPROC) (GLhandleARB, GLint, GLint *); 342 | typedef void (APIENTRY * glGetShaderSourceARBPROC) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); 343 | 344 | #ifdef _WIN32 345 | 346 | ////////////////// 347 | //WGL_EXT_SWAP_CONTROL 348 | ////////////////// 349 | typedef BOOL (APIENTRY *wglSwapIntervalEXTPROC) (int interval); 350 | typedef int (APIENTRY *wglGetSwapIntervalEXTPROC) (void); 351 | 352 | #endif 353 | 354 | ///////////////////////////////////////////////////// 355 | /////////////// 356 | //classes to handle extensions 357 | /////////////// 358 | ///////////////////////////////////////////////////// 359 | 360 | class FFGLExtensions 361 | { 362 | public: 363 | FFGLExtensions(); 364 | 365 | void Initialize(); 366 | 367 | //Multitexture 368 | int multitexture; 369 | glActiveTexturePROC glActiveTexture; 370 | glClientActiveTexturePROC glClientActiveTexture; 371 | glMultiTexCoord1dPROC glMultiTexCoord1d; 372 | glMultiTexCoord1dvPROC glMultiTexCoord1dv; 373 | glMultiTexCoord1fPROC glMultiTexCoord1f; 374 | glMultiTexCoord1fvPROC glMultiTexCoord1fv; 375 | glMultiTexCoord1iPROC glMultiTexCoord1i; 376 | glMultiTexCoord1ivPROC glMultiTexCoord1iv; 377 | glMultiTexCoord1sPROC glMultiTexCoord1s; 378 | glMultiTexCoord1svPROC glMultiTexCoord1sv; 379 | glMultiTexCoord2dPROC glMultiTexCoord2d; 380 | glMultiTexCoord2dvPROC glMultiTexCoord2dv; 381 | glMultiTexCoord2fPROC glMultiTexCoord2f; 382 | glMultiTexCoord2fvPROC glMultiTexCoord2fv; 383 | glMultiTexCoord2iPROC glMultiTexCoord2i; 384 | glMultiTexCoord2ivPROC glMultiTexCoord2iv; 385 | glMultiTexCoord2sPROC glMultiTexCoord2s; 386 | glMultiTexCoord2svPROC glMultiTexCoord2sv; 387 | glMultiTexCoord3dPROC glMultiTexCoord3d; 388 | glMultiTexCoord3dvPROC glMultiTexCoord3dv; 389 | glMultiTexCoord3fPROC glMultiTexCoord3f; 390 | glMultiTexCoord3fvPROC glMultiTexCoord3fv; 391 | glMultiTexCoord3iPROC glMultiTexCoord3i; 392 | glMultiTexCoord3ivPROC glMultiTexCoord3iv; 393 | glMultiTexCoord3sPROC glMultiTexCoord3s; 394 | glMultiTexCoord3svPROC glMultiTexCoord3sv; 395 | glMultiTexCoord4dPROC glMultiTexCoord4d; 396 | glMultiTexCoord4dvPROC glMultiTexCoord4dv; 397 | glMultiTexCoord4fPROC glMultiTexCoord4f; 398 | glMultiTexCoord4fvPROC glMultiTexCoord4fv; 399 | glMultiTexCoord4iPROC glMultiTexCoord4i; 400 | glMultiTexCoord4ivPROC glMultiTexCoord4iv; 401 | glMultiTexCoord4sPROC glMultiTexCoord4s; 402 | glMultiTexCoord4svPROC glMultiTexCoord4sv; 403 | 404 | //ARB_shader_objects 405 | int ARB_shader_objects; 406 | glDeleteObjectARBPROC glDeleteObjectARB; 407 | glGetHandleARBPROC glGetHandleARB; 408 | glDetachObjectARBPROC glDetachObjectARB; 409 | glCreateShaderObjectARBPROC glCreateShaderObjectARB; 410 | glShaderSourceARBPROC glShaderSourceARB; 411 | glCompileShaderARBPROC glCompileShaderARB; 412 | glCreateProgramObjectARBPROC glCreateProgramObjectARB; 413 | glAttachObjectARBPROC glAttachObjectARB; 414 | glLinkProgramARBPROC glLinkProgramARB; 415 | glUseProgramObjectARBPROC glUseProgramObjectARB; 416 | glValidateProgramARBPROC glValidateProgramARB; 417 | glUniform1fARBPROC glUniform1fARB; 418 | glUniform2fARBPROC glUniform2fARB; 419 | glUniform3fARBPROC glUniform3fARB; 420 | glUniform4fARBPROC glUniform4fARB; 421 | glUniform1iARBPROC glUniform1iARB; 422 | glUniform2iARBPROC glUniform2iARB; 423 | glUniform3iARBPROC glUniform3iARB; 424 | glUniform4iARBPROC glUniform4iARB; 425 | glUniform1fvARBPROC glUniform1fvARB; 426 | glUniform2fvARBPROC glUniform2fvARB; 427 | glUniform3fvARBPROC glUniform3fvARB; 428 | glUniform4fvARBPROC glUniform4fvARB; 429 | glUniform1ivARBPROC glUniform1ivARB; 430 | glUniform2ivARBPROC glUniform2ivARB; 431 | glUniform3ivARBPROC glUniform3ivARB; 432 | glUniform4ivARBPROC glUniform4ivARB; 433 | glUniformMatrix2fvARBPROC glUniformMatrix2fvARB; 434 | glUniformMatrix3fvARBPROC glUniformMatrix3fvARB; 435 | glUniformMatrix4fvARBPROC glUniformMatrix4fvARB; 436 | glGetObjectParameterfvARBPROC glGetObjectParameterfvARB; 437 | glGetObjectParameterivARBPROC glGetObjectParameterivARB; 438 | glGetInfoLogARBPROC glGetInfoLogARB; 439 | glGetAttachedObjectsARBPROC glGetAttachedObjectsARB; 440 | glGetUniformLocationARBPROC glGetUniformLocationARB; 441 | glGetActiveUniformARBPROC glGetActiveUniformARB; 442 | glGetUniformfvARBPROC glGetUniformfvARB; 443 | glGetUniformivARBPROC glGetUniformivARB; 444 | glGetShaderSourceARBPROC glGetShaderSourceARB; 445 | 446 | //EXT_framebuffer_object 447 | int EXT_framebuffer_object; 448 | glBindFramebufferEXTPROC glBindFramebufferEXT; 449 | glBindRenderbufferEXTPROC glBindRenderbufferEXT; 450 | glCheckFramebufferStatusEXTPROC glCheckFramebufferStatusEXT; 451 | glDeleteFramebuffersEXTPROC glDeleteFramebuffersEXT; 452 | glDeleteRenderBuffersEXTPROC glDeleteRenderBuffersEXT; 453 | glFramebufferRenderbufferEXTPROC glFramebufferRenderbufferEXT; 454 | glFramebufferTexture1DEXTPROC glFramebufferTexture1DEXT; 455 | glFramebufferTexture2DEXTPROC glFramebufferTexture2DEXT; 456 | glFramebufferTexture3DEXTPROC glFramebufferTexture3DEXT; 457 | glGenFramebuffersEXTPROC glGenFramebuffersEXT; 458 | glGenRenderbuffersEXTPROC glGenRenderbuffersEXT; 459 | glGenerateMipmapEXTPROC glGenerateMipmapEXT; 460 | glGetFramebufferAttachmentParameterivEXTPROC glGetFramebufferAttachmentParameterivEXT; 461 | glGetRenderbufferParameterivEXTPROC glGetRenderbufferParameterivEXT; 462 | glIsFramebufferEXTPROC glIsFramebufferEXT; 463 | glIsRenderbufferEXTPROC glIsRenderbufferEXT; 464 | glRenderbufferStorageEXTPROC glRenderbufferStorageEXT; 465 | 466 | #ifdef _WIN32 467 | int WGL_EXT_swap_control; 468 | wglSwapIntervalEXTPROC wglSwapIntervalEXT; 469 | wglGetSwapIntervalEXTPROC wglGetSwapIntervalEXT; 470 | #endif 471 | 472 | private: 473 | void *GetProcAddress(char *); 474 | 475 | void InitMultitexture(); 476 | void InitARBShaderObjects(); 477 | void InitEXTFramebufferObject(); 478 | 479 | #ifdef _WIN32 480 | void InitWGLEXTSwapControl(); 481 | #endif 482 | }; 483 | 484 | #endif 485 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLFBO.cpp: -------------------------------------------------------------------------------- 1 | #include "FFGLFBO.h" 2 | 3 | int FFGLFBO::Create(int _width, 4 | int _height, 5 | FFGLExtensions &e) 6 | { 7 | int glWidth = 1; 8 | while (glWidth<_width) glWidth*=2; 9 | 10 | int glHeight = 1; 11 | while (glHeight<_height) glHeight*=2; 12 | 13 | m_width = _width; 14 | m_height = _height; 15 | m_glWidth = glWidth; 16 | m_glHeight = glHeight; 17 | m_glPixelFormat = GL_RGBA8; 18 | m_glTextureTarget = GL_TEXTURE_2D; 19 | 20 | m_glTextureHandle = 0; 21 | 22 | e.glGenFramebuffersEXT(1, &m_fboHandle); 23 | 24 | return 1; 25 | } 26 | 27 | int IsTextureResident(GLuint handle) 28 | { 29 | GLboolean b; 30 | 31 | if (glAreTexturesResident(1, &handle, &b)) 32 | return 1; 33 | 34 | return 0; 35 | } 36 | 37 | 38 | int FFGLFBO::BindAsRenderTarget(FFGLExtensions &e) 39 | { 40 | //make our fbo active 41 | e.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboHandle); 42 | 43 | //make sure there's a valid depth buffer attached to it 44 | if (e.glIsRenderbufferEXT(m_depthBufferHandle)==0) 45 | { 46 | e.glGenRenderbuffersEXT(1, &m_depthBufferHandle); 47 | e.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBufferHandle); 48 | e.glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, m_glWidth, m_glHeight); 49 | 50 | //attach our depth buffer to the fbo 51 | e.glFramebufferRenderbufferEXT( 52 | GL_FRAMEBUFFER_EXT, 53 | GL_DEPTH_ATTACHMENT_EXT, 54 | GL_RENDERBUFFER_EXT, 55 | m_depthBufferHandle); 56 | } 57 | 58 | //make sure we have a valid gl texture attached to it 59 | if (!IsTextureResident(m_glTextureHandle)) 60 | { 61 | //get a new one 62 | glGenTextures(1,&m_glTextureHandle); 63 | 64 | //bind it for some initialization 65 | glBindTexture(m_glTextureTarget, m_glTextureHandle); 66 | 67 | //this only works if the FBO pixel format 68 | //is GL_RGBA8. other FBO pixel formats have to 69 | //define their texture differently 70 | GLuint pformat = GL_RGBA; 71 | GLuint ptype = GL_UNSIGNED_BYTE; 72 | 73 | glTexImage2D( 74 | m_glTextureTarget, //texture target 75 | 0, //mipmap level 76 | m_glPixelFormat, //gl internal pixel format 77 | m_glWidth, //gl width 78 | m_glHeight, //gl height 79 | 0, //no border 80 | pformat, //pixel format #2 81 | ptype, //pixel type 82 | NULL); //null texture image data pointer 83 | 84 | //for now, do not do mipmapping. 85 | //to do mipmapping, set this to 1, and after we've bound the texture, 86 | //we would need to call glGenerateMipmapEXT(m_textureTarget) to make sure 87 | //the mipmaps have been updated 88 | int do_mipmaps = 0; 89 | 90 | if (do_mipmaps) 91 | e.glGenerateMipmapEXT(m_glTextureTarget); 92 | 93 | glTexParameteri(m_glTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 94 | 95 | if (do_mipmaps) 96 | glTexParameteri(m_glTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 97 | else 98 | glTexParameteri(m_glTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 99 | 100 | glTexParameteri(m_glTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 101 | glTexParameteri(m_glTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 102 | 103 | //unbind the texture 104 | glBindTexture(m_glTextureTarget, 0); 105 | 106 | //attach our texture to the FBO 107 | e.glFramebufferTexture2DEXT( 108 | GL_FRAMEBUFFER_EXT, 109 | GL_COLOR_ATTACHMENT0_EXT, 110 | m_glTextureTarget, 111 | m_glTextureHandle, 112 | 0); 113 | } 114 | 115 | GLenum status = e.glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ); 116 | 117 | switch(status) 118 | { 119 | case GL_FRAMEBUFFER_COMPLETE_EXT: 120 | //no error 121 | break; 122 | 123 | case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 124 | //FFDebugMessage("GL_FRAMEBUFFER_UNSUPPORTED_EXT"); 125 | return 0; 126 | 127 | case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: 128 | //FFDebugMessage("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT"); 129 | return 0; 130 | 131 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: 132 | //FFDebugMessage("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT"); 133 | return 0; 134 | 135 | case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: 136 | //FFDebugMessage("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT"); 137 | return 0; 138 | 139 | case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: 140 | //FFDebugMessage("GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT"); 141 | return 0; 142 | 143 | case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: 144 | //FFDebugMessage("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT"); 145 | return 0; 146 | 147 | case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: 148 | //FFDebugMessage("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT"); 149 | return 0; 150 | 151 | default: 152 | //FFDebugMessage("Unknown GL_FRAMEBUFFER error"); 153 | return 0; 154 | } 155 | 156 | return 1; 157 | } 158 | 159 | int FFGLFBO::UnbindAsRenderTarget(FFGLExtensions &e) 160 | { 161 | e.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 162 | return 1; 163 | } 164 | 165 | FFGLTextureStruct FFGLFBO::GetTextureInfo() 166 | { 167 | FFGLTextureStruct t; 168 | 169 | t.Width = m_width; 170 | t.Height = m_height; 171 | 172 | t.HardwareWidth = m_glWidth; 173 | t.HardwareHeight = m_glHeight; 174 | 175 | t.Handle = m_glTextureHandle; 176 | 177 | return t; 178 | } 179 | 180 | 181 | void FFGLFBO::FreeResources(FFGLExtensions &e) 182 | { 183 | if (m_fboHandle) 184 | { 185 | e.glDeleteFramebuffersEXT(1, &m_fboHandle); 186 | m_fboHandle = 0; 187 | } 188 | 189 | if (m_depthBufferHandle) 190 | { 191 | e.glDeleteRenderBuffersEXT(1, &m_depthBufferHandle); 192 | m_depthBufferHandle = 0; 193 | } 194 | 195 | if (m_glTextureHandle) 196 | { 197 | glDeleteTextures(1, &m_glTextureHandle); 198 | m_glTextureHandle = 0; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLFBO.h: -------------------------------------------------------------------------------- 1 | #ifndef FFGLFBO_H 2 | #define FFGLFBO_H 3 | 4 | #include 5 | #include 6 | 7 | class FFGLFBO 8 | { 9 | public: 10 | FFGLFBO() 11 | :m_width(0), 12 | m_height(0), 13 | m_glWidth(0), 14 | m_glHeight(0), 15 | m_glPixelFormat(0), 16 | m_glTextureTarget(0), 17 | m_glTextureHandle(0), 18 | m_fboHandle(0), 19 | m_depthBufferHandle(0) 20 | {} 21 | 22 | int Create(int width, int height, FFGLExtensions &e); 23 | int BindAsRenderTarget(FFGLExtensions &e); 24 | int UnbindAsRenderTarget(FFGLExtensions &e); 25 | 26 | FFGLTextureStruct GetTextureInfo(); 27 | 28 | void FreeResources(FFGLExtensions &e); 29 | 30 | GLuint GetWidth() { return m_width; } 31 | GLuint GetHeight() { return m_height; } 32 | GLuint GetFBOHandle() { return m_fboHandle; } 33 | 34 | protected: 35 | GLuint m_width; 36 | GLuint m_height; 37 | GLuint m_glWidth; 38 | GLuint m_glHeight; 39 | GLuint m_glPixelFormat; 40 | GLuint m_glTextureTarget; 41 | GLuint m_glTextureHandle; 42 | GLuint m_fboHandle; 43 | GLuint m_depthBufferHandle; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLLib.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // FFGLLib.h 3 | // 4 | // FreeFrame is an open-source cross-platform real-time video effects plugin system. 5 | // It provides a framework for developing video effects plugins and hosts on Windows, 6 | // Linux and Mac OSX. 7 | // 8 | // Copyright (c) 2006 www.freeframe.org 9 | // All rights reserved. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 14 | // FFGLLib.h by Trey Harrison 15 | // www.harrisondigitalmedia.com 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 19 | // 20 | // Redistribution and use in source and binary forms, with or without modification, 21 | // are permitted provided that the following conditions are met: 22 | // 23 | // * Redistributions of source code must retain the above copyright 24 | // notice, this list of conditions and the following disclaimer. 25 | // * Redistributions in binary form must reproduce the above copyright 26 | // notice, this list of conditions and the following disclaimer in 27 | // the documentation and/or other materials provided with the 28 | // distribution. 29 | // * Neither the name of FreeFrame nor the names of its 30 | // contributors may be used to endorse or promote products derived 31 | // from this software without specific prior written permission. 32 | // 33 | // 34 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 35 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 36 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 37 | // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 39 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 40 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 41 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 42 | // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 43 | // OF THE POSSIBILITY OF SUCH DAMAGE. 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | 47 | #ifndef __FFGLLIB_H__ 48 | #define __FFGLLIB_H__ 49 | 50 | //FFGLTexCoords 51 | typedef struct FFGLTexCoordsTag 52 | { 53 | GLdouble s,t; 54 | } FFGLTexCoords; 55 | 56 | //helper function to return the s,t,r coordinate 57 | //that cooresponds to the width,height,depth of the used 58 | //portion of the texture 59 | inline FFGLTexCoords GetMaxGLTexCoords(FFGLTextureStruct t) 60 | { 61 | FFGLTexCoords texCoords; 62 | 63 | //the texture may only occupy a portion 64 | //of the allocated hardware texture memory 65 | 66 | //normalized (0..1) S and T coords 67 | texCoords.s = ((GLdouble)t.Width) / (GLdouble)t.HardwareWidth; 68 | texCoords.t = ((GLdouble)t.Height) / (GLdouble)t.HardwareHeight; 69 | 70 | return texCoords; 71 | } 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginInfo.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Last modified: 2004-11-10 15 | // 16 | 17 | #include "FFGLPluginInfo.h" 18 | 19 | #include 20 | #include 21 | 22 | extern CFFGLPluginInfo* g_CurrPluginInfo; 23 | 24 | 25 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 26 | // CFFGLPluginInfo constructor and destructor 27 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 28 | 29 | CFFGLPluginInfo::CFFGLPluginInfo( 30 | FPCREATEINSTANCEGL* pCreateInstance, 31 | const char* pchUniqueID, 32 | const char* pchPluginName, 33 | DWORD dwAPIMajorVersion, 34 | DWORD dwAPIMinorVersion, 35 | DWORD dwPluginMajorVersion, 36 | DWORD dwPluginMinorVersion, 37 | DWORD dwPluginType, 38 | const char* pchDescription, 39 | const char* pchAbout, 40 | DWORD dwFreeFrameExtendedDataSize, 41 | const void* pFreeFrameExtendedDataBlock 42 | ) 43 | { 44 | m_pCreateInstance = pCreateInstance; 45 | 46 | // Filling PluginInfoStruct 47 | m_PluginInfo.APIMajorVersion = dwAPIMajorVersion; 48 | m_PluginInfo.APIMinorVersion = dwAPIMinorVersion; 49 | 50 | bool bEndFound = false; 51 | for (int i = 0; (i < 16) && (!bEndFound); ++i) { 52 | if (pchPluginName[i] == 0) bEndFound = true; 53 | (m_PluginInfo.PluginName)[i] = (bEndFound) ? 0 : pchPluginName[i]; 54 | } 55 | 56 | bEndFound = false; 57 | for (int j = 0; (j < 4) && (!bEndFound); ++j) { 58 | if (pchUniqueID[j] == 0) bEndFound = true; 59 | (m_PluginInfo.PluginUniqueID)[j] = (bEndFound) ? 0 : pchUniqueID[j]; 60 | } 61 | 62 | m_PluginInfo.PluginType = dwPluginType; 63 | 64 | // Filling PluginExtendedInfoStruct 65 | m_PluginExtendedInfo.About = strdup(pchAbout); 66 | m_PluginExtendedInfo.Description = strdup(pchDescription); 67 | m_PluginExtendedInfo.PluginMajorVersion = dwPluginMajorVersion; 68 | m_PluginExtendedInfo.PluginMinorVersion = dwPluginMinorVersion; 69 | if ((dwFreeFrameExtendedDataSize > 0) && (pFreeFrameExtendedDataBlock != NULL)) { 70 | memcpy(m_PluginExtendedInfo.FreeFrameExtendedDataBlock, pFreeFrameExtendedDataBlock, dwFreeFrameExtendedDataSize); 71 | m_PluginExtendedInfo.FreeFrameExtendedDataSize = dwFreeFrameExtendedDataSize; 72 | } 73 | else { 74 | m_PluginExtendedInfo.FreeFrameExtendedDataBlock = NULL; 75 | m_PluginExtendedInfo.FreeFrameExtendedDataSize = 0; 76 | } 77 | 78 | g_CurrPluginInfo = this; 79 | } 80 | 81 | CFFGLPluginInfo::~CFFGLPluginInfo() 82 | { 83 | free(m_PluginExtendedInfo.About); 84 | free(m_PluginExtendedInfo.Description); 85 | } 86 | 87 | 88 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 89 | // CFFGLPluginInfo methods 90 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 91 | 92 | const PluginInfoStruct* CFFGLPluginInfo::GetPluginInfo() const 93 | { 94 | return &m_PluginInfo; 95 | } 96 | 97 | const PluginExtendedInfoStruct* CFFGLPluginInfo::GetPluginExtendedInfo() const 98 | { 99 | return &m_PluginExtendedInfo; 100 | } 101 | 102 | FPCREATEINSTANCEGL* CFFGLPluginInfo::GetFactoryMethod() const 103 | { 104 | return m_pCreateInstance; 105 | } 106 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Developer: Trey Harrison 15 | // www.harrisondigitalmedia.com 16 | // 17 | // Last modified: Oct. 26 2006 18 | // 19 | 20 | #ifndef FFGLPLUGININFO_STANDARD 21 | #define FFGLPLUGININFO_STANDARD 22 | 23 | #include "FFGL.h" 24 | 25 | #ifdef TARGET_OS_MAC 26 | //there is no need for __stdcall on mac, so this will eliminate any 27 | //usage of it 28 | #define __stdcall 29 | #endif 30 | 31 | #ifdef __linux__ 32 | #define __stdcall 33 | #endif 34 | 35 | //FPCREATEINSTANCEGL is a pointer to a function that creates FFGL plugins 36 | //in this SDK, all FFGL plugins must derive from CFreeFrameGLPlugin 37 | typedef DWORD __stdcall FPCREATEINSTANCEGL(class CFreeFrameGLPlugin **ppOutInstance); 38 | 39 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 40 | /// \class CFFGLPluginInfo 41 | /// \brief CFFGLPluginInfo manages static information concerning a plugin name, version, and description. 42 | /// \author Gualtiero Volpe 43 | /// \date 20041110 44 | /// \version 1.0.0.2 45 | /// 46 | /// The CFFGLPluginInfo class manages static information related to a FreeFrameGL plugin. Examples are the name of 47 | /// the plugin, its unique identifier, its type (either source or effect), the current version, the version of 48 | /// the FreeFrame API the plugin refers to, a short description of the plugin, information about the developer(s) 49 | /// and possible copyright. In other words, this class stores the information required by the FreeFrame getInfo 50 | /// and getExtendedInfo global functions. 51 | /// The CFFGLPluginInfo class is also involved in the process of creating an instance of the subclass implementing 52 | /// a plugin: it stores a pointer to the factory method of the plugin subclass, which is called when the plugin 53 | /// object needs to be instantiated. The FreeFrame SDK keeps a prototype instance of the plugin in order to be able 54 | /// to access information on the plugin at any time. The effectively working instance is created at the time the 55 | /// plugin is instantiated by the host. 56 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 57 | 58 | class CFFGLPluginInfo { 59 | 60 | public: 61 | 62 | /// The constructor of CFFGLPluginInfo receives through its parameters the information that needs 63 | /// to be stored. 64 | /// 65 | /// \param pCreateInstance A pointer to the factory method of the subclass implementing 66 | /// the plugin. 67 | /// \param pchUniqueID A string representing the unique identificator of the plugin. 68 | /// According to the FreeFrame specification, it must be a not null 69 | /// terminated string of 4 1-byte ASCII characters. Longer strings will 70 | /// be truncated at the 4th character. 71 | /// \param pchPluginName A string containing the name of the plugin. According to the 72 | /// FreeFrame specification, it must be a not null terminated string 73 | /// of 16 1-byte ASCII characters. Longer strings will be truncated at 74 | /// the 16th character. 75 | /// \param dwAPIMajorVersion The major version number of the FreeFrame API employed by the plugin. 76 | /// It is the number before the decimal point in the API version number. 77 | /// \param dwAPIMinorVersion The minor version number of the FreeFrame API employed by the plugin. 78 | /// It is the number after the decimal point in the API version number. 79 | /// \param dwPluginMajorVersion The major version number of the plugin. It is the number before 80 | /// the decimal point in the plugin version number. 81 | /// \param dwPluginMinorVersion The minor version number of the plugin. It is the number after 82 | /// the decimal point in the plugin version number. 83 | /// \param dwPluginType The type of the plugin. According to the FreeFrame specification, 84 | /// it should be 0 in case of effect plugins and 1 in case of source 85 | /// plugins. 86 | /// \param pchDescription A string providing a short description of what the plugin does. 87 | /// \param pchAbout A string providing information on the developer(s) of the plugin, 88 | /// their possible company, and possible copyright information. 89 | /// \param dwFreeFrameExtendedDataSize Size in bytes of the FreeFrame ExtendedDataBlock, or 0 if not 90 | /// provided by plugin. Extended Data Bloks are not yet exploited 91 | /// in the current version of the FreeFrame specification (1.0). 92 | /// Therefore, at the moment the default value (0) should be used 93 | /// for this parameter. 94 | /// \param pFreeFrameExtendedDataBlock 32-bit pointer to a FreeFrame ExtendedDataBlock, Extended 95 | /// Data Bloks are not yet expolited by the FreeFrame specification 96 | /// version 1.0. Therefore, at the moment the default value (NULL) 97 | /// should be used for this parameter 98 | CFFGLPluginInfo( 99 | FPCREATEINSTANCEGL* pCreateInstance, 100 | const char* pchUniqueID, 101 | const char* pchPluginName, 102 | DWORD dwAPIMajorVersion, 103 | DWORD dwAPIMinorVersion, 104 | DWORD dwPluginMajorVersion, 105 | DWORD dwPluginMinorVersion, 106 | DWORD dwPluginType, 107 | const char* pchDescription, 108 | const char* pchAbout, 109 | DWORD dwFreeFrameExtendedDataSize = 0, 110 | const void* pFreeFrameExtendedDataBlock = NULL 111 | ); 112 | 113 | /// The standard destructor of CFFGLPluginInfo. 114 | ~CFFGLPluginInfo(); 115 | 116 | /// This method returns a pointer to a PluginInfoStruct as defined in FreeFrame.h. Such structure 117 | /// contains information on the plugin name and type, its unique identifier, and the version of the 118 | /// FreeFrame API it uses. 119 | /// 120 | /// \return A pointer to a PluginInfoStruct containing information on the plugin. For further 121 | /// information on the definition of PluginInfoStruct see the header file FreeFrame.h and 122 | /// the FreeFrame specification version 1.0. 123 | const PluginInfoStruct* GetPluginInfo() const; 124 | 125 | /// This method returns a pointer to a PluginExtendedInfoStruct (for further information see 126 | /// FreeFrame.h and the FreeFrame specification). A PluginExtendedInfoStruct contains information on 127 | /// the plugin version, a short description of the plugin, and information about the developer(s) and 128 | /// possible copyright issues. 129 | /// 130 | /// \return A pointer to a PluginExtendedInfoStruct containing information on the plugin. 131 | /// For further information on the definition PluginExtendedInfoStruct see the header file 132 | /// FreeFrame.h and the FreeFrame specification version 1.0. 133 | const PluginExtendedInfoStruct* GetPluginExtendedInfo() const; 134 | 135 | /// This method returns a pointer to the factory method of the subclass implementing the plugin. It is 136 | /// called by the FreeFrame SDK when creating a new instance of the plugin. 137 | /// 138 | /// \return A pointer to the factory method of the plugin subclass. 139 | FPCREATEINSTANCEGL* GetFactoryMethod() const; 140 | 141 | private: 142 | 143 | // Structures containing information about the plugin 144 | PluginInfoStruct m_PluginInfo; 145 | PluginExtendedInfoStruct m_PluginExtendedInfo; 146 | 147 | // Pointer to the factory method of the plugin subclass 148 | FPCREATEINSTANCEGL* m_pCreateInstance; 149 | }; 150 | 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginInfoData.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FFGLPluginInfoData.cpp 3 | // 4 | // Usually you do not need to edit this file! 5 | // 6 | 7 | #include "FFGLPluginInfo.h" 8 | 9 | 10 | ////////////////////////////////////////////////////////////////// 11 | // Information about the plugin 12 | ////////////////////////////////////////////////////////////////// 13 | 14 | CFFGLPluginInfo* g_CurrPluginInfo = NULL; 15 | 16 | 17 | ////////////////////////////////////////////////////////////////// 18 | // Plugin dll entry point 19 | ////////////////////////////////////////////////////////////////// 20 | #ifdef _WIN32 21 | BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 22 | { 23 | return TRUE; 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginInstance.cpp: -------------------------------------------------------------------------------- 1 | #include "FFGLPluginInstance.h" 2 | #include "FFDebugMessage.h" 3 | #include 4 | 5 | FFGLPluginInstance:: FFGLPluginInstance() 6 | :m_ffPluginMain(NULL), 7 | m_ffInstanceID(INVALIDINSTANCE), 8 | m_numParameters(0) 9 | { 10 | int i; 11 | for (i=0; i=MAX_PARAMETERS) 26 | return; 27 | 28 | int i = paramNum; 29 | 30 | if (m_paramNames[i]!=NULL) 31 | delete m_paramNames[i]; 32 | 33 | m_paramNames[i] = new char[strlen(name)+1]; 34 | strcpy(m_paramNames[i], name); 35 | } 36 | 37 | const char *FFGLPluginInstance::GetParameterName(int paramNum) 38 | { 39 | if (paramNum<0 || paramNum>=MAX_PARAMETERS) 40 | return ""; 41 | 42 | if (m_paramNames[paramNum]!=NULL) 43 | return m_paramNames[paramNum]; 44 | 45 | return ""; 46 | } 47 | 48 | void FFGLPluginInstance::SetFloatParameter(int paramNum, float value) 49 | { 50 | if (paramNum<0 || paramNum>=m_numParameters || 51 | m_ffInstanceID==INVALIDINSTANCE || m_ffPluginMain==NULL) 52 | { 53 | //the parameter or the plugin doesn't exist 54 | return; 55 | } 56 | 57 | //make sure its a float parameter type 58 | DWORD ffParameterType = m_ffPluginMain(FF_GETPARAMETERTYPE,(DWORD)paramNum,0).ivalue; 59 | if (ffParameterType!=FF_TYPE_TEXT) 60 | { 61 | SetParameterStruct ArgStruct; 62 | ArgStruct.ParameterNumber = paramNum; 63 | 64 | //be careful with this cast.. ArgStruct.NewParameterValue is DWORD 65 | //for this to compile correctly, sizeof(DWORD) must == sizeof(float) 66 | *((float *)(unsigned)&ArgStruct.NewParameterValue) = value; 67 | 68 | m_ffPluginMain(FF_SETPARAMETER,(DWORD)(&ArgStruct), m_ffInstanceID); 69 | } 70 | } 71 | 72 | void FFGLPluginInstance::SetTime(double curTime) 73 | { 74 | if (m_ffInstanceID==INVALIDINSTANCE || m_ffPluginMain==NULL) 75 | { 76 | FFDebugMessage("Invalid SetTime call"); 77 | return; 78 | } 79 | 80 | m_ffPluginMain(FF_SETTIME, (DWORD)(&curTime), m_ffInstanceID); 81 | } 82 | 83 | float FFGLPluginInstance::GetFloatParameter(int paramNum) 84 | { 85 | if (paramNum<0 || paramNum>=m_numParameters || 86 | m_ffInstanceID==INVALIDINSTANCE || m_ffPluginMain==NULL) 87 | { 88 | FFDebugMessage("Invalid GetFloatParameter call"); 89 | return 0.f; 90 | } 91 | 92 | //make sure its a float parameter type 93 | DWORD ffParameterType = m_ffPluginMain(FF_GETPARAMETERTYPE,(DWORD)paramNum,0).ivalue; 94 | if (ffParameterType!=FF_TYPE_TEXT) 95 | { 96 | plugMainUnion result = m_ffPluginMain(FF_GETPARAMETER,(DWORD)paramNum, m_ffInstanceID); 97 | 98 | //make sure the call to get the parameter succeeded before 99 | //reading the float value 100 | if (result.ivalue!=FF_FAIL) 101 | { 102 | return result.fvalue; 103 | } 104 | } 105 | 106 | return 0.f; 107 | } 108 | 109 | DWORD FFGLPluginInstance::CallProcessOpenGL(ProcessOpenGLStructTag &t) 110 | { 111 | //make sure we have code to call otherwise return the unprocessed input 112 | if (m_ffPluginMain==NULL || m_ffInstanceID==INVALIDINSTANCE) 113 | { 114 | FFDebugMessage("Invalid CallProcessOpenGL call"); 115 | return FF_FAIL; 116 | } 117 | 118 | DWORD retVal = FF_FAIL; 119 | 120 | try 121 | { 122 | retVal = m_ffPluginMain(FF_PROCESSOPENGL, (DWORD)&t, m_ffInstanceID).ivalue; 123 | } 124 | catch (...) 125 | { 126 | FFDebugMessage("Error on call to FreeFrame::ProcessFrame"); 127 | retVal = FF_FAIL; 128 | } 129 | 130 | return retVal; 131 | } 132 | 133 | void FFGLPluginInstance::ReleaseParamNames() 134 | { 135 | int i; 136 | for (i=0; i 5 | 6 | class FFGLPluginInstance 7 | { 8 | public: 9 | //each platform implements this and returns 10 | //a class that derives from FFGLPluginInstance 11 | //(that class implements the real Load and Unload methods which 12 | //by default return FF_FAIL below) 13 | static FFGLPluginInstance *New(); 14 | 15 | FFGLPluginInstance(); 16 | 17 | //these methods are virtual because each platform implements 18 | //dynamic libraries differently 19 | virtual DWORD Load(const char *filename) 20 | { 21 | return FF_FAIL; 22 | } 23 | 24 | //calls plugMain(FF_INSTANTIATEGL) and assigns 25 | //each parameter its default value 26 | DWORD InstantiateGL(const FFGLViewportStruct *vp); 27 | 28 | //calls plugMain(FF_DEINSTANTIATEGL) 29 | DWORD DeInstantiateGL(); 30 | 31 | virtual DWORD Unload() 32 | { 33 | return FF_FAIL; 34 | } 35 | 36 | //these methods are shared by the 37 | //platform-specific implementations 38 | const char *GetParameterName(int paramNum); 39 | float GetFloatParameter(int paramNum); 40 | void SetFloatParameter(int paramNum, float value); 41 | void SetTime(double curTime); 42 | 43 | DWORD CallProcessOpenGL(ProcessOpenGLStructTag &t); 44 | 45 | virtual ~FFGLPluginInstance(); 46 | 47 | protected: 48 | FF_Main_FuncPtr m_ffPluginMain; 49 | 50 | //many plugins will return 0x00000000 as the first valid instance, 51 | //so we use 0xFFFFFFFF to represent an uninitialized/invalid instance 52 | enum { INVALIDINSTANCE=0xFFFFFFFF }; 53 | DWORD m_ffInstanceID; 54 | 55 | enum { MAX_PARAMETERS = 64 }; 56 | int m_numParameters; 57 | char *m_paramNames[MAX_PARAMETERS]; 58 | 59 | //helper methods 60 | //calls plugMain(FF_INITIALISE) and gets the 61 | //parameter names 62 | DWORD InitPluginLibrary(); 63 | 64 | //calls DeletePluginInstance if needed, calls 65 | //ReleaseParamNames, then calls plugMain(FF_DEINITIALISE) 66 | DWORD DeinitPluginLibrary(); 67 | 68 | void SetParameterName(int paramNum, const char *srcString); 69 | void ReleaseParamNames(); 70 | }; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Last modified: Oct 25 2006 by Trey Harrison 15 | // email:trey@harrisondigitalmedia.com 16 | 17 | #include "FFGLPluginManager.h" 18 | #include "FFGLPluginSDK.h" 19 | 20 | #include 21 | #include 22 | 23 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 24 | // CFFGLPluginManager constructor and destructor 25 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 26 | 27 | CFFGLPluginManager::CFFGLPluginManager() 28 | { 29 | m_iMinInputs = 0; 30 | m_iMaxInputs = 0; 31 | m_timeSupported = 0; 32 | 33 | m_NParams = 0; 34 | m_pFirst = NULL; 35 | m_pLast = NULL; 36 | } 37 | 38 | CFFGLPluginManager::~CFFGLPluginManager() 39 | { 40 | if (m_pFirst != NULL) 41 | { 42 | ParamInfo* pCurr = m_pFirst; 43 | ParamInfo* pNext = m_pFirst; 44 | 45 | while (pCurr != NULL) 46 | { 47 | pNext = pCurr->pNext; 48 | 49 | if ( (pCurr->dwType == FF_TYPE_TEXT) && 50 | (pCurr->StrDefaultValue != NULL) ) 51 | { 52 | free(pCurr->StrDefaultValue); 53 | } 54 | 55 | delete pCurr; 56 | pCurr = pNext; 57 | } 58 | } 59 | 60 | m_pFirst = NULL; 61 | m_pLast = NULL; 62 | } 63 | 64 | 65 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 66 | // CFFGLPluginManager methods 67 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 68 | void CFFGLPluginManager::SetMinInputs(int iMinInputs) 69 | { 70 | m_iMinInputs = iMinInputs; 71 | } 72 | 73 | void CFFGLPluginManager::SetMaxInputs(int iMaxInputs) 74 | { 75 | m_iMaxInputs = iMaxInputs; 76 | } 77 | 78 | void CFFGLPluginManager::SetParamInfo(DWORD dwIndex, const char* pchName, DWORD dwType, float fDefaultValue) 79 | { 80 | ParamInfo* pInfo = new ParamInfo; 81 | pInfo->ID = dwIndex; 82 | 83 | bool bEndFound = false; 84 | for (int i = 0; i < 16; ++i) { 85 | if (pchName[i] == 0) bEndFound = true; 86 | pInfo->Name[i] = (bEndFound) ? 0 : pchName[i]; 87 | } 88 | 89 | pInfo->dwType = dwType; 90 | if (fDefaultValue > 1.0) fDefaultValue = 1.0; 91 | if (fDefaultValue < 0.0) fDefaultValue = 0.0; 92 | pInfo->DefaultValue = fDefaultValue; 93 | pInfo->StrDefaultValue = NULL; 94 | pInfo->pNext = NULL; 95 | if (m_pFirst == NULL) m_pFirst = pInfo; 96 | if (m_pLast != NULL) m_pLast->pNext = pInfo; 97 | m_pLast = pInfo; 98 | m_NParams++; 99 | } 100 | 101 | void CFFGLPluginManager::SetParamInfo(DWORD dwIndex, const char* pchName, DWORD dwType, bool bDefaultValue) 102 | { 103 | ParamInfo* pInfo = new ParamInfo; 104 | pInfo->ID = dwIndex; 105 | 106 | bool bEndFound = false; 107 | for (int i = 0; i < 16; ++i) { 108 | if (pchName[i] == 0) bEndFound = true; 109 | pInfo->Name[i] = (bEndFound) ? 0 : pchName[i]; 110 | } 111 | 112 | pInfo->dwType = dwType; 113 | pInfo->DefaultValue = bDefaultValue ? 1.0f : 0.0f; 114 | pInfo->StrDefaultValue = NULL; 115 | pInfo->pNext = NULL; 116 | if (m_pFirst == NULL) m_pFirst = pInfo; 117 | if (m_pLast != NULL) m_pLast->pNext = pInfo; 118 | m_pLast = pInfo; 119 | m_NParams++; 120 | } 121 | 122 | void CFFGLPluginManager::SetParamInfo(DWORD dwIndex, const char* pchName, DWORD dwType, const char* pchDefaultValue) 123 | { 124 | ParamInfo* pInfo = new ParamInfo; 125 | pInfo->ID = dwIndex; 126 | 127 | bool bEndFound = false; 128 | for (int i = 0; i < 16; ++i) { 129 | if (pchName[i] == 0) bEndFound = true; 130 | pInfo->Name[i] = (bEndFound) ? 0 : pchName[i]; 131 | } 132 | 133 | pInfo->dwType = dwType; 134 | pInfo->DefaultValue = 0; 135 | pInfo->StrDefaultValue = strdup(pchDefaultValue); 136 | pInfo->pNext = NULL; 137 | if (m_pFirst == NULL) m_pFirst = pInfo; 138 | if (m_pLast != NULL) m_pLast->pNext = pInfo; 139 | m_pLast = pInfo; 140 | m_NParams++; 141 | } 142 | 143 | void CFFGLPluginManager::SetTimeSupported(bool supported) 144 | { 145 | m_timeSupported = supported; 146 | } 147 | 148 | char* CFFGLPluginManager::GetParamName(DWORD dwIndex) const 149 | { 150 | ParamInfo* pCurr = m_pFirst; 151 | bool bFound = false; 152 | while (pCurr != NULL) { 153 | if (pCurr->ID == dwIndex) { 154 | bFound = true; 155 | break; 156 | } 157 | pCurr = pCurr->pNext; 158 | } 159 | if (bFound) return pCurr->Name; 160 | return NULL; 161 | } 162 | 163 | DWORD CFFGLPluginManager::GetParamType(DWORD dwIndex) const 164 | { 165 | ParamInfo* pCurr = m_pFirst; 166 | bool bFound = false; 167 | while (pCurr != NULL) { 168 | if (pCurr->ID == dwIndex) { 169 | bFound = true; 170 | break; 171 | } 172 | pCurr = pCurr->pNext; 173 | } 174 | if (bFound) return pCurr->dwType; 175 | return FF_FAIL; 176 | } 177 | 178 | void* CFFGLPluginManager::GetParamDefault(DWORD dwIndex) const 179 | { 180 | ParamInfo* pCurr = m_pFirst; 181 | bool bFound = false; 182 | while (pCurr != NULL) { 183 | if (pCurr->ID == dwIndex) { 184 | bFound = true; 185 | break; 186 | } 187 | pCurr = pCurr->pNext; 188 | } 189 | if (bFound) { 190 | if (GetParamType(dwIndex) == FF_TYPE_TEXT) 191 | return (void*)pCurr->StrDefaultValue; 192 | else 193 | return (void*) &pCurr->DefaultValue; 194 | } 195 | return NULL; 196 | } 197 | 198 | bool CFFGLPluginManager::GetTimeSupported() const 199 | { 200 | return m_timeSupported; 201 | } 202 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Developer: Trey Harrison 15 | // www.harrisondigitalmedia.com 16 | // 17 | // Last modified: October 26 2006 18 | // 19 | 20 | #ifndef FFGLPLUGINMANAGER_STANDARD 21 | #define FFGLPLUGINMANAGER_STANDARD 22 | 23 | 24 | #include "FFGL.h" 25 | 26 | 27 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 28 | /// \class CFFGLPluginManager 29 | /// \brief CFFGLPluginManager manages information concerning a plugin inputs, parameters, and capabilities. 30 | /// \author Gualtiero Volpe 31 | /// \version 1.0.0.3 32 | /// 33 | /// The CFFGLPluginManager class is the base class for FreeFrameGL plugins developed with the FreeFrameGL SDK since it provides 34 | /// them with methods for automatically manage information concerning plugin inputs, paramaters, and capabilities. 35 | /// Examples of information managed by this class are the number of inputs and parameters of a plugin; the name, type and 36 | /// default value of each parameter; the image formats a plugin supports; the supported optimizations. 37 | /// Plugins developed with the FreeFrameGL SDK (and thus having this class as base class) should call the protected methods 38 | /// of this class in order to specify the information related to their inputs, parameters and capabilities. These calls 39 | /// are usually done while constructing the plugin subclass. Plugins subclasses should also call methods of this class in 40 | /// order to get information about the images they are going to process (i.e., their width, height, depth, orientation). 41 | /// The defualt implementations of the FreeFrame gloabal functions call the public methods of this class in order to 42 | /// return to the host information about a plugin inputs, parameters, and capabilities. 43 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 44 | 45 | class CFFGLPluginManager 46 | { 47 | public: 48 | 49 | /// The standard destructor of CFFGLPluginManager. 50 | virtual ~CFFGLPluginManager(); 51 | 52 | /// This method returns the minimum number of inputs the host must provide. 53 | /// It is usually called by the default implementations of the FreeFrame global functions. 54 | /// 55 | /// \return The minimum number of inputs the host must provide. 56 | int GetMinInputs() const; 57 | 58 | /// This method returns the maximum number of inputs the plugin can receive. 59 | /// It is usually called by the default implementations of the FreeFrame global functions. 60 | /// 61 | /// \return The maximum number of inputs the plugin can receive. 62 | int GetMaxInputs() const; 63 | 64 | /// This method returns how may parameters the plugin has. 65 | /// It is usually called by the default implementations of the FreeFrame global functions. 66 | /// 67 | /// \return The number of parameters of the plugin. 68 | int GetNumParams() const; 69 | 70 | /// This method returns the name of the plugin parameter whose index is passed as parameter 71 | /// to the method. It is usually called by the default implementations of the FreeFrame global functions. 72 | /// 73 | /// \param dwIndex The index of the plugin parameter whose name is queried. 74 | /// It should be in the range [0, Number of plugin parameters). 75 | /// \return The name of the plugin parameter whose index is passed to the method. 76 | /// The return value is a pointer to an array of 16 1-byte ASCII characters, 77 | /// not null terminated (see FreeFrame specification). NULL is returned on error. 78 | char* GetParamName(DWORD dwIndex) const; 79 | 80 | /// This method is called to know the type of the plugin parameter whose index is passed as parameter 81 | /// to the method. It is usually called by the default implementations of the FreeFrame global functions. 82 | /// 83 | /// \param dwIndex The index of the plugin parameter whose name is queried. 84 | /// It should be in the range [0, Number of plugin parameters). 85 | /// \return The type of the plugin parameter whose index is passed as parameter to the method. 86 | /// Codes for allowed parameter types are defined in FreeFrame.h. 87 | /// In case of error, FF_FAIL is returned. 88 | DWORD GetParamType(DWORD dwIndex) const; 89 | 90 | /// This method is called to get the default value of the plugin parameter whose index is passed as parameter 91 | /// to the method. It is usually called by the default implementations of the FreeFrame global functions. 92 | /// 93 | /// \param dwIndex The index of the plugin parameter whose name is queried. 94 | /// It should be in the range [0, Number of plugin parameters). 95 | /// \return The default value of the plugin parameter whose index is passed as parameter to the method. 96 | /// The return value should be cast either to a char* in case of text parameters or to a float* 97 | /// in any other case. In case of error, NULL is returned. 98 | void* GetParamDefault(DWORD dwIndex) const; 99 | 100 | /// This method is called by a the host to determine whether the plugin supports the SetTime function 101 | bool GetTimeSupported() const; 102 | 103 | protected: 104 | 105 | /// The standard constructor of CFFGLPluginManager. 106 | /// \remark Notice that the CFFGLPluginManager constructor is a protected member function, i.e., nor CFFGLPluginManager 107 | /// objects nor CFreeFramePlugin objects should be created directly, but only objects of the subclasses 108 | /// implementing specific plugins should be instantiated. 109 | CFFGLPluginManager(); 110 | 111 | /// This method is called by a plugin subclass, derived from this class, to indicate the minimum number 112 | /// of inputs the host must provide. This method is usually called when a plugin object is instantiated 113 | /// (i.e., in the plugin subclass constructor). 114 | /// 115 | /// \param iMinInputs The plugin subclass should set it to the minimum number of inputs 116 | /// the host must provide. 117 | void SetMinInputs(int iMinInputs); 118 | 119 | /// This method is called by a plugin subclass, derived from this class, to indicate the maximum number 120 | /// of inputs the plugin can receive. This method is usually called when a plugin object is instantiated 121 | /// (i.e., in the plugin subclass constructor). 122 | /// 123 | /// \param iMaxInputs The plugin subclass should set it to the maximum number of inputs the plugin 124 | /// can receive. 125 | void SetMaxInputs(int iMaxInputs); 126 | 127 | /// This method is called by a plugin subclass, derived from this class, to specify name, type, and default 128 | /// value of the plugin parameter whose index is passed as parameter to the method. This method is usually 129 | /// called when a plugin object is instantiated (i.e., in the plugin subclass contructor). This version of 130 | /// the SetParamInfo function (DefaultValue of type float) should be called for all types of plugin parameters 131 | /// except for text, boolean, and event parameters. 132 | /// 133 | /// \param dwIndex Index of the plugin parameter whose data are specified. 134 | /// It should be in the range [0, Number of plugin parameters). 135 | /// \param pchName A string containing the name of the plugin parameter. 136 | /// According to the FreeFrame specification it should be at most 16 1-byte ASCII 137 | /// characters long. Longer strings will be truncated at the 16th character. 138 | /// \param dwType The type of the plugin parameter. Codes for allowed types are defined in FreeFrame.h. 139 | /// \param fDefaultValue The default value of the plugin parameter. According to the FreeFrame 140 | /// specification it must be a float in the range [0, 1]. 141 | void SetParamInfo(DWORD dwIndex, const char* pchName, DWORD dwType, float fDefaultValue); 142 | 143 | /// This method is called by a plugin subclass, derived from this class, to specify name, type, and default 144 | /// value of the plugin parameter whose index is passed as parameter to the method. This method is usually 145 | /// called when a plugin object is instantiated (i.e., in the plugin subclass contructor). This version of 146 | /// the SetParamInfo function (DefaultValue of type bool) should be called for plugin parameters of type 147 | /// boolean or event. 148 | /// 149 | /// \param dwIndex Index of the plugin parameter whose data are specified. 150 | /// It should be in the range [0, Number of plugin parameters). 151 | /// \param pchName A string containing the name of the plugin parameter. 152 | /// According to the FreeFrame specification it should be at most 16 1-byte ASCII 153 | /// characters long. Longer strings will be truncated at the 16th character. 154 | /// \param dwType The type of the plugin parameter. Codes for allowed types are defined in FreeFrame.h. 155 | /// \param bDefaultValue The boolean default value of the plugin parameter. 156 | void SetParamInfo(DWORD dwIndex, const char* pchName, DWORD dwType, bool bDefaultValue); 157 | 158 | /// This method is called by a plugin subclass, derived from this class, to specify name, type, and default 159 | /// value of the plugin parameter whose index is passed as parameter to the method. This method is usually 160 | /// called when a plugin object is instantiated (i.e., in the plugin subclass contructor). This version of 161 | /// the SetParamInfo function (DefaultValue of type char*) should be called for plugin parameters of type text. 162 | /// 163 | /// \param dwIndex Index of the plugin parameter whose data are specified. 164 | /// It should be in the range [0, Number of plugin parameters). 165 | /// \param pchName A string containing the name of the plugin parameter. 166 | /// According to the FreeFrame specification it should be at most 16 1-byte ASCII 167 | /// characters long. Longer strings will be truncated at the 16th character. 168 | /// \param dwType The type of the plugin parameter. Codes for allowed types are defined in FreeFrame.h. 169 | /// \param pchDefaultValue A string to be used as the default value of the plugin parameter. 170 | void SetParamInfo(DWORD dwIndex, const char* pchName, DWORD dwType, const char* pchDefaultValue); 171 | 172 | /// This method is called by a plugin subclass, derived from this class, to indicate whether the 173 | /// SetTime function is supported 174 | /// 175 | /// \param supported The plugin indicates whether it supports the SetTime function by passing true or false (1 or 0) 176 | void SetTimeSupported(bool supported); 177 | 178 | private: 179 | 180 | // Structure for keeping information about each plugin parameter 181 | typedef struct ParamInfoStruct { 182 | DWORD ID; 183 | char Name[16]; 184 | DWORD dwType; 185 | float DefaultValue; 186 | char* StrDefaultValue; 187 | ParamInfoStruct* pNext; 188 | } ParamInfo; 189 | 190 | // Information on paramters and pointers to ParamInfo list 191 | int m_NParams; 192 | ParamInfo* m_pFirst; 193 | ParamInfo* m_pLast; 194 | 195 | // Inputs 196 | int m_iMinInputs; 197 | int m_iMaxInputs; 198 | 199 | // Time capability 200 | bool m_timeSupported; 201 | }; 202 | 203 | 204 | #include "FFGLPluginManager_inl.h" 205 | 206 | #endif 207 | 208 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginManager_inl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Developer: Trey Harrison 15 | // www.harrisondigitalmedia.com 16 | // 17 | // Last modified: Oct. 26 2006 18 | // 19 | 20 | 21 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 22 | // CFFGLPluginManager inline methods 23 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 24 | 25 | inline int CFFGLPluginManager::GetMinInputs() const 26 | { 27 | return m_iMinInputs; 28 | } 29 | 30 | inline int CFFGLPluginManager::GetMaxInputs() const 31 | { 32 | return m_iMaxInputs; 33 | } 34 | 35 | inline int CFFGLPluginManager::GetNumParams() const 36 | { 37 | return m_NParams; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginSDK.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Developer: Trey Harrison 15 | // mailto:trey@treyharrison.com 16 | // 17 | // Last modified: Oct. 26 2006 18 | // 19 | 20 | #include "FFGLPluginSDK.h" 21 | #include 22 | #include 23 | 24 | // Buffer used by the default implementation of getParameterDisplay 25 | static char s_DisplayValue[5]; 26 | 27 | 28 | //////////////////////////////////////////////////////// 29 | // CFreeFrameGLPlugin constructor and destructor 30 | //////////////////////////////////////////////////////// 31 | 32 | CFreeFrameGLPlugin::CFreeFrameGLPlugin() 33 | : CFFGLPluginManager() 34 | { 35 | } 36 | 37 | CFreeFrameGLPlugin::~CFreeFrameGLPlugin() 38 | { 39 | } 40 | 41 | 42 | //////////////////////////////////////////////////////// 43 | // Default implementation of CFreeFrameGLPlugin methods 44 | //////////////////////////////////////////////////////// 45 | 46 | char* CFreeFrameGLPlugin::GetParameterDisplay(DWORD dwIndex) 47 | { 48 | DWORD dwType = m_pPlugin->GetParamType(dwIndex); 49 | DWORD dwValue = m_pPlugin->GetParameter(dwIndex); 50 | 51 | if ((dwValue != FF_FAIL) && (dwType != FF_FAIL)) 52 | { 53 | if (dwType == FF_TYPE_TEXT) 54 | { 55 | return (char *)dwValue; 56 | } 57 | else 58 | { 59 | float fValue; 60 | memcpy(&fValue, &dwValue, 4); 61 | memset(s_DisplayValue, 0, 5); 62 | sprintf(s_DisplayValue, "%f", fValue); 63 | return s_DisplayValue; 64 | } 65 | } 66 | return NULL; 67 | } 68 | 69 | DWORD CFreeFrameGLPlugin::SetParameter(const SetParameterStruct* pParam) 70 | { 71 | return FF_FAIL; 72 | } 73 | 74 | DWORD CFreeFrameGLPlugin::GetParameter(DWORD dwIndex) 75 | { 76 | return FF_FAIL; 77 | } 78 | 79 | DWORD CFreeFrameGLPlugin::GetInputStatus(DWORD dwIndex) 80 | { 81 | if (dwIndex >= (DWORD)GetMaxInputs()) return FF_FAIL; 82 | return FF_INPUT_INUSE; 83 | } 84 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLPluginSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2004 - InfoMus Lab - DIST - University of Genova 3 | // 4 | // InfoMus Lab (Laboratorio di Informatica Musicale) 5 | // DIST - University of Genova 6 | // 7 | // http://www.infomus.dist.unige.it 8 | // news://infomus.dist.unige.it 9 | // mailto:staff@infomus.dist.unige.it 10 | // 11 | // Developer: Gualtiero Volpe 12 | // mailto:volpe@infomus.dist.unige.it 13 | // 14 | // Developer: Trey Harrison 15 | // www.harrisondigitalmedia.com 16 | // 17 | // Last modified: October 26 2006 18 | // 19 | 20 | #ifndef FFGLPLUGINSDK_STANDARD 21 | #define FFGLPLUGINSDK_STANDARD 22 | 23 | #include "FFGLPluginManager.h" 24 | #include "FFGLPluginInfo.h" 25 | 26 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 27 | /// \class CFreeFrameGLPlugin 28 | /// \brief CFreeFrameGLPlugin is the base class for all FreeFrameGL plugins developed with the FreeFrameGL SDK. 29 | /// \author Gualtiero Volpe 30 | /// \version 1.0.0.2 31 | /// 32 | /// The CFreeFrameGLPlugin class is the base class for every FreeFrameGL plugins developed with the FreeFrameGL SDK. 33 | /// It is derived from CFFGLPluginManager, so that most of the plugin management and communication with the host 34 | /// can be transparently handled through the default implementations of the methods of CFFGLPluginManager. 35 | /// While CFFGLPluginManager is used by the global FreeFrame methods, CFreeFrameGLPlugin provides a default implementation 36 | /// of the instance specific FreeFrame functions. Note that CFreeFrameGLPlugin methods are virtual methods: any given 37 | /// FreeFrameGL plugin developed with the FreeFrameGL SDK will be a derived class of CFreeFrameGLPlugin and will have to 38 | /// provide a custom implementation of most of such methods. Except for CFreeFrameGLPlugin::GetParameterDisplay and 39 | /// CFreeFrameGLPlugin::GetInputStatus, all the default methods of CFreeFrameGLPlugin just return FF_FAIL: every derived 40 | /// plugin is responsible of providing its specific implementation of such default methods. 41 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 42 | 43 | class CFreeFrameGLPlugin : 44 | public CFFGLPluginManager 45 | { 46 | public: 47 | 48 | /// The standard destructor of CFreeFrameGLPlugin. 49 | virtual ~CFreeFrameGLPlugin(); 50 | 51 | /// Default implementation of the FFGL InitGL instance specific function. This function allocates 52 | /// the OpenGL resources the plugin needs during its lifetime 53 | /// 54 | /// \param vp Pointer to a FFGLViewportStruct structure (see the definition in FFGL.h and 55 | /// the description in the FFGL specification). 56 | /// \return The default implementation always returns FF_SUCCESS. 57 | /// A custom implementation must be provided by every specific plugin that allocates 58 | /// any OpenGL resources 59 | virtual DWORD InitGL(const FFGLViewportStruct *vp) { return FF_SUCCESS; } 60 | 61 | /// Default implementation of the FFGL DeInitGL instance specific function. This function frees 62 | /// any OpenGL resources the plugin has allocated 63 | /// 64 | /// \return The default implementation always returns FF_SUCCESS. 65 | /// A custom implementation must be provided by every specific plugin that allocates 66 | /// any OpenGL resources 67 | virtual DWORD DeInitGL() { return FF_SUCCESS; } 68 | 69 | /// Default implementation of the FreeFrame getParameterDisplay instance specific function. It provides a string 70 | /// to display as the value of the plugin parameter whose index is passed as parameter to the method. This default 71 | /// implementation just returns the string representation of the float value of the plugin parameter. A custom 72 | /// implementation may be provided by every specific plugin. 73 | /// 74 | /// \param dwIndex The index of the parameter whose display value is queried. 75 | /// It should be in the range [0, Number of plugin parameters). 76 | /// \return The display value of the plugin parameter or NULL in case of error 77 | virtual char* GetParameterDisplay(DWORD dwIndex); 78 | 79 | /// Default implementation of the FreeFrame setParameter instance specific function. It allows setting the current 80 | /// value of the plugin parameter whose index is passed as parameter to the method. This default implementation 81 | /// always returns FF_FAIL. A custom implementation must be provided by every specific plugin. 82 | /// 83 | /// \param pParam A pointer to a SetParameterStruct (see FreeFrame.h and FreeFrame specification for 84 | /// further information) containing the index and the new value of the plugin parameter 85 | /// whose value is going to be set. The parameter index should be in the range 86 | /// [0, Number of plugin parameters). 87 | /// \return The default implementation always returns FF_FAIL. 88 | /// A custom implementation must be provided. 89 | virtual DWORD SetParameter(const SetParameterStruct* pParam); 90 | 91 | /// Default implementation of the FreeFrame getParameter instance specific function. It allows getting the current 92 | /// value of the plugin parameter whose index is passed as parameter to the method. This default implementation 93 | /// always returns FF_FAIL. A custom implementation must be provided by every specific plugin. 94 | /// 95 | /// \param dwIndex The index of the parameter whose current value is queried. 96 | /// It should be in the range [0, Number of plugin parameters). 97 | /// \return The default implementation always returns FF_FAIL. 98 | /// A custom implementation must be provided by every specific plugin 99 | virtual DWORD GetParameter(DWORD dwIndex); 100 | 101 | /// Default implementation of the FFGL ProcessOpenGL instance specific function. This function processes 102 | /// the input texture(s) by 103 | /// 104 | /// \param pOpenGLData to a ProcessOpenGLStruct structure (see the definition in FFGL.h and 105 | /// the description in the FFGL specification). 106 | /// \return The default implementation always returns FF_FAIL. 107 | /// A custom implementation must be provided by every specific plugin. 108 | virtual DWORD ProcessOpenGL(ProcessOpenGLStruct* pOpenGLData) { return FF_FAIL; } 109 | 110 | /// Default implementation of the FFGL SetTime instance specific function 111 | /// 112 | /// \param pOpenGLData to a ProcessOpenGLStruct structure (see the definition in FFGL.h and 113 | /// the description in the FFGL specification). 114 | /// \return The default implementation always returns FF_FAIL. 115 | /// A custom implementation must be provided by every specific plugin. 116 | virtual DWORD SetTime(double time) { return FF_FAIL; } 117 | 118 | /// Default implementation of the FreeFrame getInputStatus instance specific function. This function is called 119 | /// to know whether a given input is currently in use. For the default implementation every input is always in use. 120 | /// A custom implementation may be provided by every specific plugin. 121 | /// 122 | /// \param dwIndex The index of the input whose status is queried. 123 | /// It should be in the range [Minimum number of inputs, Maximum number of inputs). 124 | /// \return The default implementation always returns FF_FF_INPUT_INUSE or FF_FAIL if the index 125 | /// is out of range. A custom implementation may be provided by every specific plugin. 126 | virtual DWORD GetInputStatus(DWORD dwIndex); 127 | 128 | /// The only public data field CFreeFrameGLPlugin contains is m_pPlugin, a pointer to the plugin instance. 129 | /// Subclasses may use this pointer for self-referencing (e.g., a plugin may pass this pointer to external modules, 130 | /// so that they can use it for calling the plugin methods). 131 | CFreeFrameGLPlugin *m_pPlugin; 132 | 133 | protected: 134 | 135 | /// The only protected function of CFreeFrameGLPlugin is its constructor. In fact, nor CFFGLPluginManager objects nor 136 | /// CFreeFrameGLPlugin objects should be created directly, but only objects of the subclasses implementing specific 137 | /// plugins should be instantiated. Moreover, subclasses should define and provide a factory method to be used by 138 | /// the FreeFrame SDK for instantiating plugin objects. 139 | CFreeFrameGLPlugin(); 140 | }; 141 | 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLShader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "FFGLShader.h" 3 | 4 | FFGLShader::FFGLShader() 5 | { 6 | m_linkStatus = 0; 7 | m_glProgram = 0; 8 | m_glVertexShader = 0; 9 | m_glFragmentShader = 0; 10 | m_extensions = NULL; 11 | } 12 | 13 | void FFGLShader::CreateGLResources() 14 | { 15 | if (m_extensions==NULL) 16 | return; 17 | 18 | if (m_glProgram==0) 19 | m_glProgram = (GLenum)m_extensions->glCreateProgramObjectARB(); 20 | 21 | if (m_glVertexShader==0) 22 | m_glVertexShader = (GLenum)m_extensions->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); 23 | 24 | if (m_glFragmentShader==0) 25 | m_glFragmentShader = (GLenum)m_extensions->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); 26 | } 27 | 28 | void FFGLShader::FreeGLResources() 29 | { 30 | if (m_extensions==NULL) 31 | return; 32 | 33 | if (m_glFragmentShader) 34 | { 35 | m_extensions->glDeleteObjectARB((void*)m_glFragmentShader); 36 | m_glFragmentShader = 0; 37 | } 38 | 39 | if (m_glVertexShader) 40 | { 41 | m_extensions->glDeleteObjectARB((void*)m_glVertexShader); 42 | m_glVertexShader = 0; 43 | } 44 | 45 | if (m_glProgram) 46 | { 47 | m_extensions->glDeleteObjectARB((void*)m_glProgram); 48 | m_glProgram = 0; 49 | } 50 | } 51 | 52 | int FFGLShader::BindShader() 53 | { 54 | if (m_extensions==NULL) 55 | return 0; 56 | 57 | //make sure the program type is supported 58 | if (m_extensions->ARB_shader_objects==0) 59 | return 0; 60 | 61 | if (m_glProgram==0) 62 | return 0; 63 | 64 | m_extensions->glUseProgramObjectARB((void*)m_glProgram); 65 | 66 | return 1; 67 | } 68 | 69 | int FFGLShader::UnbindShader() 70 | { 71 | if (m_extensions->ARB_shader_objects==0) 72 | return 0; 73 | 74 | m_extensions->glUseProgramObjectARB(0); 75 | 76 | return 1; 77 | } 78 | 79 | FFGLShader::~FFGLShader() 80 | { 81 | } 82 | 83 | void FFGLShader::SetExtensions(FFGLExtensions *e) 84 | { 85 | m_extensions = e; 86 | } 87 | 88 | int FFGLShader::Compile(const char *vtxProgram, const char *fragProgram) 89 | { 90 | if (m_extensions==NULL) 91 | return 0; 92 | 93 | if (m_glProgram==0) 94 | CreateGLResources(); 95 | 96 | int doLink = 0; 97 | 98 | //if we can compile a fragment shader, do it. 99 | if (m_glFragmentShader!=0 && 100 | m_glProgram!=0 && 101 | fragProgram!=NULL && fragProgram[0]!=0) 102 | { 103 | const char *strings[] = 104 | { 105 | fragProgram, 106 | NULL 107 | }; 108 | 109 | // Load Shader Sources 110 | m_extensions->glShaderSourceARB((void*)m_glFragmentShader, 1, strings, NULL); 111 | 112 | // Compile The Shaders 113 | m_extensions->glCompileShaderARB((void*)m_glFragmentShader); 114 | 115 | GLint compileSuccess; 116 | 117 | m_extensions->glGetObjectParameterivARB( 118 | (void*)m_glFragmentShader, 119 | GL_OBJECT_COMPILE_STATUS_ARB, 120 | &compileSuccess); 121 | 122 | if (compileSuccess == GL_TRUE) 123 | { 124 | //attach it to the program 125 | m_extensions->glAttachObjectARB((void*)m_glProgram, (void*)m_glFragmentShader); 126 | doLink = 1; 127 | } 128 | else 129 | { 130 | //get the log so we can peek at the error string 131 | char log[1024]; 132 | GLsizei returnedLength; 133 | 134 | m_extensions->glGetInfoLogARB( 135 | (void*)m_glFragmentShader, 136 | sizeof(log)-1, 137 | &returnedLength, 138 | log); 139 | 140 | log[returnedLength] = 0; 141 | int a; 142 | a=0; 143 | std::cerr << log << std::endl; 144 | } 145 | } 146 | 147 | //if we can compile a vertex shader, do it 148 | if (m_glVertexShader!=0 && 149 | m_glProgram!=0 && 150 | vtxProgram!=0 && vtxProgram[0]!=0) 151 | { 152 | const char *strings[] = 153 | { 154 | vtxProgram, 155 | NULL 156 | }; 157 | 158 | // Load Shader Sources 159 | m_extensions->glShaderSourceARB((void*)m_glVertexShader, 1, strings, NULL); 160 | 161 | // Compile The Shaders 162 | m_extensions->glCompileShaderARB((void*)m_glVertexShader); 163 | 164 | GLint compileSuccess; 165 | 166 | m_extensions->glGetObjectParameterivARB( 167 | (void*)m_glVertexShader, 168 | GL_OBJECT_COMPILE_STATUS_ARB, 169 | &compileSuccess); 170 | 171 | if (compileSuccess == GL_TRUE) 172 | { 173 | //attach it to the program 174 | m_extensions->glAttachObjectARB((void*)m_glProgram, (void*)m_glVertexShader); 175 | doLink = 1; 176 | } 177 | else 178 | { 179 | //get the log so we can peek at the error string 180 | char log[1024]; 181 | GLsizei returnedLength; 182 | 183 | m_extensions->glGetInfoLogARB( 184 | (void*)m_glVertexShader, 185 | sizeof(log)-1, 186 | &returnedLength, 187 | log); 188 | 189 | log[returnedLength] = 0; 190 | int a; 191 | a=0; 192 | std::cerr << log << std::endl; 193 | } 194 | } 195 | 196 | //check if linking worked 197 | GLint linkSuccess = 0; 198 | 199 | if (doLink) 200 | { 201 | // Link The Program Object 202 | m_extensions->glLinkProgramARB((void*)m_glProgram); 203 | 204 | m_extensions->glGetObjectParameterivARB( 205 | (void*)m_glProgram, 206 | GL_OBJECT_LINK_STATUS_ARB, 207 | &linkSuccess); 208 | } 209 | 210 | m_linkStatus = linkSuccess; 211 | 212 | return linkSuccess; 213 | } 214 | 215 | GLuint FFGLShader::FindUniform(const char *name) 216 | { 217 | return m_extensions->glGetUniformLocationARB((void*)m_glProgram,name); 218 | } 219 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FFGLShader.h: -------------------------------------------------------------------------------- 1 | #ifndef FFGLShader_H 2 | #define FFGLShader_H 3 | 4 | #include 5 | #include 6 | 7 | class FFGLShader 8 | { 9 | public: 10 | FFGLShader(); 11 | virtual ~FFGLShader(); 12 | 13 | void SetExtensions(FFGLExtensions *e); 14 | 15 | int IsReady() { return (m_glProgram!=0 && m_glVertexShader!=0 && m_glFragmentShader!=0 && m_linkStatus==1); } 16 | 17 | int Compile(const char *vtxProgram, const char *fragProgram); 18 | 19 | GLuint FindUniform(const char *name); 20 | 21 | int BindShader(); 22 | int UnbindShader(); 23 | 24 | void FreeGLResources(); 25 | 26 | private: 27 | FFGLExtensions *m_extensions; 28 | GLenum m_glProgram; 29 | GLenum m_glVertexShader; 30 | GLenum m_glFragmentShader; 31 | GLuint m_linkStatus; 32 | 33 | void CreateGLResources(); 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/FreeFrame.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // FreeFrame.h 3 | // 4 | // FreeFrame is an open-source cross-platform real-time video effects plugin system. 5 | // It provides a framework for developing video effects plugins and hosts on Windows, 6 | // Linux and Mac OSX. 7 | // 8 | // Copyright (c) 2002, 2003, 2004, 2005, 2006 www.freeframe.org 9 | // All rights reserved. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Redistribution and use in source and binary forms, with or without modification, 16 | // are permitted provided that the following conditions are met: 17 | // 18 | // * Redistributions of source code must retain the above copyright 19 | // notice, this list of conditions and the following disclaimer. 20 | // * Redistributions in binary form must reproduce the above copyright 21 | // notice, this list of conditions and the following disclaimer in 22 | // the documentation and/or other materials provided with the 23 | // distribution. 24 | // * Neither the name of FreeFrame nor the names of its 25 | // contributors may be used to endorse or promote products derived 26 | // from this software without specific prior written permission. 27 | // 28 | // 29 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 30 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 31 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32 | // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 34 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 36 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 37 | // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 38 | // OF THE POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 41 | 42 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 43 | // 44 | // First version, Marcus Clements (marcus@freeframe.org) 45 | // www.freeframe.org 46 | // 47 | // FreeFrame 1.0 upgrade by Pete Warden 48 | // www.petewarden.com 49 | // 50 | // FreeFrame 1.0 - 03 upgrade by Gualtiero Volpe 51 | // Gualtiero.Volpe@poste.it 52 | // 53 | // #ifdef tweaks for FreeFrameGL upgrade by Trey Harrison 54 | // www.harrisondigitalmedia.com 55 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 56 | 57 | 58 | #ifndef __FREEFRAME_H__ 59 | #define __FREEFRAME_H__ 60 | 61 | #if _MSC_VER > 1000 62 | #pragma once 63 | #endif 64 | 65 | 66 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 67 | // Includes 68 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 69 | 70 | #ifdef _WIN32 71 | 72 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 73 | #include 74 | 75 | #else 76 | 77 | extern "C" { 78 | 79 | #include 80 | #include 81 | 82 | #endif 83 | 84 | 85 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 86 | // FreeFrame defines 87 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 88 | 89 | // Function codes 90 | #define FF_GETINFO 0 91 | #define FF_INITIALISE 1 92 | #define FF_DEINITIALISE 2 93 | #define FF_PROCESSFRAME 3 94 | #define FF_GETNUMPARAMETERS 4 95 | #define FF_GETPARAMETERNAME 5 96 | #define FF_GETPARAMETERDEFAULT 6 97 | #define FF_GETPARAMETERDISPLAY 7 98 | #define FF_SETPARAMETER 8 99 | #define FF_GETPARAMETER 9 100 | #define FF_GETPLUGINCAPS 10 101 | #define FF_INSTANTIATE 11 102 | #define FF_DEINSTANTIATE 12 103 | #define FF_GETEXTENDEDINFO 13 104 | #define FF_PROCESSFRAMECOPY 14 105 | #define FF_GETPARAMETERTYPE 15 106 | #define FF_GETIPUTSTATUS 16 107 | 108 | // Return values 109 | #define FF_SUCCESS 0 110 | #define FF_FAIL 0xFFFFFFFF 111 | #define FF_TRUE 1 112 | #define FF_FALSE 0 113 | #define FF_SUPPORTED 1 114 | #define FF_UNSUPPORTED 0 115 | 116 | // Plugin types 117 | #define FF_EFFECT 0 118 | #define FF_SOURCE 1 119 | 120 | // Plugin capabilities 121 | #define FF_CAP_16BITVIDEO 0 122 | #define FF_CAP_24BITVIDEO 1 123 | #define FF_CAP_32BITVIDEO 2 124 | #define FF_CAP_PROCESSFRAMECOPY 3 125 | #define FF_CAP_MINIMUMINPUTFRAMES 10 126 | #define FF_CAP_MAXIMUMINPUTFRAMES 11 127 | #define FF_CAP_COPYORINPLACE 15 128 | 129 | // Plugin optimization 130 | #define FF_CAP_PREFER_NONE 0 131 | #define FF_CAP_PREFER_INPLACE 1 132 | #define FF_CAP_PREFER_COPY 2 133 | #define FF_CAP_PREFER_BOTH 3 134 | 135 | // Parameter types 136 | #define FF_TYPE_BOOLEAN 0 137 | #define FF_TYPE_EVENT 1 138 | #define FF_TYPE_RED 2 139 | #define FF_TYPE_GREEN 3 140 | #define FF_TYPE_BLUE 4 141 | #define FF_TYPE_XPOS 5 142 | #define FF_TYPE_YPOS 6 143 | #define FF_TYPE_STANDARD 10 144 | #define FF_TYPE_TEXT 100 145 | 146 | // Input status 147 | #define FF_INPUT_NOTINUSE 0 148 | #define FF_INPUT_INUSE 1 149 | 150 | // Image depth 151 | #define FF_DEPTH_16 0 152 | #define FF_DEPTH_24 1 153 | #define FF_DEPTH_32 2 154 | 155 | // Image orientation 156 | #define FF_ORIENTATION_TL 1 157 | #define FF_ORIENTATION_BL 2 158 | 159 | 160 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 161 | // FreeFrame Types 162 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 163 | 164 | // Typedefs for Linux and MacOS - in Windows these are defined in files included by windows.h 165 | #ifndef _WIN32 166 | typedef unsigned int DWORD; 167 | typedef unsigned char BYTE; 168 | typedef void *LPVOID; 169 | #endif 170 | 171 | // PluginInfoStruct 172 | typedef struct PluginInfoStructTag { 173 | DWORD APIMajorVersion; 174 | DWORD APIMinorVersion; 175 | BYTE PluginUniqueID[4]; // 4 chars uniqueID - not null terminated 176 | BYTE PluginName[16]; // 16 chars plugin friendly name - not null terminated 177 | DWORD PluginType; // Effect or source 178 | } PluginInfoStruct; 179 | 180 | // PluginExtendedInfoStruct 181 | typedef struct PluginExtendedInfoStructTag { 182 | DWORD PluginMajorVersion; 183 | DWORD PluginMinorVersion; 184 | char* Description; 185 | char* About; 186 | DWORD FreeFrameExtendedDataSize; 187 | void* FreeFrameExtendedDataBlock; 188 | } PluginExtendedInfoStruct; 189 | 190 | // VideoInfoStruct 191 | typedef struct VideoInfoStructTag { 192 | DWORD FrameWidth; // width of frame in pixels 193 | DWORD FrameHeight; // height of frame in pixels 194 | DWORD BitDepth; // enumerated indicator of bit depth of video: 0 = 16 bit 5-6-5 1 = 24bit packed 2 = 32bit 195 | DWORD Orientation; 196 | } VideoInfoStruct; 197 | 198 | // ProcessFrameCopyStruct 199 | typedef struct ProcessFrameCopyStructTag { 200 | DWORD numInputFrames; 201 | void** ppInputFrames; 202 | void* pOutputFrame; 203 | } ProcessFrameCopyStruct; 204 | 205 | // SetParameterStruct 206 | typedef struct SetParameterStructTag { 207 | DWORD ParameterNumber; 208 | DWORD NewParameterValue; 209 | } SetParameterStruct; 210 | 211 | // plugMain function return values 212 | typedef union plugMainUnionTag { 213 | DWORD ivalue; 214 | float fvalue; 215 | VideoInfoStruct* VISvalue; 216 | PluginInfoStruct* PISvalue; 217 | char* svalue; 218 | } plugMainUnion; 219 | 220 | 221 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 222 | // Function prototypes 223 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 224 | 225 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 226 | // plugMain - The one and only exposed function 227 | // parameters: 228 | // functionCode - tells the plugin which function is being called 229 | // pParam - 32-bit parameter or 32-bit pointer to parameter structure 230 | // 231 | // PLUGIN DEVELOPERS: you shouldn't need to change this function 232 | // 233 | // All parameters are cast as 32-bit untyped pointers and cast to appropriate 234 | // types here 235 | // 236 | // All return values are cast to 32-bit untyped pointers here before return to 237 | // the host 238 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 239 | 240 | #ifdef _WIN32 241 | 242 | BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); 243 | 244 | __declspec(dllexport) plugMainUnion __stdcall plugMain(DWORD functionCode, DWORD inputValue, DWORD instanceID); 245 | typedef __declspec(dllimport) plugMainUnion (__stdcall *FF_Main_FuncPtr)(DWORD, DWORD, DWORD); 246 | 247 | #else 248 | 249 | //linux and Mac OSX share these 250 | plugMainUnion plugMain(DWORD functionCode, DWORD inputValue, DWORD instanceID); 251 | typedef plugMainUnion (*FF_Main_FuncPtr)(DWORD funcCode, DWORD inputVal, DWORD instanceID); 252 | 253 | #endif 254 | 255 | #ifndef _WIN32 256 | } 257 | #endif 258 | 259 | #endif 260 | -------------------------------------------------------------------------------- /ffgl-host/lib/ffgl/Timer.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMER_H 2 | #define TIMER_H 3 | 4 | class Timer 5 | { 6 | public: 7 | static Timer *New(); 8 | 9 | virtual void Reset() = 0; 10 | virtual double GetElapsedTime() = 0; 11 | 12 | virtual ~Timer() {} 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ffgl-host/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "FFDebugMessage.h" 6 | #include "FFGLPluginInstance.h" 7 | #include "Timer.h" 8 | 9 | //this defines the size of the window when it is first opened 10 | int WINDOWWIDTH = 640; 11 | int WINDOWHEIGHT = 480; 12 | int WindowClosed = 0; //set to 1 when the window closes, detected by the glutVisibilityFunc 13 | 14 | FFGLViewportStruct fboViewport; //the viewport used when rendering into the FBO 15 | FFGLViewportStruct windowViewport; //the viewport used when rendering into the output window 16 | //they are the same, but seperated to emphasize the FFGL spec that requires maintaining 17 | //the same viewport during the lifetime of a plugin. plugin1 always renders into the fboViewport, 18 | //plugin2 always renders into the windowViewport 19 | 20 | //these classes assist with handling the loading/unloading, and calling of plugins 21 | FFGLPluginInstance *plugin1 = NULL; 22 | FFGLPluginInstance *plugin2 = NULL; 23 | 24 | //this represents the texture (in main system/CPU memory) that we feed to the plugins 25 | //it is generated procedurally, a clever algorithm from Gabor Papp's minimal 26 | //FreeFrame host for linux 27 | unsigned char *inputImage = NULL; 28 | 29 | //this represents the texture (on the GPU) that we feed to the plugins 30 | FFGLTextureStruct inputTexture; 31 | 32 | //this is a function to allocate the above inputTexture and inputImage 33 | void AllocateInputTexture(int textureWidth, int textureHeight); 34 | 35 | //this generates the inputImage (in CPU) memory at the 36 | //specified "time" (it is a procedurally generated image), then 37 | //uploads the image to the GPU texture, inputTexture 38 | void UpdateInputTexture(double time); 39 | 40 | //OSX supports many more opengl extension directly, by including 41 | // - to be more portable to other platforms 42 | //(like Windows, *ahem*), this class (FFGLExtensions) is used 43 | //to provide a defined subset of the GL extensions to all the implementations 44 | //of FFGL plugins / hosts in the FFGL SDK. 45 | FFGLExtensions glExtensions; 46 | 47 | //this represents a blank canvas on the GPU that we use to store temporary 48 | //results of FFGL processing. the output from plugin #1 (brightness) is rendered 49 | //to this FBO, then the FBO is bound as a texture and fed to plugin #2 (mirror, by default) 50 | FFGLFBO fbo; 51 | 52 | //this is a timer used to increment the procedurally generated input image 53 | //smoothly over time (also used to ramp the brightness up and down) 54 | Timer *timer = NULL; 55 | 56 | //these are methods provided to GLUT that redraw the window 57 | //and handle when the window is resized 58 | void FFGLHostDisplay(); 59 | void FFGLHostReshape(int width, int height); 60 | 61 | //GLUT calls this function so that we can respond to mouse movement 62 | void FFGLHostMouseMove(int x, int y); 63 | 64 | //GLUT calls this function so that we can respond to changes of the window's visibility 65 | void FFGLHostVisibilityChange(int visible); 66 | 67 | //when the mouse moves, these values are updated according to the 68 | //x/y position of the mosue. (0,0) corresponds to the lower left 69 | //corner of the window, (1,1) corresponds to the upper right. the 70 | //mouse values are then assigned to the plugins each time they draw 71 | //x -> plugin 1 parameter 0 72 | //y -> plugin 2 parameter 0 73 | float mouseX = 0.5; 74 | float mouseY = 0.5; 75 | 76 | //this locates the host binary and plugin binaries so that 77 | //they can be found when the host is launched from the finder 78 | void SetCorrectWorkingPath(); 79 | 80 | 81 | int main(int argc, char **argv) 82 | { 83 | if (argc != 3) 84 | { 85 | FFDebugMessage("Please provide two plugin arguments"); 86 | exit(EXIT_FAILURE); 87 | } 88 | char *PluginFilename1 = argv[1]; 89 | char *PluginFilename2 = argv[2]; 90 | 91 | //this sets the 'working' path to the folder that 92 | //contains the plugins, for some reason this is necessary 93 | //in order for the host to run when launched from the finder 94 | //(but not necessary when launched from the terminal) 95 | SetCorrectWorkingPath(); 96 | 97 | //load first plugin (does not instantiate!) 98 | plugin1 = FFGLPluginInstance::New(); 99 | if (plugin1->Load(PluginFilename1)==FF_FAIL) 100 | { 101 | FFDebugMessage("Couldn't open plugin 1"); 102 | return 0; 103 | } 104 | 105 | //init second plugin (does not instantiate!) 106 | plugin2 = FFGLPluginInstance::New(); 107 | if (plugin2->Load(PluginFilename2)==FF_FAIL) 108 | { 109 | FFDebugMessage("Couldn't open plugin 2"); 110 | return 0; 111 | } 112 | 113 | //init OpenGL/GLUT 114 | glutInit(&argc, argv); 115 | glutInitWindowSize(WINDOWWIDTH, WINDOWHEIGHT); 116 | glutInitDisplayString("double rgb depth"); 117 | glutCreateWindow("FFGLHost"); 118 | glutReshapeFunc(FFGLHostReshape); 119 | glutPassiveMotionFunc(FFGLHostMouseMove); 120 | glutVisibilityFunc(FFGLHostVisibilityChange); 121 | 122 | //this allocates the CPU inputImage and GPU inputTexture 123 | //(they must be the same size) 124 | AllocateInputTexture(320,240); 125 | 126 | if (inputTexture.Handle==0 || inputImage==NULL) 127 | { 128 | FFDebugMessage("Texture allocation failed"); 129 | return 0; 130 | } 131 | 132 | //init gl extensions 133 | glExtensions.Initialize(); 134 | if (glExtensions.EXT_framebuffer_object==0) 135 | { 136 | FFDebugMessage("FBO not detected, cannot continue"); 137 | return 0; 138 | } 139 | 140 | //allocate fbo, same size as window 141 | if (!fbo.Create(WINDOWWIDTH, WINDOWHEIGHT, glExtensions)) 142 | { 143 | FFDebugMessage("Framebuffer Object Init Failed"); 144 | return 0; 145 | } 146 | 147 | //instantiate the first plugin passing a viewport that matches 148 | //the FBO (plugin1 is rendered into our FBO) 149 | fboViewport.x = 0; 150 | fboViewport.y = 0; 151 | fboViewport.width = WINDOWWIDTH; 152 | fboViewport.height = WINDOWHEIGHT; 153 | if (plugin1->InstantiateGL(&fboViewport)!=FF_SUCCESS) 154 | { 155 | FFDebugMessage("plugin1->InstantiateGL failed"); 156 | return 0; 157 | } 158 | 159 | //plugin2 renders into the window viewport, which is the 160 | //same as the FBO viewport, but the viewport structures are seperated 161 | //here to emphasize the FFGL spec requirement of maintaining a consistent 162 | //output viewport for the lifetime of a plugin 163 | windowViewport = fboViewport; 164 | if (plugin2->InstantiateGL(&windowViewport)!=FF_SUCCESS) 165 | { 166 | FFDebugMessage("plugin2->InstantiateGL failed"); 167 | return 0; 168 | } 169 | 170 | //tell GLUT about our display functions 171 | glutDisplayFunc(FFGLHostDisplay); 172 | 173 | //start the timer and the glut main loop 174 | timer = Timer::New(); 175 | 176 | //loop as long as the window is open 177 | while (WindowClosed==0) 178 | { 179 | glutCheckLoop(); 180 | } 181 | 182 | plugin1->Unload(); 183 | delete plugin1; 184 | 185 | plugin2->Unload(); 186 | delete plugin2; 187 | 188 | delete [] inputImage; 189 | 190 | delete timer; 191 | 192 | //...GL texture is left allocated? 193 | return 0; 194 | } 195 | 196 | //glut is not clear in its specification about whether or not 197 | //an opengl context is active during this call. GLUT doesn't seem to 198 | //be designed to gracefully exit the application freeing opengl resources 199 | //appropriately. since the FFGL spec requires an active opengl context 200 | //during the call to DeInstantiateGL (so that plugins can release their OpenGL 201 | //resources) this is the best place I can think to put it. 202 | void FFGLHostVisibilityChange(int visible) 203 | { 204 | if (visible==0) 205 | { 206 | //free all of the gl resources we've allocated and mark our WindowClosed variable 207 | WindowClosed = 1; 208 | fbo.FreeResources(glExtensions); 209 | plugin1->DeInstantiateGL(); 210 | plugin2->DeInstantiateGL(); 211 | glDeleteTextures(1,&inputTexture.Handle); 212 | } 213 | } 214 | 215 | void FFGLHostDisplay() 216 | { 217 | if (WindowClosed) 218 | return; 219 | 220 | //whats the current time on the timer? 221 | double curFrameTime = timer->GetElapsedTime(); 222 | 223 | UpdateInputTexture(curFrameTime); 224 | 225 | //activate the fbo as our render target 226 | if (!fbo.BindAsRenderTarget(glExtensions)) 227 | { 228 | FFDebugMessage("FBO Bind As Render Target Failed"); 229 | return; 230 | } 231 | 232 | //set the gl viewport to equal the size of the FBO 233 | glViewport( 234 | fboViewport.x, 235 | fboViewport.y, 236 | fboViewport.width, 237 | fboViewport.height); 238 | 239 | //prepare gl state for rendering the first plugin (brightness) 240 | 241 | //make sure all the matrices are reset 242 | glMatrixMode(GL_TEXTURE); 243 | glLoadIdentity(); 244 | glMatrixMode(GL_PROJECTION); 245 | glLoadIdentity(); 246 | glMatrixMode(GL_MODELVIEW); 247 | glLoadIdentity(); 248 | 249 | //clear the depth and color buffers 250 | glClearColor(0,0,0,0); 251 | glClearDepth(1.0); 252 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 253 | 254 | //tell plugin 1 about the current time 255 | plugin1->SetTime(curFrameTime); 256 | 257 | //set plugin 1 parameter 0 258 | plugin1->SetFloatParameter(0, mouseX); 259 | 260 | //prepare the structure used to call 261 | //the plugin's ProcessOpenGL method 262 | ProcessOpenGLStructTag processStruct; 263 | 264 | //create the array of OpenGLTextureStruct * to be passed 265 | //to the plugin 266 | FFGLTextureStruct *inputTextures[1]; 267 | inputTextures[0] = &inputTexture; 268 | 269 | //provide the 1 input texture we allocated above 270 | processStruct.numInputTextures = 1; 271 | processStruct.inputTextures = inputTextures; 272 | 273 | //specify our FBO's handle in the processOpenGLStruct 274 | processStruct.HostFBO = fbo.GetFBOHandle(); 275 | 276 | //call the plugin's ProcessOpenGL 277 | if (plugin1->CallProcessOpenGL(processStruct)==FF_SUCCESS) 278 | { 279 | //if the plugin call succeeds, the drawning is complete 280 | } 281 | else 282 | { 283 | //the plugin call failed, exit 284 | FFDebugMessage("Plugin 1's ProcessOpenGL failed"); 285 | return; 286 | } 287 | 288 | //deactivate rendering to the fbo 289 | //(this re-activates rendering to the window) 290 | fbo.UnbindAsRenderTarget(glExtensions); 291 | 292 | //set the gl viewport to equal the size of our output window 293 | glViewport( 294 | windowViewport.x, 295 | windowViewport.y, 296 | windowViewport.width, 297 | windowViewport.height); 298 | 299 | //prepare to render the 2nd plugin (the mirror effect or the custom plugin) 300 | 301 | //reset all matrices 302 | glMatrixMode(GL_TEXTURE); 303 | glLoadIdentity(); 304 | glMatrixMode(GL_PROJECTION); 305 | glLoadIdentity(); 306 | glMatrixMode(GL_MODELVIEW); 307 | glLoadIdentity(); 308 | 309 | //clear the color and depth buffers 310 | glClearColor(0,0,0,0); 311 | glClearDepth(1.0); 312 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 313 | 314 | //now pass the contents of the FBO as a texture to the mirror plugin 315 | FFGLTextureStruct fboTexture = fbo.GetTextureInfo(); 316 | 317 | //change processStruct to refer to the FBO texture 318 | inputTextures[0] = &fboTexture; 319 | 320 | //specify no FBO handle since we are rendering to the output window 321 | processStruct.HostFBO = 0; 322 | 323 | //tell plugin 2 about the current frame time 324 | plugin2->SetTime(curFrameTime); 325 | 326 | //set plugin 2 parameter 0 327 | plugin2->SetFloatParameter(0, mouseY); 328 | 329 | //call the mirror plugin's ProcessOpenGL 330 | if (plugin2->CallProcessOpenGL(processStruct)==FF_SUCCESS) 331 | { 332 | //if the plugin call succeeds, the drawning is complete 333 | } 334 | else 335 | { 336 | //the plugin call failed 337 | FFDebugMessage("Plugin 2's ProcessOpenGL failed"); 338 | } 339 | 340 | glutSwapBuffers(); 341 | glutPostRedisplay(); 342 | } 343 | 344 | void FFGLHostMouseMove(int x, int y) 345 | { 346 | if (x<0) x=0; 347 | else 348 | if (x>WINDOWWIDTH) x = WINDOWWIDTH; 349 | 350 | if (y<0) y = 0; 351 | else 352 | if (y>WINDOWHEIGHT) y = WINDOWHEIGHT; 353 | 354 | mouseX = ((double)x) / (double)WINDOWWIDTH; 355 | mouseY = 1.0 - ((double)y) / (double)WINDOWHEIGHT; 356 | } 357 | 358 | void FFGLHostReshape(int width, int height) 359 | { 360 | //force GLUT to keep the window the same size as when we created it. this is 361 | //to avoid having to re-instantiate plugins 362 | if (width!=WINDOWWIDTH || height!=WINDOWHEIGHT) 363 | { 364 | glutReshapeWindow(WINDOWWIDTH,WINDOWHEIGHT); 365 | } 366 | } 367 | 368 | void UpdateInputTexture(double timeInSeconds) 369 | { 370 | int time = (int)(timeInSeconds*160.0); 371 | 372 | unsigned char *p = inputImage; 373 | 374 | //this algorithm taken from Gabor Papp's minimal freeframe host for linux 375 | for (int y=0; y //for CFBundle* 476 | #include //for chdir() 477 | 478 | void SetCorrectWorkingPath() 479 | { 480 | CFBundleRef mainBundle = CFBundleGetMainBundle(); 481 | CFURLRef url = CFBundleCopyExecutableURL(mainBundle); 482 | if (!url) 483 | return; 484 | 485 | char binPath[1024]; 486 | if (CFURLGetFileSystemRepresentation(url, true, (UInt8 *)binPath, sizeof(binPath))) 487 | { 488 | #ifdef _DEBUG 489 | const char *binaryName = "FFGLHost_debug"; 490 | #else 491 | const char *binaryName = "FFGLHost"; 492 | #endif 493 | 494 | int chopLength = strlen(binaryName); 495 | 496 | //cut the binary name off the end of the binPath 497 | //string so that only the path remains 498 | binPath[strlen(binPath)-chopLength] = 0; 499 | 500 | chdir(binPath); 501 | } 502 | 503 | CFRelease(url); 504 | } -------------------------------------------------------------------------------- /img/Evil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Evil.png -------------------------------------------------------------------------------- /img/Noise-params.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Noise-params.png -------------------------------------------------------------------------------- /img/Noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Noise.png -------------------------------------------------------------------------------- /img/Plasma-params.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Plasma-params.png -------------------------------------------------------------------------------- /img/Plasma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Plasma.png -------------------------------------------------------------------------------- /img/RGBSource-params.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/RGBSource-params.png -------------------------------------------------------------------------------- /img/RGBSource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/RGBSource.png -------------------------------------------------------------------------------- /img/Spiral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Spiral.png -------------------------------------------------------------------------------- /img/Springs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/Springs.png -------------------------------------------------------------------------------- /img/UnderwaterLife.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/UnderwaterLife.png -------------------------------------------------------------------------------- /img/resolume-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilcode/ffglplugin-examples/87d65e7503f526114e3ff862584e88adfb156633/img/resolume-config.png --------------------------------------------------------------------------------