Skip to content

Executing Shaders

Adam Gorski edited this page Aug 17, 2021 · 1 revision

Executing a standard shader

To execute a standard shader, an object, a projection matrix and a depthbuffer will be required:

//A depth buffer and object will be required
GLTexture depthBuffer = ...;
GLBuffer teapotObject = ...;

//Load shader and assign its frame buffers and uniforms
Shader teapotShader = ...;
AssignBuffersAndUniforms(teapotShader);

//Create a projection matrix, with a FOV of 90
GLMatrix projMatrix = GLMatrix.Perspective(90.0f, viewportWidth, viewportHeight);

//Execute the draw command
GL.Draw(teapotObject, teapotShader, depthBuffer, projMatrix, GLMode.Triangle);

You can also set the start and stop triangle index:

//render the first 12 triangles:
GL.Draw(teapotObject, teapotShader, depthBuffer, projMatrix, GLMode.Triangle, 0, 12);

Executing a screenspace shader

To execute a screenspace, you can either use the GL.Pass() from GL or Pass() method from the shader. Both do the same thing.

//Load shader and assign its frame buffers and uniforms
Shader ssaoShader = ...;
AssignBuffersAndUniforms(ssaoShader);

ssaoShader.Pass();
//Or
GL.Pass(ssaoShader);

Clone this wiki locally