naev 0.12.5
nlua_shader.c File Reference

Handles shaders. More...

#include "nlua_shader.h"
#include "array.h"
#include "nlua_tex.h"
#include "nluadef.h"
#include "render.h"
Include dependency graph for nlua_shader.c:

Go to the source code of this file.

Macros

#define ATTRIB(name)
#define UNIFORM(name)

Functions

static int shaderL_gc (lua_State *L)
 Frees a shader.
static int shaderL_eq (lua_State *L)
 Compares two shaders to see if they are the same.
static int shaderL_new (lua_State *L)
 Creates a new shader.
static int shaderL_send (lua_State *L)
 Allows setting values of uniforms for a shader. Errors out if the uniform is unknown or unused (as in optimized out by the compiler).
static int shaderL_sendRaw (lua_State *L)
 Allows setting values of uniforms for a shader, while ignoring unknown (or unused) uniforms.
static int shaderL_hasUniform (lua_State *L)
 Checks to see if a shader has a uniform.
static int shaderL_addPostProcess (lua_State *L)
 Sets a shader as a post-processing shader.
static int shaderL_rmPostProcess (lua_State *L)
 Removes a shader as a post-processing shader.
static int shader_compareUniform (const void *a, const void *b)
static int shader_searchUniform (const void *id, const void *u)
static LuaUniform_tshader_getUniform (const LuaShader_t *ls, const char *name)
static int shaderL_sendHelper (lua_State *L, int ignore_missing)
 Helper to set the uniform while handling unknown/inactive uniforms.
int nlua_loadShader (nlua_env env)
 Loads the shader library.
LuaShader_tlua_toshader (lua_State *L, int ind)
 Lua bindings to interact with shaders.
LuaShader_tluaL_checkshader (lua_State *L, int ind)
 Gets shader at index or raises error if there is no shader at index.
LuaShader_tlua_pushshader (lua_State *L, LuaShader_t shader)
 Pushes a shader on the stack.
int lua_isshader (lua_State *L, int ind)
 Checks to see if ind is a shader.
void shader_parseUniformArgsFloat (GLfloat values[4], lua_State *L, int idx, int n)
 Helper to parse up float vector (or arguments).
void shader_parseUniformArgsInt (GLint values[4], lua_State *L, int idx, int n)
 Helper to parse up integer vector (or arguments).

Variables

static const luaL_Reg shaderL_methods []

Detailed Description

Handles shaders.

Definition in file nlua_shader.c.

Macro Definition Documentation

◆ ATTRIB

#define ATTRIB ( name)
Value:
shader.name = glGetAttribLocation( shader.program, #name )

◆ UNIFORM

#define UNIFORM ( name)
Value:
shader.name = glGetUniformLocation( shader.program, #name )

Function Documentation

◆ lua_isshader()

int lua_isshader ( lua_State * L,
int ind )

Checks to see if ind is a shader.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a shader.

Definition at line 112 of file nlua_shader.c.

◆ lua_pushshader()

LuaShader_t * lua_pushshader ( lua_State * L,
LuaShader_t shader )

Pushes a shader on the stack.

Parameters
LLua state to push shader into.
shaderShader to push.
Returns
Newly pushed shader.

Definition at line 97 of file nlua_shader.c.

◆ lua_toshader()

LuaShader_t * lua_toshader ( lua_State * L,
int ind )

Lua bindings to interact with shaders.

Lua module: shader

Gets shader at index.

Parameters
LLua state to get shader from.
indIndex position to find the shader.
Returns
Shader found at the index in the state.

Definition at line 72 of file nlua_shader.c.

◆ luaL_checkshader()

LuaShader_t * luaL_checkshader ( lua_State * L,
int ind )

Gets shader at index or raises error if there is no shader at index.

Parameters
LLua state to get shader from.
indIndex position to find shader.
Returns
Shader found at the index in the state.

Definition at line 83 of file nlua_shader.c.

◆ nlua_loadShader()

int nlua_loadShader ( nlua_env env)

Loads the shader library.

Parameters
envEnvironment to load shader library into.
Returns
0 on success.

Definition at line 54 of file nlua_shader.c.

◆ shader_compareUniform()

int shader_compareUniform ( const void * a,
const void * b )
static

Definition at line 167 of file nlua_shader.c.

◆ shader_getUniform()

LuaUniform_t * shader_getUniform ( const LuaShader_t * ls,
const char * name )
static

Definition at line 180 of file nlua_shader.c.

◆ shader_parseUniformArgsFloat()

void shader_parseUniformArgsFloat ( GLfloat values[4],
lua_State * L,
int idx,
int n )

Helper to parse up float vector (or arguments).

Definition at line 271 of file nlua_shader.c.

◆ shader_parseUniformArgsInt()

void shader_parseUniformArgsInt ( GLint values[4],
lua_State * L,
int idx,
int n )

Helper to parse up integer vector (or arguments).

Definition at line 290 of file nlua_shader.c.

◆ shader_searchUniform()

int shader_searchUniform ( const void * id,
const void * u )
static

Definition at line 175 of file nlua_shader.c.

◆ shaderL_addPostProcess()

int shaderL_addPostProcess ( lua_State * L)
static

Sets a shader as a post-processing shader.

Lua function parameter: Shader shader Shader to set as a post-processing shader. Lua function parameter:[opt="final"] string layer Layer to add the shader to. Lua function parameter:[opt=0] number priority Priority of the shader to set. Higher values mean it is run later. Lua return parameter: boolean true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: addPPShader

Definition at line 441 of file nlua_shader.c.

◆ shaderL_eq()

int shaderL_eq ( lua_State * L)
static

Compares two shaders to see if they are the same.

Lua function parameter: Shader f1 Shader 1 to compare. Lua function parameter: Shader f2 Shader 2 to compare. Lua return parameter: boolean true if both shaders are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 155 of file nlua_shader.c.

◆ shaderL_gc()

int shaderL_gc ( lua_State * L)
static

Frees a shader.

Lua function parameter: Shader shader Shader to free.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __gc

Definition at line 134 of file nlua_shader.c.

◆ shaderL_hasUniform()

int shaderL_hasUniform ( lua_State * L)
static

Checks to see if a shader has a uniform.

Lua function parameter: Shader shader Shader to send uniform to. Lua function parameter: string name Name of the uniform to check. Lua return parameter: boolean true if the shader has the uniform.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: hasUniform

Definition at line 420 of file nlua_shader.c.

◆ shaderL_new()

int shaderL_new ( lua_State * L)
static

Creates a new shader.

Lua function parameter: string vertex Script containing the vertex shader. Lua function parameter: string fragment String containing the fragment shader. Lua return parameter: Shader A newly created shader.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 195 of file nlua_shader.c.

◆ shaderL_rmPostProcess()

int shaderL_rmPostProcess ( lua_State * L)
static

Removes a shader as a post-processing shader.

Lua function parameter: Shader shader Shader to disable as post-processing shader. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: rmPPShader

Definition at line 475 of file nlua_shader.c.

◆ shaderL_send()

int shaderL_send ( lua_State * L)
static

Allows setting values of uniforms for a shader. Errors out if the uniform is unknown or unused (as in optimized out by the compiler).

Lua function parameter: Shader shader Shader to send uniform to. Lua function parameter: string name Name of the uniform.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: send

Definition at line 313 of file nlua_shader.c.

◆ shaderL_sendHelper()

int shaderL_sendHelper ( lua_State * L,
int ignore_missing )
static

Helper to set the uniform while handling unknown/inactive uniforms.

Definition at line 334 of file nlua_shader.c.

◆ shaderL_sendRaw()

int shaderL_sendRaw ( lua_State * L)
static

Allows setting values of uniforms for a shader, while ignoring unknown (or unused) uniforms.

Lua function parameter: Shader shader Shader to send uniform to. Lua function parameter: string name Name of the uniform.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: send

Definition at line 326 of file nlua_shader.c.

Variable Documentation

◆ shaderL_methods

const luaL_Reg shaderL_methods[]
static
Initial value:
= {
{ "__gc", shaderL_gc },
{ "__eq", shaderL_eq },
{ "new", shaderL_new },
{ "send", shaderL_send },
{ "sendRaw", shaderL_sendRaw },
{ "hasUniform", shaderL_hasUniform },
{ "addPPShader", shaderL_addPostProcess },
{ "rmPPShader", shaderL_rmPostProcess },
{ 0, 0 } }
static int shaderL_send(lua_State *L)
Allows setting values of uniforms for a shader. Errors out if the uniform is unknown or unused (as in...
static int shaderL_sendRaw(lua_State *L)
Allows setting values of uniforms for a shader, while ignoring unknown (or unused) uniforms.
static int shaderL_eq(lua_State *L)
Compares two shaders to see if they are the same.
static int shaderL_new(lua_State *L)
Creates a new shader.
static int shaderL_hasUniform(lua_State *L)
Checks to see if a shader has a uniform.
static int shaderL_addPostProcess(lua_State *L)
Sets a shader as a post-processing shader.
static int shaderL_rmPostProcess(lua_State *L)
Removes a shader as a post-processing shader.
static int shaderL_gc(lua_State *L)
Frees a shader.

Shader metatable methods.

Definition at line 30 of file nlua_shader.c.