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 <memory>
5 
6 namespace gl {
7 
8 // Global variables
9 std::unique_ptr<Context> context;
10 
11 Context::Context(int width, int height)
12 {
13  VertexShader texVertexShader ("texture.vert");
14  FragmentShader texFragmentShader("texture.frag");
15  progTex.allocate();
16  progTex.attach(texVertexShader);
17  progTex.attach(texFragmentShader);
18  progTex.bindAttribLocation(0, "a_position");
19  progTex.bindAttribLocation(1, "a_texCoord");
20  progTex.link();
21  progTex.activate();
22  glUniform1i(progTex.getUniformLocation("u_tex"), 0);
24  unifTexMvp = progTex.getUniformLocation("u_mvpMatrix");
25 
26  VertexShader fillVertexShader ("fill.vert");
27  FragmentShader fillFragmentShader("fill.frag");
29  progFill.attach(fillVertexShader);
30  progFill.attach(fillFragmentShader);
31  progFill.bindAttribLocation(0, "a_position");
32  progFill.bindAttribLocation(1, "a_color");
33  progFill.link();
35  unifFillMvp = progFill.getUniformLocation("u_mvpMatrix");
36 
37  pixelMvp = ortho(0, width, height, 0, -1, 1);
38 }
39 
40 Context::~Context() = default;
41 
43 {
44  if (!fallbackScaler) {
45  fallbackScaler = std::make_unique<openmsx::GLDefaultScaler>();
46  }
47  return *fallbackScaler;
48 }
49 
50 } // namespace gl
gl::ortho
mat4 ortho(float left, float right, float bottom, float top, float nearVal, float farVal)
Definition: gl_transform.hh:169
gl::VertexShader
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff.
Definition: GLUtil.hh:353
gl::Context::unifTexMvp
GLuint unifTexMvp
Definition: GLContext.hh:30
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:285
gl_transform.hh
gl::Context::progFill
ShaderProgram progFill
Definition: GLContext.hh:38
gl::ShaderProgram::activate
void activate() const
Makes this program the active shader program.
Definition: GLUtil.cc:298
gl::Context::Context
Context(int width, int height)
Initialize global openGL state.
Definition: GLContext.cc:11
gl
Definition: gl_mat.hh:24
gl::Context::pixelMvp
mat4 pixelMvp
Definition: GLContext.hh:44
gl::ShaderProgram::getUniformLocation
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition: GLUtil.cc:290
gl::Context::progTex
ShaderProgram progTex
Definition: GLContext.hh:28
gl::Context::getFallbackScaler
openmsx::GLScaler & getFallbackScaler()
Definition: GLContext.cc:42
gl::ShaderProgram::allocate
void allocate()
Allocate a shader program handle.
Definition: GLUtil.cc:231
gl::context
std::unique_ptr< Context > context
Definition: GLContext.cc:9
gl::ShaderProgram::attach
void attach(const Shader &shader)
Adds a given shader to this program.
Definition: GLUtil.cc:253
gl::Context::unifFillMvp
GLuint unifFillMvp
Definition: GLContext.hh:39
openmsx::GLScaler
Abstract base class for OpenGL scalers.
Definition: GLScaler.hh:14
gl::ShaderProgram::link
void link()
Links all attached shaders together into one program.
Definition: GLUtil.cc:265
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:366
gl::Context::~Context
~Context()
GLContext.hh
gl::Context::unifTexColor
GLuint unifTexColor
Definition: GLContext.hh:29