21 #include "../gpu/bgl.h"
42 attribute vec2 inVertex;
43 attribute vec2 inTexCoord;
44 uniform mat3 modelview;
45 uniform
bool flipVertically;
46 varying vec2 texCoord;
49 gl_Position = vec4(modelview * vec3(inVertex, 1), 1);
50 gl_Position.x = gl_Position.x * 2.0 - 1.0;
52 gl_Position.y = gl_Position.y * 2.0 - 1.0;
54 gl_Position.y = 1.0 - gl_Position.y * 2.0;
55 texCoord = inTexCoord;
61 attribute vec2 inVertex;
62 attribute vec2 inTexCoord;
63 uniform mat3 modelview;
64 uniform
bool flipVertically;
65 uniform mat3 maskMapping;
66 uniform mat3 invImgMapping;
67 varying vec2 texCoord;
68 varying vec2 maskCoord;
71 gl_Position = vec4(modelview * maskMapping * vec3(inVertex, 1), 1);
72 gl_Position.x = gl_Position.x * 2.0 - 1.0;
74 gl_Position.y = gl_Position.y * 2.0 - 1.0;
76 gl_Position.y = 1.0 - gl_Position.y * 2.0;
77 texCoord = (invImgMapping * vec3(inVertex, 1)).
xy;
78 maskCoord = inTexCoord;
84 uniform beatmupSampler image;
85 uniform mediump vec4 modulationColor;
86 varying mediump vec2 texCoord;
88 gl_FragColor = beatmupTexture(image, texCoord.xy).rgba * modulationColor;
94 uniform beatmupSampler image;
95 uniform highp sampler2D mask;
96 uniform highp sampler2D maskLookup;
97 uniform highp
float blockSize;
98 uniform highp
float pixOffset;
99 uniform mediump vec4 modulationColor;
100 uniform mediump vec4 bgColor;
101 varying mediump vec2 texCoord;
102 varying highp vec2 maskCoord;
104 #ifdef BEATMUP_OPENGLVERSION_GLES20
107 highp
float o = mod(maskCoord.x, blockSize);
109 if (texCoord.x >= 0.0 && texCoord.y >= 0.0 && texCoord.x < 1.0 && texCoord.y < 1.0)
112 vec2(texture2D(mask, vec2(maskCoord.x - o + pixOffset, maskCoord.y)).a, o / blockSize + 0.03125)
114 gl_FragColor = mix(bgColor, beatmupTexture(image, texCoord.xy).rgba,
a) * modulationColor;
120 highp
float o = mod(maskCoord.x, blockSize);
122 if (texCoord.x >= 0.0 && texCoord.y >= 0.0 && texCoord.x < 1.0 && texCoord.y < 1.0)
125 vec2(texture2D(mask, vec2(maskCoord.x - o + pixOffset, maskCoord.y)).r, o / blockSize + 0.03125)
127 gl_FragColor = mix(bgColor, beatmupTexture(image, texCoord.xy).rgba,
a) * modulationColor;
134 uniform beatmupSampler image;
135 uniform highp sampler2D mask;
136 uniform mediump vec4 modulationColor;
137 uniform mediump vec4 bgColor;
138 varying mediump vec2 texCoord;
139 varying highp vec2 maskCoord;
141 #ifdef BEATMUP_OPENGLVERSION_GLES20
145 if (texCoord.x >= 0.0 && texCoord.y >= 0.0 && texCoord.x < 1.0 && texCoord.y < 1.0)
146 a = texture2D(mask, maskCoord).a;
147 gl_FragColor = mix(bgColor, beatmupTexture(image, texCoord.xy).rgba,
a) * modulationColor;
154 if (texCoord.x >= 0.0 && texCoord.y >= 0.0 && texCoord.x < 1.0 && texCoord.y < 1.0)
155 a = texture2D(mask, maskCoord).r;
156 gl_FragColor = mix(bgColor, beatmupTexture(image, texCoord.xy).rgba,
a) * modulationColor;
163 uniform beatmupSampler image;
164 varying mediump vec2 texCoord;
165 varying mediump vec2 maskCoord;
166 uniform highp vec2 borderProfile;
167 uniform highp
float slope;
168 uniform highp
float border;
169 uniform highp
float cornerRadius;
170 uniform mediump vec4 modulationColor;
171 uniform mediump vec4 bgColor;
174 highp vec2 cornerCoords = vec2(cornerRadius -
min(maskCoord.x, 1.0 - maskCoord.x) * borderProfile.x, cornerRadius -
min(maskCoord.y, 1.0 - maskCoord.y) * borderProfile.y);
176 if (cornerRadius > 0.0 && cornerCoords.x > 0.0 && cornerCoords.y > 0.0)
177 r = length(cornerCoords / cornerRadius) * cornerRadius;
179 r =
max(cornerCoords.x, cornerCoords.y);
180 if (texCoord.x < 0.0 || texCoord.y < 0.0 || texCoord.x >= 1.0 || texCoord.y >= 1.0)
181 gl_FragColor = bgColor;
183 gl_FragColor = beatmupTexture(image, texCoord.xy).rgba;
184 gl_FragColor = gl_FragColor * clamp((cornerRadius - border -
r) / (slope + 0.00098), 0.0, 1.0) * modulationColor;
208 unsigned char mask1[8][256], mask2[4][256], mask4[2][256];
209 for (
int v = 0;
v < 256; ++
v) {
210 for (
int o = 0; o < 8; ++o)
211 mask1[o][
v] = ((
v >> o) % 2) * 255;
212 for (
int o = 0; o < 4; ++o)
213 mask2[o][
v] = (
int)((
v >> (2 * o)) % 4) * 255 / 3;
214 for (
int o = 0; o < 2; ++o)
215 mask4[o][
v] = (
int)((
v >> (4 * o)) % 16) * 255 / 15;
218 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
220 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 256, 8, 0, GL_ALPHA, GL_UNSIGNED_BYTE, mask1);
222 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 256, 4, 0, GL_ALPHA, GL_UNSIGNED_BYTE, mask2);
224 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 256, 2, 0, GL_ALPHA, GL_UNSIGNED_BYTE, mask4);
239 throw GLException(
"Mask bitmap pixel format is not supported");
241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
261 auto it = map.find(operation);
266 std::string fragmentCode;
304 std::piecewise_construct,
305 std::forward_as_tuple(operation),
306 std::forward_as_tuple(*gpu, *vertexShader, fragmentShader)
308 if (!useDefaultVertexShader)
356 DebugAssertion::check(
maskSetUp,
"Mask was not set up in masked blending");
360 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
370 switch (
content.getTextureFormat()) {
371 case TextureHandler::TextureFormat::OES_Ext:
388 blend(output ==
nullptr);
A very basic class for any image.
virtual const PixelFormat getPixelFormat() const =0
Pixel format of the bitmap.
const unsigned char getBitsPerPixel() const
Returns number of bits per pixel stored in each bitmap.
static const AffineMapping IDENTITY
static const CustomRectangle UNIT_SQUARE
void setInteger(const std::string &name, const int value, bool safe=false)
Assigns a value to a specific integer variable in the program.
void enable(const GraphicPipeline &gpu)
void setFloat(const std::string &name, const float value, bool safe=false)
Assigns a value to a specific floating point variable in the program.
void setVector4(const std::string &name, const float x, const float y, const float z, const float w)
void setMatrix3(const std::string &name, const Matrix2 &mat, const Point &pos)
static void check(const std::string &info)
static const char * TEXTURE_COORD_ATTRIB_NAME
texture coordinate attribute name in vertex shaders
Program & getCurrentProgram()
void paveBackground(GraphicPipeline *gpu, TextureHandler &content, GL::TextureHandler *output)
Fills background with a repeated texture taking 1 pixel of this texture per 1 pixel of the output.
Program * currentGlProgram
Program & getProgram(const GraphicPipeline *gpu, Operation program)
std::map< Operation, RenderingProgram > programs
void enableProgram(GraphicPipeline *gpu, Operation program)
Select and enable a common program.
static const char * TEXTURE_COORDINATES_ID
Texture coordinates shader variable name in vertex shader.
Operation
Standard rendering operations.
@ MASKED_BLEND_EXT
blending an image through a pixelwise mask (texture extension)
@ MASKED_8BIT_BLEND_EXT
blending an image through a 8 bit pixelwise mask (texture extension)
@ SHAPED_BLEND
shaping an image
@ BLEND_EXT
default blending using a texture extension
@ MASKED_8BIT_BLEND
blending an image through a 8 bit pixelwise mask
@ MASKED_BLEND
blending an image through a pixelwise mask
@ SHAPED_BLEND_EXT
shaping an image (texture extension)
@ BLEND
default blending of a single image
static const char * VERTEX_COORD_ATTRIB_NAME
vertex coordinate attribute name in vertex shaders
static const char * VERTICAL_FLIP_ID
Vertical flipping variable name in vertex shader.
const VertexShader & getDefaultVertexShader(const GraphicPipeline *gpu) const
VertexShader defaultVertexShader
static const char * DECLARE_TEXTURE_COORDINATES_IN_FRAG
Declaring texture coordinates in fragment shader.
static const char * MODELVIEW_MATRIX_ID
Modelview matrix (mapping input geometry to output) shader variable name in vertex shader.
void blend(bool onScreen)
Performs the blending operation.
RenderingPrograms(GraphicPipeline *gpu)
void bindMask(GraphicPipeline *gpu, AbstractBitmap &mask)
Binds a mask to a masked rendering program.
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const int getWidth() const =0
Width of the texture in pixels.
Internal low-level GPU control API.
const ImageResolution & getDisplayResolution() const
void setTextureCoordinates(const Rectangle &coords)
Specifies texture coordinates for the next rendering pass.
void bind(GL::TextureHandler &texture, size_t texUnit, const TextureParam param)
unsigned int getWidth() const
unsigned int getHeight() const
static void insanity(const char *message)
GLuint hMaskLookups[3]
texture containing mask values for 1, 2 and 4 bpp
void bindMaskLookup(PixelFormat format)
Extensions
Supported OpenGL estensions.
@ BEATMUP_DIALECT
pseudo-extension enabling Beatmup GLSL dialect
@ EXTERNAL_TEXTURE
GL_OES_EGL_image_external_essl3 if available or GL_OES_EGL_image_external.
@ QuaternaryMask
2 bits per pixel
@ BinaryMask
1 bit per pixel
@ HexMask
4 bits per pixel
CustomRectangle< float > Rectangle
@ INTERP_NEAREST
nearest neighbor pixel interpolation
@ REPEAT
wrapping the texture by repeating instead of clamping to edge
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
#define BEATMUP_SHADER_CODE(...)
static const char * VERTEX_SHADER_BLEND
static const char * VERTEX_SHADER_BLENDMASK
static const char * FRAGMENT_SHADER_BLENDMASK
static const char * FRAGMENT_SHADER_BLENDSHAPE
static const char * FRAGMENT_SHADER_BLENDMASK_8BIT
static const char * FRAGMENT_SHADER_BLEND
JNIEnv jobject jint format
jobject jlong jint jint jint r
jobject jlong jint jint jint jint jint jint a
JNIEnv jlong jfloat jfloat jfloat v