| 1 |
#include "GLContext.hh" |
| 2 |
|
| 3 |
#include "GLDefaultScaler.hh" |
| 4 |
#include "gl_transform.hh" |
| 5 |
|
| 6 |
#include <memory> |
| 7 |
|
| 8 |
namespace gl { |
| 9 |
|
| 10 |
|
| 11 |
std::optional<Context> context; |
| 12 |
|
| 13 |
Context::Context() |
| 14 |
{ |
| 15 |
VertexShader texVertexShader ("texture.vert"); |
| 16 |
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(); |
| 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.attach(fillVertexShader); |
| 30 |
progFill.attach(fillFragmentShader); |
| 31 |
progFill.bindAttribLocation(0, "a_position"); |
| 32 |
progFill.bindAttribLocation(1, "a_color"); |
| 33 |
progFill.link(); |
| 34 |
progFill.activate(); |
| 35 |
unifFillMvp = progFill.getUniformLocation("u_mvpMatrix"); |
| 36 |
} |
| 37 |
|
| 38 |
Context::~Context() = default; |
| 39 |
|
| 40 |
openmsx::GLScaler& Context::getFallbackScaler() |
| 41 |
{ |
| 42 |
if (!fallbackScaler) { |
| 43 |
fallbackScaler = std::make_unique<openmsx::GLDefaultScaler>(); |
| 44 |
} |
| 45 |
return *fallbackScaler; |
| 46 |
} |
| 47 |
|
| 48 |
void Context::setupMvpMatrix(gl::vec2 logicalSize) |
| 49 |
{ |
| 50 |
pixelMvp = ortho(logicalSize.x, logicalSize.y); |
| 51 |
} |
| 52 |
|
| 53 |
} |