21 xytheta = std::vector<float>(sizeHint*xythetaDim+padSprites*xythetaDim,0.0f);
22 scale = std::vector<float>(sizeHint*scaleDim+padSprites*scaleDim,0.0f);
23 textureRegion = std::vector<float>(sizeHint*textureRegionDim+padSprites*textureRegionDim,0.0f);
24 textureOptions = std::vector<float>(sizeHint*textureOptionsDim+padSprites*textureOptionsDim,0.0f);
26 shader = std::make_shared<glShader>(vertexShader, fragmentShader);
39 std::shared_ptr<Shader>
shader,
40 std::vector<std::pair<Info, Sprite>> & sprites
43 GLuint vao, a_position, a_xytheta, a_scale, a_textureRegion, a_textureOption;
48 0.5f, 0.5f, 1.0f, 1.0f,
49 0.5f, -0.5f, 1.0f, 0.0f,
50 -0.5f, -0.5f, 0.0f, 0.0f,
51 -0.5f, 0.5f, 0.0f, 1.0f,
52 -0.5f, -0.5f, 0.0f, 0.0f,
53 0.5f, 0.5f, 1.0f, 1.0f
56 std::vector<float> xytheta;
57 size_t xythetaDim = 3;
58 size_t xythetaAttribute = 1;
60 std::vector<float> scale;
62 size_t scaleAttribute = 2;
64 std::vector<float> textureRegion;
65 size_t textureRegionDim = 4;
66 size_t textureRegionAttribute = 3;
68 std::vector<float> textureOptions;
69 size_t textureOptionsDim = 2;
70 size_t textureOptionsAttribute = 4;
72 size_t padSprites = 8;
77 const char * vertexShader =
78 "#version " GLSL_VERSION
"\n"
79 "precision lowp float; precision lowp int;\n"
80 "layout(location=0) in vec4 a_position;\n"
81 "layout(location=1) in vec3 a_xytheta;\n"
82 "layout(location=2) in vec2 a_scale;\n"
83 "layout(location=3) in vec4 a_textureOffset;\n"
84 "layout(location=4) in vec2 a_textureOptions;\n"
85 "uniform mat4 proj;\n"
86 "out vec2 texCoord;\n"
87 "flat out float alpha;\n"
90 "vec2 pos = a_position.xy*a_scale;\n"
91 "float ct = cos(a_xytheta.z); float st = sin(a_xytheta.z);\n"
92 "mat2 rot = mat2(ct, -st, st, ct);\n"
93 "pos = rot*pos + a_xytheta.xy;\n"
94 "gl_Position = proj*vec4(pos,0.0,1.0);\n"
95 "texCoord.x = (a_position.z * a_textureOffset.z)+a_textureOffset.x;\n"
96 "texCoord.y = (a_position.w * a_textureOffset.w)+a_textureOffset.y;\n"
97 "tex = int(a_textureOptions.x);\n"
98 "alpha = a_textureOptions.y;\n"
101 const char * fragmentShader =
102 "#version " GLSL_VERSION
"\n"
103 "precision lowp float; precision lowp int;\n"
104 "uniform sampler2D sampler0;\n"
105 "uniform sampler2D sampler1;\n"
106 "uniform sampler2D sampler2;\n"
107 "uniform sampler2D sampler3;\n"
108 "in vec2 texCoord;\n"
109 "flat in float alpha;\n"
111 "layout(location=0) out vec4 colour;\n"
114 "if (tex == 0) {colour = texture(sampler0, texCoord);}\n"
115 "else if (tex == 1) {colour = texture(sampler1, texCoord);}\n"
116 "else if (tex == 2) {colour = texture(sampler2, texCoord);}\n"
117 "else if (tex == 3) {colour = texture(sampler3, texCoord);}\n"
118 "else {colour = vec4(0.0,0.0,0.0,alpha);}\n"
119 "colour.a = colour.a*alpha;\n"