2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2012-09-23 02:51:13 +00:00
|
|
|
#ifndef BBGE_SHADER_H
|
|
|
|
#define BBGE_SHADER_H
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
#include "Base.h"
|
2013-05-11 22:05:57 +00:00
|
|
|
#include "ScriptObject.h"
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2013-06-15 02:11:11 +00:00
|
|
|
class Shader
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Shader();
|
|
|
|
~Shader();
|
2013-05-11 22:05:57 +00:00
|
|
|
bool isLoaded() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
void load(const std::string &file, const std::string &fragFile);
|
2013-05-10 20:22:35 +00:00
|
|
|
void loadSrc(const char *vertCode, const char *fragCode);
|
2011-08-03 20:05:33 +00:00
|
|
|
void reload();
|
2013-05-10 20:22:35 +00:00
|
|
|
void unload();
|
2011-08-03 20:05:33 +00:00
|
|
|
void bind();
|
|
|
|
void unbind();
|
2013-05-10 20:22:35 +00:00
|
|
|
|
2013-05-11 22:05:57 +00:00
|
|
|
void setInt(const char *name, int x, int y = 0, int z = 0, int w = 0);
|
|
|
|
void setFloat(const char *name, float x, float y = 0, float z = 0, float w = 0);
|
|
|
|
// TODO: other setters needed?
|
2013-05-10 20:22:35 +00:00
|
|
|
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
protected:
|
2013-05-10 20:22:35 +00:00
|
|
|
std::string vertFile, fragFile;
|
2013-10-24 23:44:34 +00:00
|
|
|
std::string vertSrc, fragSrc;
|
2016-07-09 02:18:40 +00:00
|
|
|
unsigned g_programObj;
|
2013-05-11 22:05:57 +00:00
|
|
|
int numUniforms;
|
2012-02-05 19:26:23 +00:00
|
|
|
|
2013-05-10 20:22:35 +00:00
|
|
|
private:
|
2012-02-05 19:26:23 +00:00
|
|
|
static void staticInit();
|
|
|
|
static bool _wasInited;
|
|
|
|
static bool _useShaders;
|
2013-05-10 20:22:35 +00:00
|
|
|
|
|
|
|
static unsigned int _compileShader(int type, const char *src, char *errbuf, size_t errbufsize);
|
2013-05-11 22:05:57 +00:00
|
|
|
|
|
|
|
struct Uniform
|
|
|
|
{
|
|
|
|
int location; // GL location variable
|
|
|
|
int type;
|
|
|
|
bool dirty; // need to flush if true
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int i[4];
|
|
|
|
};
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
float f[4];
|
|
|
|
};
|
|
|
|
} data;
|
2013-10-24 23:44:34 +00:00
|
|
|
char name[64];
|
2013-05-11 22:05:57 +00:00
|
|
|
|
|
|
|
bool operator< (const Uniform&) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool _sortUniform(const Uniform& a, const char *bname);
|
|
|
|
|
|
|
|
void _queryUniforms();
|
|
|
|
void _flushUniforms();
|
|
|
|
void _registerUniform();
|
|
|
|
|
|
|
|
void _setUniform(Uniform *u);
|
|
|
|
int _getUniformIndex(const char *name);
|
|
|
|
|
|
|
|
typedef std::vector<Uniform> UniformVec;
|
|
|
|
UniformVec uniforms;
|
|
|
|
|
|
|
|
bool uniformsDirty;
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
2012-09-23 02:51:13 +00:00
|
|
|
|
|
|
|
#endif
|