I am going through the book “Mastering openFrameworks” and on page 214 it is mentioned that compute shader can be used for universal computation along with OF. So far as i know compute shader is supported in opengl 4.3 and OF uses opengl 3 if the programmable renderer is used.
In that case i do not understand how to use the compute shader with the existing version of OF.
you can’t, it’s actually relatively easy to change the core to support any other version of openGL just edit ofAppRunner to change the version of openGL and then the programmable GL renderer to change the default shader versions to the corresponding GLSL version. even with that ofShader doesn’t support compute shaders yet although it should be easy to hack it as well. but no in principle there’s no support for compute shaders or anything beyond openGL 3.2
ofAppRunner and ofGLProgrammableRenderer, i’m looking at ofShader and it’s possible that you won’t need to change it if you use setupShaderFromSource instead of load.
I managed to change some of the parameters within the file you suggested and it is as follows
//--------------------------------------
void ofSetupOpenGL(ofPtr<ofAppBaseWindow> windowPtr, int w, int h, int screenMode){
//if the current renderer is not found
if(!ofGetCurrentRenderer()) {
#ifdef USE_PROGRAMMABLE_GL
//if the programmable renderer is defined create a new instance of it
ofPtr<ofBaseRenderer> renderer(new ofGLProgrammableRenderer(false));
#else
//otherwise create a normal renderer instance
ofPtr<ofBaseRenderer> renderer(new ofGLRenderer(false));
#endif
//set the newly created renderer as the current one
ofSetCurrentRenderer(renderer,false);
}
window = windowPtr;
//IF WE DEAL WITH PROGRAMMABLE PIPELINE ONY
//WHICH VERSION SHOULD WE CONSIDER
if(ofIsGLProgrammableRenderer())
{
#if defined(TARGET_RASPBERRY_PI)
static_cast<ofAppEGLWindow*>(window.get())->setGLESVersion(2);
#elif defined(TARGET_LINUX_ARM)
static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(2,0);
#elif !defined(TARGET_OPENGLES)
//THIS IS WHERE I EDIT - SAJJAD****************** previous one - (3,2)
static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(4,3);
#endif
}
else
{
And inside the ofGLProgrammableRenderer i did not find anything else to change other than altering the version string as follows:
#version 430 core
What do i have to look into ? I build the library again after the changes and it build fine.
Now it is time to test. Any hint to get started with ?
I guess that there are more to be done other than extending the ofShader to compute shader. Now it is mandatory to create vertex array object in the OpenGL 4.3 core profile irrespective of the fact one is using the vbo or not.
glGenVertexArrays(...)
I think i have to do some more changes within the ofGLProgrammableRenderer and ofVbo classes. It will be nice if you could suggest me which functions i should look into within these two classes or if i have to look into somewhere else.
Really? It means that if i use your branch i do not have to make those changes with in the API that have been discussed from the beginning of this thread.
And again, i checked the ofShader and ofGLProgrammableRenderer class of this branch and i do not see where you incorporated the provision of tesselation control shader and tesselation evaluation shader which are part of the opengl 4.3 core profile. Yes, they could be written , but we have avoid using the ofShader::load(…) function.
yes with that branch you don’t need to do any changes.
and no, i haven’t done any change to ofShader since it’ll complicate the load function a lot so you’ll need to load the shaders using setupShaderFromSource instead of load
Do i have to include some more file inside the main.cpp . I am getting error with the following snippet:
#include "ofMain.h"
#include "ofApp.h"
// comment out the line below if you want to use a fixed pipeline opengl renderer,
// otherwise leave this line uncommented if you want to use a programmable pipeline opengl renderer.
#define USE_PROGRAMMABLE_RENDERER
#ifdef USE_PROGRAMMABLE_RENDERER
#include "ofGLProgrammableRenderer.h"
#endif
//========================================================================
int main( )
{
#ifdef USE_PROGRAMMABLE_RENDERER
ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);
#endif
//ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
ofSetGLVersion(4,3);
ofSetupOpenGL(1024,768, OF_FULLSCREEN);
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
And i am getting the error
src/main.cpp: In function ‘int main()’:
src/main.cpp:18:22: error: ‘ofSetGLVersion’ was not declared in this scope
ofSetGLVersion(4,3);
None of the shaders app works with the new programmable branch. I am getting the following error:
sajjad@sajjad-G74Sx:~/Downloads/openFrameworks/moreProgrammable/openFrameworks-feature-moreProgrammableGL/apps/myApps/myShaderRimLight$ [verbose] ofxAssimpModelLoader: loadModel(): loading "buddha.obj" from "/home/sajjad/Downloads/openFrameworks/moreProgrammable/openFrameworks-feature-moreProgrammableGL/apps/myApps/myShaderRimLight/bin/data/"
[verbose] ofxAssimpModelLoader: calculateDimensions(): inited scene with 2 meshes & 0 animations
[verbose] ofxAssimpModelLoader: loadGLResources(): starting
[verbose] ofxAssimpModelLoader: loadGLResources(): loading mesh 0
[verbose] ofxAssimpModelLoader: loadGLResources(): loading mesh 1
[verbose] ofxAssimpModelLoader: loadGLResource(): finished
[verbose] ofxAssimpModelLoader: loadMode(): no animations
[verbose] ofShader: checkAndCreateProgram(): creating GLSL program
[verbose] ofShader: setupShaderFromSource(): GL_VERTEX_SHADER shader compiled
[verbose] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader compiled
[verbose] linkProgram(): attaching GL_FRAGMENT_SHADER shader to program 22
[verbose] linkProgram(): attaching GL_VERTEX_SHADER shader to program 22
[verbose] ofShader: checkProgramLinkStatus(): program 22linked
[verbose] ofTrueTypeFont: loadFontFace(): "sans-serif" not a file in data loading system font from "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
[verbose] ofTrueTypeFont: loadFontFace(): "sans-serif" not a file in data loading system font from "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
[verbose] ofTrueTypeFont: loadFontFace(): "sans-serif" not a file in data loading system font from "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
[verbose] ofShader: checkAndCreateProgram(): creating GLSL program
[verbose] ofShader: setupShaderFromSource(): GL_VERTEX_SHADER shader compiled
[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
0(10) : error C1043: size of dimension cannot be less than 1
[verbose] linkProgram(): attaching GL_VERTEX_SHADER shader to program 25
[verbose] ofShader: checkProgramLinkStatus(): program 25linked
[verbose] ofShader: checkAndCreateProgram(): creating GLSL program
[verbose] ofShader: setupShaderFromSource(): GL_VERTEX_SHADER shader compiled
[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
0(11) : error C1043: size of dimension cannot be less than 1
[verbose] linkProgram(): attaching GL_VERTEX_SHADER shader to program 28
[verbose] ofShader: checkProgramLinkStatus(): program 28linked
[verbose] ofShader: checkAndCreateProgram(): creating GLSL program
[verbose] ofShader: setupShaderFromSource(): GL_VERTEX_SHADER shader compiled
[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
0(11) : error C1043: size of dimension cannot be less than 1
[verbose] linkProgram(): attaching GL_VERTEX_SHADER shader to program 31
[verbose] ofShader: checkProgramLinkStatus(): program 31linked
are you using materials? in that case you need at least a light enabled for them to work, i’ll fix this so it reports an error or the shader doesn’t fail to compile, but the error C1043: size of dimension cannot be less than 1 seems related to that, unless it comes from your own shaders
Did you mean ofLight ? I have a point light defined inside shader and i wanted to preserve it. If it has to be programmable pipeline, would it not be better to remove the some fixed-pipeline stuff ?