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
(
int
width,
int
height)
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
pixelMvp
=
ortho
(0.0f, narrow_cast<float>(width),
39
narrow_cast<float>(height), 0.0f,
40
-1.0f, 1.0f);
41
}
42
43
Context::~Context
() =
default
;
44
45
openmsx::GLScaler
&
Context::getFallbackScaler
()
46
{
47
if
(!fallbackScaler) {
48
fallbackScaler = std::make_unique<openmsx::GLDefaultScaler>();
49
}
50
return
*fallbackScaler;
51
}
52
53
}
// 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:372
gl::ShaderProgram::activate
void activate() const
Makes this program the active shader program.
Definition:
GLUtil.cc:265
gl::ShaderProgram::attach
void attach(const Shader &shader)
Adds a given shader to this program.
Definition:
GLUtil.cc:220
gl::ShaderProgram::allocate
void allocate()
Allocate a shader program handle.
Definition:
GLUtil.cc:198
gl::ShaderProgram::link
void link()
Links all attached shaders together into one program.
Definition:
GLUtil.cc:232
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:252
gl::ShaderProgram::getUniformLocation
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition:
GLUtil.cc:257
gl::VertexShader
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff.
Definition:
GLUtil.hh:357
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::progFill
ShaderProgram progFill
Definition:
GLContext.hh:39
gl::Context::unifTexColor
GLint unifTexColor
Definition:
GLContext.hh:30
gl::Context::unifTexMvp
GLint unifTexMvp
Definition:
GLContext.hh:31
gl::Context::Context
Context(int width, int height)
Initialize global openGL state.
Definition:
GLContext.cc:12
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:45
gl::Context::unifFillMvp
GLint unifFillMvp
Definition:
GLContext.hh:40
Generated on Wed Sep 27 2023 14:13:12 for openMSX by
1.9.4