shaderProgram.h File Reference

Functions for working with shaders. More...

`#include <3ds/types.h>`
`#include <3ds/gpu/shbin.h>`

Go to the source code of this file.

## Data Structures

struct | float24Uniform_s
| 24-bit float uniforms. More...
struct | shaderInstance_s
| Describes an instance of either a vertex or geometry shader. More...
struct | shaderProgram_s
| Describes an instance of a full shader program. More...

## Functions

Result | shaderInstanceInit (shaderInstance_s *si, DVLE_s *dvle)
| Initializes a shader instance. More...
Result | shaderInstanceFree (shaderInstance_s *si)
| Frees a shader instance. More...
Result | shaderInstanceSetBool (shaderInstance_s *si, int id, bool value)
| Sets a bool uniform of a shader. More...
Result | shaderInstanceGetBool (shaderInstance_s *si, int id, bool *value)
| Gets a bool uniform of a shader. More...
s8 | shaderInstanceGetUniformLocation (shaderInstance_s *si, const char *name)
| Gets the location of a shader's uniform. More...
Result | shaderProgramInit (shaderProgram_s *sp)
| Initializes a shader program. More...
Result | shaderProgramFree (shaderProgram_s *sp)
| Frees a shader program. More...
Result | shaderProgramSetVsh (shaderProgram_s *sp, DVLE_s *dvle)
| Sets the vertex shader of a shader program. More...
Result | shaderProgramSetGsh (shaderProgram_s *sp, DVLE_s *dvle, u8 stride)
| Sets the geometry shader of a shader program. More...
Result | shaderProgramSetGshInputPermutation (shaderProgram_s *sp, u64 permutation)
| Configures the permutation of the input attributes of the geometry shader of a shader program. More...
Result | shaderProgramConfigure (shaderProgram_s *sp, bool sendVshCode, bool sendGshCode)
| Configures the shader units to use the specified shader program. More...
Result | shaderProgramUse (shaderProgram_s *sp)
| Same as shaderProgramConfigure, but always loading code/operand descriptors and uploading DVLE constants afterwards. More...

## Detailed Description

Functions for working with shaders.

## Function Documentation

## shaderInstanceFree()

Result shaderInstanceFree | ( | shaderInstance_s * | si | ) |

Frees a shader instance.

Parameters

  si | Shader instance to free.

## shaderInstanceGetBool()

Result shaderInstanceGetBool | ( | shaderInstance_s * | si,
|  | int | id,
|  | bool * | value
| ) |  |

Gets a bool uniform of a shader.

Parameters

  si | Shader instance to use.
  id | ID of the bool uniform.
  value | Pointer to output the value to.

## shaderInstanceGetUniformLocation()

s8 shaderInstanceGetUniformLocation | ( | shaderInstance_s * | si,
|  | const char * | name
| ) |  |

Gets the location of a shader's uniform.

Parameters

  si | Shader instance to use.
  name | Name of the uniform.

Examples
  graphics/gpu/both_screens/source/main.c, graphics/gpu/fragment_light/source/main.c, graphics/gpu/geoshader/source/main.c, graphics/gpu/immediate/source/main.c, graphics/gpu/lenny/source/main.c, graphics/gpu/loop_subdivision/source/main.c, graphics/gpu/mipmap_fog/source/main.c, graphics/gpu/particles/source/main.c, graphics/gpu/proctex/source/main.c, graphics/gpu/simple_tri/source/main.c, graphics/gpu/textured_cube/source/main.c, and graphics/gpu/toon_shading/source/main.c.

## shaderInstanceInit()

Result shaderInstanceInit | ( | shaderInstance_s * | si,
|  | DVLE_s * | dvle
| ) |  |

Initializes a shader instance.

Parameters

  si | Shader instance to initialize.
  dvle | DVLE to initialize the shader instance with.

## shaderInstanceSetBool()

Result shaderInstanceSetBool | ( | shaderInstance_s * | si,
|  | int | id,
|  | bool | value
| ) |  |

Sets a bool uniform of a shader.

Parameters

  si | Shader instance to use.
  id | ID of the bool uniform.
  value | Value to set.

## shaderProgramConfigure()

Result shaderProgramConfigure | ( | shaderProgram_s * | sp,
|  | bool | sendVshCode,
|  | bool | sendGshCode
| ) |  |

Configures the shader units to use the specified shader program.

Parameters

  sp | Shader program to use.
  sendVshCode | When true, the vertex shader's code and operand descriptors are uploaded.
  sendGshCode | When true, the geometry shader's code and operand descriptors are uploaded.

## shaderProgramFree()

Result shaderProgramFree | ( | shaderProgram_s * | sp | ) |

Frees a shader program.

Parameters

  sp | Shader program to free.

Examples
  graphics/gpu/both_screens/source/main.c, graphics/gpu/fragment_light/source/main.c, graphics/gpu/geoshader/source/main.c, graphics/gpu/immediate/source/main.c, graphics/gpu/lenny/source/main.c, graphics/gpu/loop_subdivision/source/main.c, graphics/gpu/mipmap_fog/source/main.c, graphics/gpu/particles/source/main.c, graphics/gpu/proctex/source/main.c, graphics/gpu/simple_tri/source/main.c, graphics/gpu/textured_cube/source/main.c, and graphics/gpu/toon_shading/source/main.c.

## shaderProgramInit()

Result shaderProgramInit | ( | shaderProgram_s * | sp | ) |

Initializes a shader program.

Parameters

  sp | Shader program to initialize.

Examples
  graphics/gpu/both_screens/source/main.c, graphics/gpu/fragment_light/source/main.c, graphics/gpu/geoshader/source/main.c, graphics/gpu/immediate/source/main.c, graphics/gpu/lenny/source/main.c, graphics/gpu/loop_subdivision/source/main.c, graphics/gpu/mipmap_fog/source/main.c, graphics/gpu/particles/source/main.c, graphics/gpu/proctex/source/main.c, graphics/gpu/simple_tri/source/main.c, graphics/gpu/textured_cube/source/main.c, and graphics/gpu/toon_shading/source/main.c.

## shaderProgramSetGsh()

Result shaderProgramSetGsh | ( | shaderProgram_s * | sp,
|  | DVLE_s * | dvle,
|  | u8 | stride
| ) |  |

Sets the geometry shader of a shader program.

Parameters

  sp | Shader program to use.
  dvle | Geometry shader to set.
  stride | Input stride of the shader (pass 0 to match the number of outputs of the vertex shader).

Examples
  graphics/gpu/geoshader/source/main.c, graphics/gpu/loop_subdivision/source/main.c, and graphics/gpu/particles/source/main.c.

## shaderProgramSetGshInputPermutation()

Result shaderProgramSetGshInputPermutation | ( | shaderProgram_s * | sp,
|  | u64 | permutation
| ) |  |

Configures the permutation of the input attributes of the geometry shader of a shader program.

Parameters

  sp | Shader program to use.
  permutation | Attribute permutation to use.

## shaderProgramSetVsh()

Result shaderProgramSetVsh | ( | shaderProgram_s * | sp,
|  | DVLE_s * | dvle
| ) |  |

Sets the vertex shader of a shader program.

Parameters

  sp | Shader program to use.
  dvle | Vertex shader to set.

Examples
  graphics/gpu/both_screens/source/main.c, graphics/gpu/fragment_light/source/main.c, graphics/gpu/geoshader/source/main.c, graphics/gpu/immediate/source/main.c, graphics/gpu/lenny/source/main.c, graphics/gpu/loop_subdivision/source/main.c, graphics/gpu/mipmap_fog/source/main.c, graphics/gpu/particles/source/main.c, graphics/gpu/proctex/source/main.c, graphics/gpu/simple_tri/source/main.c, graphics/gpu/textured_cube/source/main.c, and graphics/gpu/toon_shading/source/main.c.

## shaderProgramUse()

Result shaderProgramUse | ( | shaderProgram_s * | sp | ) |

Same as shaderProgramConfigure, but always loading code/operand descriptors and uploading DVLE constants afterwards.

Parameters

  sp | Shader program to use.