GPUShader - Documentation


Util.{cc,h} : OpenGL utility/helper functions


#define ZERO_VEC4 {0,0,0,0}

used to easily declare a float[4]


struct PluginParam{

const char* name;

int type;

float param[4];

};

Basic block of plugin parameters. An array is sent by the PPlugin, which is filled with values by the UI part.


extern "C" void checkGLErrors (const char *label);

Checks for OpenGL errors. Extremely useful debugging function: When developing, make sure to call this after almost every GL call.


extern "C" void setupTexture (const GLuint texID, int, int);

Sets up a floating point texture with LINEAR filtering.


extern "C" void transferToTexture (float* data, int, int, GLuint texID);

Transfers data to texture.


extern "C" void printProgramInfoLog(GLuint obj) ;

error checking for GLSL


extern "C" void printShaderInfoLog(GLuint obj) ;

prints out shader info, any errors during compilation etc.


bool glInit(float *, int, int);

Initializes OpenGL context, loads gimp image into graphics card tecture.


void glDeInit();

Destroyes OpenGl context, cleans up source texture.


bool checkFramebufferStatus();

Checks framebuffer status. Copied directly out of the spec, modified to deliver a return value.


void transferFromTexture(float* data);

Transfers data from currently texture, and stores it in given array.


static inline unsigned rdtsc(void)

on Intel(R) machines, reads the internal timestamp counter

GPUShader.cc = user and gimp interface



static void query (void);

This function is called by GIMP once after the plugin has been recompiled. It is used to register the shader names with GIMP, so that they appear on the GIMP menu


static void run (const gchar *name,

gint nparams,

const GimpParam *param,

gint *nreturn_vals,

GimpParam **return_vals);

This method is called by GIMP in response to any of our registered menu items being clicked. The method invokes the correct Shader Module depending on the caption of the menu item clicked. This method is usually the entry point for our application


GimpPlugInInfo PLUG_IN_INFO =

{

NULL, /* init_proc */

NULL, /* quit_proc */

query, /* query_proc */

run /* run_proc */

};

This structure is populated by the plugin to provide pointers to the functions 'query' and 'run', to GIMP


static void doStuff(const gchar* pluginName,GimpRunMode run_mode, guchar * buf_in, int width, int height, int bpp);

Called by the 'run' function. It loads the appropriate Shader Module based on the menu item clicked. It calls OpenGL init functions, and invokes the Shader Module. It also loads and unloads pixel data from a float buffer


int getPPlugins(char *directory);

Read the default Shader Module path '$HOME/.gpugimp' and get a list of shader module names


void parseParameters(float* param,int numParam,const char * text);

Parse the parameters entered in entry fields, to convert them to array of float (input is of form "0,1.2,3" and the numbers 0.0, 1.2 and 3.0 should be filled into the float array)


bool makeInterface(const gchar * pluginName,PluginParam* pluginParameters,int numPluginParams);

display the interface corresponding to the params



bool handleGimpRunModes(const gchar * pluginName,PluginParam* pluginParameters,int numPluginParams,GimpRunMode run_mode);

handles displaying the interface and other stuff...



Plugin skeleton


GLuint textureIDs[...];

Ping pong texture IDs to store intermedia textures and any additional textures needed by the shader.


static unsigned int width, height;

Image height and width.


static GLenum attachmentpoints[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };

Attachpoints for off-screen rendering to the FrameBuferObject.


GLSL variables

for example

static GLuint glslProgram; // handle for the GLSL program

static GLuint fragmentShader; // handle for the GLSL pixel shader

static GLint sourceTextureParam; // / handle for the GLSL uniform variable


PluginParam myParams[]={{"alpha",1,ZERO_VEC4},

{"iterations",1,ZERO_VEC4}

};

Parameter list required by the plugin.


extern "C" int getParams(PluginParam** p);

called by GPUShader ui. Returns the plugin parameter list. Must be defined.


void runShader();

Runs the actual shader logic, loading various fragment shaders and executing them in ping-pong way on multiple textutes.


extern "C" void run(GLuint sourceTexID, int _width, int _height)

called by GPUShader ui. Usually compiles fragment shaders and pre-links GLSL programs. Should call runShader()