Prepares the mapping for application (builds its GPU programs).
601 DebugAssertion::check(input.
getNumberOfChannels() == 4,
"4-channel input texture handler expected");
602 DebugAssertion::check(output.
getNumberOfChannels() == 4,
"4-channel output texture handler expected");
611 InvalidArgument::check(isPlainOutput || isPackedOutput,
"Output vector height does not match matrix height");
638 static const unsigned int PRECISION_BOOST = 1;
644 varying highp vec2 texCoord;
653 code.line(
"void main() {");
656 if (!fixedPointStorage) {
658 code.printf(
"highp mat4 m = mat4("
659 "texture2D(%s, texCoord),"
660 "texture2D(%s, vec2(texCoord.x+%s[0], texCoord.y)),"
661 "texture2D(%s, vec2(texCoord.x+%s[1], texCoord.y)),"
662 "texture2D(%s, vec2(texCoord.x+%s[2], texCoord.y)));",
671 code.printf(
"highp vec4 m1 = unpack(texture2D(%s, texCoord), texture2D(%s, vec2(texCoord.x+%s[0], texCoord.y)));",
673 code.printf(
"highp vec4 m2 = unpack(texture2D(%s, vec2(texCoord.x+%s[1], texCoord.y)), texture2D(%s, vec2(texCoord.x+%s[2], texCoord.y)));",
684 code(
"highp vec4 v = unpackIn(vec4(vp1.xz, vp2.xz), vec4(vp1.yw, vp2.yw));");
691 if (fixedPointStorage)
692 code.line(
"highp vec2 r = vec2(dot(m1, v), dot(m2, v));");
694 code.line(
"highp vec4 r = m * v;");
700 code.printf(
"highp float x = texCoord.x + %s[3];",
UNIFORM_DELTA);
706 if (!fixedPointStorage)
708 code.printf(
"m = mat4("
709 "texture2D(%s, vec2(x, texCoord.y)),"
710 "texture2D(%s, vec2(x+%s[0], texCoord.y)),"
711 "texture2D(%s, vec2(x+%s[1], texCoord.y)),"
712 "texture2D(%s, vec2(x+%s[2], texCoord.y)));",
720 code.printf(
"m1 = unpack(texture2D(%s, vec2(x, texCoord.y)), texture2D(%s, vec2(x+%s[0], texCoord.y)));",
722 code.printf(
"m2 = unpack(texture2D(%s, vec2(x+%s[1], texCoord.y)), texture2D(%s, vec2(x+%s[2], texCoord.y)));",
733 code(
"v = unpackIn(vec4(vp1.xz, vp2.xz), vec4(vp1.yw, vp2.yw));");
740 if (fixedPointStorage)
741 code.line(
"r += vec2(dot(m1, v), dot(m2, v));");
743 code.line(
"r += m * v;");
747 if (fixedPointStorage)
748 code(
"gl_FragColor = vec4(pack(r.x), pack(r.y));");
750 code.line(
"gl_FragColor = r;");
777 bool isLastIteration =
false;
780 while (!isLastIteration) {
782 const int inBufIdx = iterNum % 2;
785 const int inBufWidth = outBufWidth;
787 isLastIteration = (outBufWidth == 1);
789 DebugAssertion::check(outBufWidth > 0,
"non-positive outBufWidth");
793 if (iterNum == 0 && !isLastIteration) {
801 for (
size_t i = 0; i < deltas.size(); ++i)
806 const int ySamplesNum = (isLastIteration && fixedPointStorage && !
fixed16Output) ? 2 : 1;
812 IntPoint(outBufWidth, bufHeightPix / ySamplesNum)
822 varying highp vec2 texCoord;
829 code.line(
"void main() {");
830 if (!fixedPointStorage) {
831 code(
"gl_FragColor = ");
842 code.printf(
"lowp vec4 i = texture2D(%s, texCoord);",
UNIFORM_MATRIX);
843 code.printf(
"highp vec2 s = ");
849 code(
"vec2(unpack(i[0], i[1]), unpack(i[2], i[3]));");
851 code(
"gl_FragColor = vec4(pack(s.x), pack(s.y));");
862 if (fixedPointStorage ||
bias) {
864 varying highp vec2 texCoord;
877 code.line(
"void main() {");
879 code.line(
"highp vec2 b;");
882 if (!fixedPointStorage) {
886 code(
"gl_FragColor = ");
908 code.printf(
"lowp vec4 i = texture2D(%s, texCoord);",
UNIFORM_MATRIX);
919 code(i == 0 ?
"highp vec2 s = " :
"s += ");
920 code.line(
"vec2(unpack(i[0], i[1]), unpack(i[2], i[3]));");
922 code(i == 0 ?
"highp vec2 s2 = " :
"s2 += ");
923 code.line(
"vec2(unpack(i2[0], i2[1]), unpack(i2[2], i2[3]));");
933 code.line(
"b = vec2(unpackBias(i[0], i[1]), unpackBias(i[2], i[3]));");
936 code.line(
"s += b;");
939 code.line(
"b = vec2(unpackBias(i2[0], i2[1]), unpackBias(i2[2], i2[3]));");
942 code.line(
"s2 += b;");
946 code(
"gl_FragColor = ");
948 code(
"vec4(pack(s.x), pack(s.y))");
std::vector< std::array< float, SUM_STAGE_STEPS > > sumStageDelta
static const int MULT_STAGE_STEPS
number of 4*4 blocks processed at the multiplication stage
std::vector< Beatmup::Rectangle > sumStageTexCoords
Beatmup::Rectangle multStageTexCoords
std::array< float, 4 > multStageDelta
void release(GraphicPipeline &gpu, GL::RenderingProgram *program)
Marks a program as unused any more.
GLSL program to render images Makes use of default vertex attributes to pass the texture coordinates ...
const int getNumberOfChannels() const
Returns number of channels containing in the texture.
virtual const int getHeight() const =0
Height of the texture in pixels.
float getMappingOffset() const
Provides the constant offset added to the vector values sent to GPU.
float getMappingScale() const
Provides the scale factor applied to the vector values sent to GPU.
Exception thrown when an implementation restriction is encountered.
static void check(const bool condition, const std::string &message)
StringBuilder including a string container.
int getMatrixWidth() const
int getMatrixHeight() const
const int getWidth() const
Width of the texture in pixels.
const int getHeight() const
Height of the texture in pixels.
static void declareGlsl16bitFixedPointFunctions(StringBuilder &code, const char *suffix, bool pack, bool unpackVec, bool unpackScalar, unsigned int packPrecision=8, unsigned int unpackPrecision=8)
Generates GLSL code of float to 16-bit fixed point packing/unpacking functions.
static const char * UNIFORM_MATRIX
static const int VECTOR_MAIN_DIM
static const char * UNIFORM_DELTA
static const char * UNIFORM_BIAS
static bool useFixedPointStorage(bool forceFixed16Storage)
static const int VECTOR_TEXTURE_DIMS
void sampleVectorComponent(String &code, const char *declaration, const char *variable, const char *uniform, const char *coordinate, int delta=-1)
static const char * UNIFORM_INPUT
@ BEATMUP_DIALECT
pseudo-extension enabling Beatmup GLSL dialect
CustomPoint< int > IntPoint
CustomRectangle< float > Rectangle
#define BEATMUP_SHADER_CODE(...)
#define ceili(x, y)
integer division x/y with ceiling
return bitmap getHeight()