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