2010-02-08 17:23:39 +01:00
|
|
|
/* Copyright (c) 2010 Wildfire Games
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2010-02-08 17:23:39 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* load and link together shaders; provides hotload support.
|
2006-04-12 01:59:08 +02:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_OGL_SHADER
|
|
|
|
#define INCLUDED_OGL_SHADER
|
2005-10-05 18:42:09 +02:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "lib/res/handle.h"
|
2010-07-04 12:15:53 +02:00
|
|
|
#include "lib/file/vfs/vfs.h"
|
2005-10-05 18:42:09 +02:00
|
|
|
|
|
|
|
#include "lib/ogl.h"
|
|
|
|
|
2006-09-22 15:19:40 +02:00
|
|
|
|
|
|
|
namespace ERR
|
|
|
|
{
|
|
|
|
const LibError SHDR_CREATE = -120200;
|
|
|
|
const LibError SHDR_COMPILE = -120201;
|
|
|
|
const LibError SHDR_NO_SHADER = -120202;
|
|
|
|
const LibError SHDR_LINK = -120203;
|
|
|
|
const LibError SHDR_NO_PROGRAM = -120204;
|
|
|
|
}
|
|
|
|
|
2005-10-05 18:42:09 +02:00
|
|
|
/*
|
|
|
|
Encapsulate shader objects into handles, which transparently enables sharing
|
|
|
|
of shader source files between programs as well as reloading shaders at
|
|
|
|
runtime.
|
|
|
|
|
|
|
|
NOTE: Only use functions form this module after verifying that the required
|
|
|
|
extensions are available, or all bets are off.
|
|
|
|
*/
|
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Create, load and compile a shader object.
|
|
|
|
*
|
2010-07-29 17:55:41 +02:00
|
|
|
* @param vfs
|
|
|
|
* @param pathname Location of the file containing the shader's source code.
|
|
|
|
* @param type Type e.g. GL_VERTEX_SHADER_ARB.
|
2008-07-05 20:46:12 +02:00
|
|
|
**/
|
2010-07-04 12:15:53 +02:00
|
|
|
Handle ogl_shader_load(const PIVFS& vfs, const VfsPath& pathname, GLenum type);
|
2005-10-05 18:42:09 +02:00
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Free all resources associated with the given handle
|
|
|
|
* (subject to reference counting).
|
|
|
|
**/
|
2005-10-05 18:42:09 +02:00
|
|
|
void ogl_shader_free(Handle& h);
|
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Attach a shader to the given OpenGL program.
|
|
|
|
**/
|
2005-12-11 23:23:55 +01:00
|
|
|
LibError ogl_shader_attach(GLhandleARB program, Handle& h);
|
2005-10-05 18:42:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Encapsulate program objects into handles.
|
|
|
|
*/
|
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Load a program object.
|
|
|
|
*
|
2010-07-29 17:55:41 +02:00
|
|
|
* @param vfs
|
2008-07-05 20:46:12 +02:00
|
|
|
* @param pathname XML file describing the program.
|
|
|
|
*
|
|
|
|
* note: Shader objects are loaded and attached automatically.
|
|
|
|
**/
|
2010-07-04 12:15:53 +02:00
|
|
|
Handle ogl_program_load(const PIVFS& vfs, const VfsPath& pathname);
|
2005-10-05 18:42:09 +02:00
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Free all resources associated with the given program handle.
|
|
|
|
* (subject to reference counting).
|
|
|
|
**/
|
2005-10-05 18:42:09 +02:00
|
|
|
void ogl_program_free(Handle& h);
|
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Activate the program (glUseProgramObjectARB).
|
|
|
|
*
|
|
|
|
* @param h may be 0, in which case program objects are disabled.
|
|
|
|
**/
|
2005-12-11 23:23:55 +01:00
|
|
|
LibError ogl_program_use(Handle h);
|
2005-10-05 18:42:09 +02:00
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Query uniform information
|
|
|
|
**/
|
2005-10-05 18:42:09 +02:00
|
|
|
GLint ogl_program_get_uniform_location(Handle h, const char* name);
|
|
|
|
|
2008-07-05 20:46:12 +02:00
|
|
|
/**
|
|
|
|
* Query vertex attribute information
|
|
|
|
**/
|
2005-10-30 02:22:22 +02:00
|
|
|
GLint ogl_program_get_attrib_location(Handle h, const char* name);
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_OGL_SHADER
|