@@ -1,8 +1,8 @@ | |||
add_library(libcygnet SHARED | |||
src/shaders/basic.cc | |||
src/Context.cc | |||
src/Program.cc | |||
src/Renderer.cc | |||
src/shaders.cc | |||
src/Window.cc) | |||
target_include_directories(libcygnet | |||
PUBLIC "include" |
@@ -2,10 +2,10 @@ | |||
namespace Cygnet::Shaders { | |||
extern const char *texturedQuadVx; | |||
extern const char *texturedFr; | |||
extern const char *basicVx; | |||
extern const char *texturedVx; | |||
extern const char *coloredQuadVx; | |||
extern const char *coloredFr; | |||
extern const char *solidColorFr; | |||
extern const char *texturedFr; | |||
} |
@@ -6,7 +6,7 @@ | |||
namespace Cygnet { | |||
struct TexturedQuad: public GlProgram { | |||
struct TexturedProg: public GlProgram { | |||
using GlProgram::GlProgram; | |||
GlLoc position = attribLoc("position"); | |||
@@ -14,7 +14,7 @@ struct TexturedQuad: public GlProgram { | |||
GlLoc tex = uniformLoc("tex"); | |||
}; | |||
struct ColoredQuad: public GlProgram { | |||
struct SolidColorProg: public GlProgram { | |||
using GlProgram::GlProgram; | |||
GlLoc position = attribLoc("position"); | |||
@@ -22,13 +22,13 @@ struct ColoredQuad: public GlProgram { | |||
}; | |||
struct RendererState { | |||
GlVxShader texturedQuadVx{Shaders::texturedQuadVx}; | |||
GlVxShader basicVx{Shaders::basicVx}; | |||
GlVxShader texturedVx{Shaders::texturedVx}; | |||
GlFrShader solidColorFr{Shaders::solidColorFr}; | |||
GlFrShader texturedFr{Shaders::texturedFr}; | |||
GlVxShader coloredQuadVx{Shaders::texturedQuadVx}; | |||
GlFrShader coloredFr{Shaders::texturedFr}; | |||
TexturedQuad texturedQuad{texturedQuadVx, texturedFr}; | |||
ColoredQuad coloredQuad{coloredQuadVx, coloredFr}; | |||
TexturedProg texturedProg{texturedVx, texturedFr}; | |||
SolidColorProg solidColorProg{basicVx, solidColorFr}; | |||
}; | |||
Renderer::Renderer(): state_(std::make_unique<RendererState>()) {} |
@@ -2,37 +2,28 @@ | |||
namespace Cygnet::Shaders { | |||
const char *texturedQuadVx = R"glsl( | |||
const char *basicVx = R"glsl( | |||
uniform mat3 transform; | |||
attribute vec2 position; | |||
attribute vec2 texCoord; | |||
varying vec2 v_texCoord; | |||
void main() { | |||
vec3 pos = transform * vec3(position, 0); | |||
gl_Position = vec4(pos.x, pos.y, 0, 1); | |||
v_texCoord = texCoord; | |||
} | |||
)glsl"; | |||
const char *texturedFr = R"glsl( | |||
precision mediump float; | |||
varying vec2 v_texCoord; | |||
uniform sampler2D tex; | |||
void main() { | |||
gl_FragColor = texture2D(tex, v_texCoord); | |||
} | |||
)glsl"; | |||
const char *coloredQuadVx = R"glsl( | |||
const char *texturedVx = R"glsl( | |||
uniform mat3 transform; | |||
attribute vec2 position; | |||
attribute vec2 texCoord; | |||
varying vec2 v_texCoord; | |||
void main() { | |||
vec3 pos = transform * vec3(position, 0); | |||
gl_Position = vec4(pos.x, pos.y, 0, 1); | |||
v_texCoord = texCoord; | |||
} | |||
)glsl"; | |||
const char *coloredFr = R"glsl( | |||
const char *solidColorFr = R"glsl( | |||
precision mediump float; | |||
uniform vec4 color; | |||
void main() { | |||
@@ -40,4 +31,13 @@ const char *coloredFr = R"glsl( | |||
} | |||
)glsl"; | |||
const char *texturedFr = R"glsl( | |||
precision mediump float; | |||
varying vec2 v_texCoord; | |||
uniform sampler2D tex; | |||
void main() { | |||
gl_FragColor = texture2D(tex, v_texCoord); | |||
} | |||
)glsl"; | |||
} |