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
void allocate()
Allocate a shader program handle.
Definition: GLUtil.cc:245
Wrapper around an OpenGL fragment shader: a program executed on the GPU that computes the colors of p...
Definition: GLUtil.hh:380
void activate() const
Makes this program the active shader program.
Definition: GLUtil.cc:312
GLuint unifFillMvp
Definition: GLContext.hh:39
mat4 pixelMvp
Definition: GLContext.hh:44
Wrapper around an OpenGL vertex shader: a program executed on the GPU that computes per-vertex stuff...
Definition: GLUtil.hh:367
void attach(const Shader &shader)
Adds a given shader to this program.
Definition: GLUtil.cc:267
GLint getUniformLocation(const char *name) const
Gets a reference to a uniform variable declared in the shader source.
Definition: GLUtil.cc:304
std::unique_ptr< Context > context
Definition: GLContext.cc:9
GLuint unifTexMvp
Definition: GLContext.hh:30
void bindAttribLocation(unsigned index, const char *name)
Bind the given name for a vertex shader attribute to the given location.
Definition: GLUtil.cc:299
ShaderProgram progFill
Definition: GLContext.hh:38
void link()
Links all attached shaders together into one program.
Definition: GLUtil.cc:279
Abstract base class for OpenGL scalers.
Definition: GLScaler.hh:13
openmsx::GLScaler & getFallbackScaler()
Definition: GLContext.cc:42
GLuint unifTexColor
Definition: GLContext.hh:29
mat4 ortho(float left, float right, float bottom, float top, float nearVal, float farVal)
ShaderProgram progTex
Definition: GLContext.hh:28
Definition: gl_mat.hh:24
Context(int width, int height)
Initialize global openGL state.
Definition: GLContext.cc:11