openMSX
video
GLContext.cc
Go to the documentation of this file.
1
#include "
GLContext.hh
"
2
#include "
GLDefaultScaler.hh
"
3
#include "
gl_transform.hh
"
4
#include "
narrow.hh
"
5
#include <memory>
6
7
namespace
gl
{
8
9
// Global variables
10
std::optional<Context>
context
;
11
12
Context::Context
()
13
{
14
VertexShader
texVertexShader (
"texture.vert"
);
15
FragmentShader
texFragmentShader(
"texture.frag"
);
16
progTex
.
allocate
();
17
progTex
.
attach
(texVertexShader);
18
progTex
.
attach
(texFragmentShader);
19
progTex
.
bindAttribLocation
(0,
"a_position"
);
20
progTex
.
bindAttribLocation
(1,
"a_texCoord"
);
21
progTex
.
link
();
22
progTex
.
activate
();
23
glUniform1i(
progTex
.
getUniformLocation
(
"u_tex"
), 0);
24
unifTexColor
=
progTex
.
getUniformLocation
(
"u_color"
);
25
unifTexMvp
=
progTex
.
getUniformLocation
(
"u_mvpMatrix"
);
26
27
VertexShader
fillVertexShader (
"fill.vert"
);
28
FragmentShader
fillFragmentShader(
"fill.frag"
);
29
progFill
.
allocate
();
30
progFill
.
attach
(fillVertexShader);
31
progFill
.
attach
(fillFragmentShader);
32
progFill
.
bindAttribLocation
(0,
"a_position"
);
33
progFill
.
bindAttribLocation
(1,
"a_color"
);
34
progFill
.
link
();
35
progFill
.
activate
();
36
unifFillMvp
=
progFill
.
getUniformLocation
(
"u_mvpMatrix"
);
37
}
38
39
Context::~Context
() =
default
;
40
41
openmsx::GLScaler
&
Context::getFallbackScaler
()
42
{
43
if
(!fallbackScaler) {
44
fallbackScaler = std::make_unique<openmsx::GLDefaultScaler>();
45
}
46
return
*fallbackScaler;
47
}
48
49
void
Context::setupMvpMatrix
(
gl::vec2
logicalSize)
50
{
51
pixelMvp
=
ortho
(logicalSize.x, logicalSize.y);
52
}
53
54
}
// namespace gl
GLContext.hh
GLDefaultScaler.hh
gl::FragmentShader
Wrapper around an OpenGL fragment shader: a program executed on the GPU that computes the colors of p...
Definition
GLUtil.hh:384
gl::ShaderProgram::activate
void activate() const
Makes this program the active shader program.
Definition
GLUtil.cc:283
gl::ShaderProgram::attach
void attach(const Shader &shader)
Adds a given shader to this program.
Definition
GLUtil.cc:238
gl::ShaderProgram::allocate
void allocate()
Allocate a shader program handle.
Definition
GLUtil.cc:213
gl::ShaderProgram::link
void link()
Links all attached shaders together into one program.
Definition
GLUtil.cc:250
gl::ShaderProgram::bindAttribLocation
void bindAttribLocation(unsigned index, const char *name)
Bind the given name for a vertex shader attribute to the given location.
Definition
GLUtil.cc:270
gl::ShaderProgram::getUniformLocation
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition
GLUtil.cc:275
gl::VertexShader
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff.
Definition
GLUtil.hh:369
gl::vecN
Definition
gl_vec.hh:32
openmsx::GLScaler
Abstract base class for OpenGL scalers.
Definition
GLScaler.hh:16
gl_transform.hh
gl
Definition
gl_mat.hh:23
gl::ortho
constexpr mat4 ortho(float left, float right, float bottom, float top, float nearVal, float farVal)
Definition
gl_transform.hh:169
gl::context
std::optional< Context > context
Definition
GLContext.cc:10
narrow.hh
gl::Context::Context
Context()
Initialize global openGL state.
Definition
GLContext.cc:12
gl::Context::progFill
ShaderProgram progFill
Definition
GLContext.hh:39
gl::Context::unifTexColor
GLint unifTexColor
Definition
GLContext.hh:30
gl::Context::setupMvpMatrix
void setupMvpMatrix(gl::vec2 logicalSize)
Definition
GLContext.cc:49
gl::Context::unifTexMvp
GLint unifTexMvp
Definition
GLContext.hh:31
gl::Context::progTex
ShaderProgram progTex
Definition
GLContext.hh:29
gl::Context::~Context
~Context()
gl::Context::pixelMvp
mat4 pixelMvp
Definition
GLContext.hh:45
gl::Context::getFallbackScaler
openmsx::GLScaler & getFallbackScaler()
Definition
GLContext.cc:41
gl::Context::unifFillMvp
GLint unifFillMvp
Definition
GLContext.hh:40
Generated on Mon Oct 7 2024 21:13:41 for openMSX by
1.9.8