Toggle navigation
ivorium
iv_components
Example project
GitHub
Main Page
Modules
Classes
Files
File List
File Members
ivorium_graphics
Rendering
Shader.cpp
Go to the documentation of this file.
1
#include "
Shader.hpp
"
2
3
#include <
ivorium_core/ivorium_core.hpp
>
4
#include <
ivorium_systems/ivorium_systems.hpp
>
5
6
namespace
iv
7
{
8
9
Shader::Shader
(
Instance
* inst,
ResourcePath
const
& path ) :
10
cm( inst, this,
"Shader"
,
ClientMarker
::Status() ),
11
inst( inst ),
12
_src_path( path ),
13
_gl_program()
14
{
15
}
16
17
Shader::~Shader
()
18
{
19
this->_gl_program.
DropProgram
( &this->
cm
);
20
}
21
22
Instance
*
Shader::instance
()
const
23
{
24
return
this->inst;
25
}
26
27
void
Shader::status
(
iv::TableDebugView
* view )
28
{
29
static
iv::TableId
DebugTable =
TableId::create
(
"Shader"
);
30
31
auto
row = view->
Table
( DebugTable ).
Row
(
this
);
32
33
row.
Column
(
"filename"
, this->_src_path );
34
}
35
36
void
Shader::LoadProgram
()
37
{
38
ResourcePath
vert_path = this->_src_path +
".gl.vert"
;
39
ResourcePath
frag_path = this->_src_path +
".gl.frag"
;
40
41
this->_gl_program.
CreateProgram
( &this->
cm
);
42
43
DataStream_Resource
vert_data( this->
instance
(), vert_path );
44
vert_data->with_stream(
45
[&]( std::istream & in )
46
{
47
this->_gl_program.
Load_VertexShader
( &this->
cm
, in );
48
}
49
);
50
51
DataStream_Resource
frag_data( this->
instance
(), frag_path );
52
frag_data->with_stream(
53
[&]( std::istream & in )
54
{
55
this->_gl_program.
Load_FragmentShader
( &this->
cm
, in );
56
}
57
);
58
}
59
60
void
Shader::BindAttribute
( GLuint location,
const
char
* attrib_name )
61
{
62
this->_gl_program.
BindAttribute
( &this->
cm
, location, attrib_name );
63
}
64
65
void
Shader::PositionAttributeName
(
const
char
* name )
66
{
67
this->_gl_program.
PositionAttributeName
( &this->
cm
, name );
68
}
69
70
void
Shader::LinkProgram
()
71
{
72
this->_gl_program.
LinkProgram
( &this->
cm
);
73
}
74
75
void
Shader::UnloadProgram
()
76
{
77
this->_gl_program.
DestroyProgram
( &this->
cm
);
78
}
79
80
void
Shader::DropProgram
()
81
{
82
this->_gl_program.
DropProgram
( &this->
cm
);
83
}
84
85
GLint
Shader::GetUniformLocation
(
const
char
* name )
const
86
{
87
auto
result = this->_gl_program.
GetUniformLocation
( name );
88
if
( result == (GLint)-1 )
89
this->
cm
.
warning
(
SRC_INFO
,
"Uniform '"
, name,
"' not found."
);
90
return
result;
91
}
92
93
GlProgram
const
*
Shader::gl_program
()
const
94
{
95
return
&this->_gl_program;
96
}
97
98
}