Gamedev Framework (gf)
0.11.0
A C++14 framework for 2D games
include
gf
Shader.h
1
/*
2
* Gamedev Framework (gf)
3
* Copyright (C) 2016-2018 Julien Bernard
4
*
5
* This software is provided 'as-is', without any express or implied
6
* warranty. In no event will the authors be held liable for any damages
7
* arising from the use of this software.
8
*
9
* Permission is granted to anyone to use this software for any purpose,
10
* including commercial applications, and to alter it and redistribute it
11
* freely, subject to the following restrictions:
12
*
13
* 1. The origin of this software must not be misrepresented; you must not
14
* claim that you wrote the original software. If you use this software
15
* in a product, an acknowledgment in the product documentation would be
16
* appreciated but is not required.
17
* 2. Altered source versions must be plainly marked as such, and must not be
18
* misrepresented as being the original software.
19
* 3. This notice may not be removed or altered from any source distribution.
20
*
21
* Part of this file comes from SFML, with the same license:
22
* Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23
*/
24
#ifndef GF_SHADER_H
25
#define GF_SHADER_H
26
27
#include <string>
28
#include <map>
29
30
#include "Matrix.h"
31
#include "Path.h"
32
#include "Portability.h"
33
#include "StringRef.h"
34
#include "Texture.h"
35
#include "Vector.h"
36
37
namespace
gf
{
38
#ifndef DOXYGEN_SHOULD_SKIP_THIS
39
inline
namespace
v1 {
40
#endif
41
42
class
InputStream;
43
120
class
GF_API
Shader
{
121
public
:
125
enum
Type
{
126
Vertex
,
127
Fragment
,
128
};
129
135
Shader
();
136
140
~
Shader
();
141
145
Shader
(
const
Shader
&) =
delete
;
146
150
Shader
& operator=(
const
Shader
&) =
delete
;
151
176
bool
loadFromFile(
const
Path
& filename,
Type
type);
177
198
bool
loadFromFile(
const
Path
& vertexShaderFilename,
const
Path
& fragmentShaderFilename);
199
218
bool
loadFromMemory(
StringRef
shader,
Type
type);
219
240
bool
loadFromMemory(
StringRef
vertexShader,
StringRef
fragmentShader);
241
242
261
bool
loadFromStream(
InputStream
& stream,
Type
type);
262
282
bool
loadFromStream(
InputStream
& vertexShaderStream,
InputStream
& fragmentShaderStream);
283
297
void
setUniform(
StringRef
name,
float
val);
298
305
void
setUniform(
StringRef
name,
int
val);
306
313
void
setUniform(
StringRef
name,
const
Vector2f
& vec);
314
321
void
setUniform(
StringRef
name,
const
Vector3f
& vec);
322
329
void
setUniform(
StringRef
name,
const
Vector4f
& vec);
330
337
void
setUniform(
StringRef
name,
const
Matrix3f
& mat);
338
345
void
setUniform(
StringRef
name,
const
Matrix4f
& mat);
346
373
void
setUniform(
StringRef
name,
const
BareTexture
& tex);
374
385
static
void
bind(
const
Shader
*shader);
386
387
private
:
388
friend
class
RenderTarget
;
389
bool
compile(
const
char
*vertexShaderCode,
const
char
*fragmentShaderCode);
390
int
getUniformLocation(
StringRef
name);
391
int
getAttributeLocation(
StringRef
name);
392
393
struct
Guard;
394
395
private
:
396
unsigned
m_program;
397
398
std::map<int, const BareTexture *> m_textures;
399
};
400
401
#ifndef DOXYGEN_SHOULD_SKIP_THIS
402
}
403
#endif
404
}
405
406
#endif // GF_SHADER_H
gf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition:
RenderTarget.h:66
gf::Shader
An OpenGL vertex and/or fragment shader.
Definition:
Shader.h:120
gf::Matrix< float, 3, 3 >
gf
The namespace for gf classes.
Definition:
Action.h:35
gf::BareTexture
An image that lives in the graphic memory that can be used for drawing.
Definition:
Texture.h:67
gf::InputStream
Abstract class for custom file input streams.
Definition:
Stream.h:54
gf::Path
boost::filesystem::path Path
A path in the filesystem.
Definition:
Path.h:44
gf::Shader::Type
Type
Type of shaders.
Definition:
Shader.h:125
gf::StringRef
A constant reference to a string and its size.
Definition:
StringRef.h:41
gf::Vector< float, 2 >
gf::Shader::Fragment
Type for a fragment (or pixel) shader.
Definition:
Shader.h:127
gf::Shader::Vertex
Type for a vertex shader.
Definition:
Shader.h:126
Generated by
1.8.13