mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Minor cleanup
This commit is contained in:
@@ -41,6 +41,8 @@ void initializeContext()
|
|||||||
|
|
||||||
contextInitialized = true;
|
contextInitialized = true;
|
||||||
|
|
||||||
|
textureUnits.clear();
|
||||||
|
|
||||||
// initialize multiple texture unit support, if available
|
// initialize multiple texture unit support, if available
|
||||||
if (GLEE_ARB_multitexture || GLEE_VERSION_1_3)
|
if (GLEE_ARB_multitexture || GLEE_VERSION_1_3)
|
||||||
{
|
{
|
||||||
@@ -57,7 +59,6 @@ void initializeContext()
|
|||||||
maxtextureunits = maxtextureimageunits;
|
maxtextureunits = maxtextureimageunits;
|
||||||
}
|
}
|
||||||
|
|
||||||
textureUnits.clear();
|
|
||||||
textureUnits.resize(maxtextureunits, 0);
|
textureUnits.resize(maxtextureunits, 0);
|
||||||
|
|
||||||
GLenum activetextureunit;
|
GLenum activetextureunit;
|
||||||
@@ -83,7 +84,6 @@ void initializeContext()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// multitexturing not supported so we only have 1 texture unit
|
// multitexturing not supported so we only have 1 texture unit
|
||||||
textureUnits.clear();
|
|
||||||
textureUnits.resize(1, 0);
|
textureUnits.resize(1, 0);
|
||||||
curTextureUnitIndex = 0;
|
curTextureUnitIndex = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -21,32 +21,6 @@
|
|||||||
#include "ShaderEffect.h"
|
#include "ShaderEffect.h"
|
||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// temporarily attaches a shader program (for setting uniforms, etc)
|
|
||||||
// reattaches the originally active program when destroyed
|
|
||||||
struct TemporaryAttacher
|
|
||||||
{
|
|
||||||
TemporaryAttacher(love::graphics::opengl::ShaderEffect *sp)
|
|
||||||
: cureffect(sp)
|
|
||||||
, preveffect(love::graphics::opengl::ShaderEffect::current)
|
|
||||||
{
|
|
||||||
cureffect->attach(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
~TemporaryAttacher()
|
|
||||||
{
|
|
||||||
if (preveffect != NULL)
|
|
||||||
preveffect->attach();
|
|
||||||
else
|
|
||||||
love::graphics::opengl::ShaderEffect::detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
love::graphics::opengl::ShaderEffect *cureffect;
|
|
||||||
love::graphics::opengl::ShaderEffect *preveffect;
|
|
||||||
};
|
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace graphics
|
namespace graphics
|
||||||
@@ -54,6 +28,33 @@ namespace graphics
|
|||||||
namespace opengl
|
namespace opengl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// temporarily attaches a shader program (for setting uniforms, etc)
|
||||||
|
// reattaches the originally active program when destroyed
|
||||||
|
struct TemporaryAttacher
|
||||||
|
{
|
||||||
|
TemporaryAttacher(ShaderEffect *sp)
|
||||||
|
: cureffect(sp)
|
||||||
|
, preveffect(ShaderEffect::current)
|
||||||
|
{
|
||||||
|
cureffect->attach(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
~TemporaryAttacher()
|
||||||
|
{
|
||||||
|
if (preveffect != NULL)
|
||||||
|
preveffect->attach();
|
||||||
|
else
|
||||||
|
ShaderEffect::detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderEffect *cureffect;
|
||||||
|
ShaderEffect *preveffect;
|
||||||
|
};
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
ShaderEffect *ShaderEffect::current = NULL;
|
ShaderEffect *ShaderEffect::current = NULL;
|
||||||
|
|
||||||
GLint ShaderEffect::_max_texture_units = 0;
|
GLint ShaderEffect::_max_texture_units = 0;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace opengl
|
|||||||
class ShaderEffect : public Object, public Volatile
|
class ShaderEffect : public Object, public Volatile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum ShaderType
|
enum ShaderType
|
||||||
{
|
{
|
||||||
TYPE_VERTEX,
|
TYPE_VERTEX,
|
||||||
@@ -78,6 +79,7 @@ public:
|
|||||||
void sendCanvas(const std::string &name, const Canvas &canvas);
|
void sendCanvas(const std::string &name, const Canvas &canvas);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GLint getUniformLocation(const std::string &name);
|
GLint getUniformLocation(const std::string &name);
|
||||||
void checkSetUniformError();
|
void checkSetUniformError();
|
||||||
GLuint createShader(const ShaderSource &source);
|
GLuint createShader(const ShaderSource &source);
|
||||||
@@ -90,7 +92,7 @@ private:
|
|||||||
// uniform location buffer
|
// uniform location buffer
|
||||||
std::map<std::string, GLint> _uniforms;
|
std::map<std::string, GLint> _uniforms;
|
||||||
|
|
||||||
static GLint _max_texture_units;
|
static GLint _max_texture_units; // total max GPU texture units for shaders
|
||||||
static std::vector<int> _texture_id_counters; // counts total number of textures bound to each texture unit in all shaders
|
static std::vector<int> _texture_id_counters; // counts total number of textures bound to each texture unit in all shaders
|
||||||
|
|
||||||
// texture unit pool for setting images
|
// texture unit pool for setting images
|
||||||
@@ -99,6 +101,7 @@ private:
|
|||||||
GLint getTextureUnit(const std::string &name);
|
GLint getTextureUnit(const std::string &name);
|
||||||
|
|
||||||
void sendTexture(const std::string &name, GLuint texture);
|
void sendTexture(const std::string &name, GLuint texture);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ int w_newCanvas(lua_State *L)
|
|||||||
int w_newShaderEffect(lua_State *L)
|
int w_newShaderEffect(lua_State *L)
|
||||||
{
|
{
|
||||||
if (!ShaderEffect::isSupported())
|
if (!ShaderEffect::isSupported())
|
||||||
return luaL_error(L, "Sorry, your graphics card does not support pixel effects.");
|
return luaL_error(L, "Sorry, your graphics card does not support shader effects.");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1305,6 +1305,7 @@ do
|
|||||||
#define VertexPosition gl_Vertex
|
#define VertexPosition gl_Vertex
|
||||||
|
|
||||||
uniform sampler2D _tex0_;
|
uniform sampler2D _tex0_;
|
||||||
|
|
||||||
#line 0]],
|
#line 0]],
|
||||||
FOOTER = [[
|
FOOTER = [[
|
||||||
void main() {
|
void main() {
|
||||||
@@ -1331,6 +1332,7 @@ void main() {
|
|||||||
#define VaryingTexCoord gl_TexCoord[0]
|
#define VaryingTexCoord gl_TexCoord[0]
|
||||||
|
|
||||||
uniform sampler2D _tex0_;
|
uniform sampler2D _tex0_;
|
||||||
|
|
||||||
#line 0]],
|
#line 0]],
|
||||||
FOOTER = [[
|
FOOTER = [[
|
||||||
void main() {
|
void main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user