More code restructuring.

Move all love.graphics functionality that doesn’t call OpenGL out of the OpenGL backend Graphics class.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-12-30 18:36:54 -04:00
parent d94b363b39
commit f12596dd19
38 changed files with 1603 additions and 1431 deletions
+13 -146
View File
@@ -18,14 +18,11 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_SHADER_H
#define LOVE_GRAPHICS_SHADER_H
#pragma once
// LOVE
#include "common/Object.h"
#include "common/StringMap.h"
#include "graphics/Shader.h"
#include "graphics/Graphics.h"
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
#include "OpenGL.h"
@@ -42,93 +39,10 @@ namespace opengl
{
// A GLSL shader
class Shader : public Object, public Volatile
class Shader final : public love::graphics::Shader, public Volatile
{
public:
static love::Type type;
enum ShaderStage
{
STAGE_VERTEX,
STAGE_PIXEL,
STAGE_MAX_ENUM
};
// Built-in uniform variables.
enum BuiltinUniform
{
BUILTIN_TRANSFORM_MATRIX = 0,
BUILTIN_PROJECTION_MATRIX,
BUILTIN_TRANSFORM_PROJECTION_MATRIX,
BUILTIN_NORMAL_MATRIX,
BUILTIN_POINT_SIZE,
BUILTIN_SCREEN_SIZE,
BUILTIN_VIDEO_Y_CHANNEL,
BUILTIN_VIDEO_CB_CHANNEL,
BUILTIN_VIDEO_CR_CHANNEL,
BUILTIN_MAX_ENUM
};
// Types of potential uniform variables used in love's shaders.
enum UniformType
{
UNIFORM_FLOAT,
UNIFORM_MATRIX,
UNIFORM_INT,
UNIFORM_BOOL,
UNIFORM_SAMPLER,
UNIFORM_UNKNOWN,
UNIFORM_MAX_ENUM
};
struct ShaderSource
{
std::string vertex;
std::string pixel;
};
struct MatrixSize
{
short columns;
short rows;
};
struct UniformInfo
{
int location;
int count;
union
{
int components;
MatrixSize matrix;
};
UniformType baseType;
std::string name;
union
{
void *data;
float *floats;
int *ints;
};
Texture **textures;
};
// Pointer to currently active Shader.
static Shader *current;
// Pointer to the default Shader.
static Shader *defaultShader;
static Shader *defaultVideoShader;
// Default shader code (a shader is always required internally.)
static ShaderSource defaultCode[Graphics::RENDERER_MAX_ENUM][2];
static ShaderSource defaultVideoCode[Graphics::RENDERER_MAX_ENUM][2];
/**
* Creates a new Shader using a list of source codes.
* Source must contain either vertex or pixel shader code, or both.
@@ -138,45 +52,19 @@ public:
virtual ~Shader();
// Implements Volatile
virtual bool loadVolatile();
virtual void unloadVolatile();
bool loadVolatile() override;
void unloadVolatile() override;
/**
* Binds this Shader's program to be used when rendering.
*
* @param temporary True if we just want to send values to the shader with no intention of rendering.
**/
void attach(bool temporary = false);
/**
* Detach the currently bound Shader.
* Causes the GPU rendering pipeline to use fixed functionality in place of shader programs.
**/
static void detach();
/**
* Returns any warnings this Shader may have generated.
**/
std::string getWarnings() const;
const UniformInfo *getUniformInfo(const std::string &name) const;
void updateUniform(const UniformInfo *info, int count, bool internalUpdate = false);
void sendTextures(const UniformInfo *info, Texture **textures, int count, bool internalUpdate = false);
/**
* Gets whether a uniform with the specified name exists and is actively
* used in the shader.
**/
bool hasUniform(const std::string &name) const;
// Implements Shader.
void attach(bool temporary = false) override;
std::string getWarnings() const override;
const UniformInfo *getUniformInfo(const std::string &name) const override;
void updateUniform(const UniformInfo *info, int count, bool internalUpdate = false) override;
void sendTextures(const UniformInfo *info, Texture **textures, int count, bool internalUpdate = false) override;
bool hasUniform(const std::string &name) const override;
GLint getAttribLocation(const std::string &name);
/**
* Internal use only.
**/
bool hasVertexAttrib(VertexAttribID attrib) const;
void setVideoTextures(GLuint ytexture, GLuint cbtexture, GLuint crtexture);
void checkSetScreenParams();
void checkSetPointSize(float size);
@@ -190,12 +78,6 @@ public:
static std::string getGLSLVersion();
static bool isSupported();
static bool getConstant(const char *in, UniformType &out);
static bool getConstant(UniformType in, const char *&out);
static bool getConstant(const char *in, VertexAttribID &out);
static bool getConstant(VertexAttribID in, const char *&out);
private:
struct TextureUnit
@@ -255,23 +137,8 @@ private:
GLuint videoTextureUnits[3];
static StringMap<ShaderStage, STAGE_MAX_ENUM>::Entry stageNameEntries[];
static StringMap<ShaderStage, STAGE_MAX_ENUM> stageNames;
static StringMap<UniformType, UNIFORM_MAX_ENUM>::Entry uniformTypeEntries[];
static StringMap<UniformType, UNIFORM_MAX_ENUM> uniformTypes;
// Names for the generic vertex attributes used by love.
static StringMap<VertexAttribID, ATTRIB_MAX_ENUM>::Entry attribNameEntries[];
static StringMap<VertexAttribID, ATTRIB_MAX_ENUM> attribNames;
// Names for the built-in uniform variables.
static StringMap<BuiltinUniform, BUILTIN_MAX_ENUM>::Entry builtinNameEntries[];
static StringMap<BuiltinUniform, BUILTIN_MAX_ENUM> builtinNames;
};
}; // Shader
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_SHADER_H