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