Option 1 for fixing android 4.4
Reinit vertex attribute pointer each time, performance may hurt
This commit is contained in:
parent
7b185ce2f1
commit
8653d410f8
@ -6,11 +6,11 @@ uniform vec2 texsize;
|
|||||||
#ifdef Explicit_Attrib_Location_Usable
|
#ifdef Explicit_Attrib_Location_Usable
|
||||||
layout(location=0) in vec2 Position;
|
layout(location=0) in vec2 Position;
|
||||||
layout(location=3) in vec2 Texcoord;
|
layout(location=3) in vec2 Texcoord;
|
||||||
layout(location=2) in uvec4 Color;
|
layout(location=2) in vec4 Color;
|
||||||
#else
|
#else
|
||||||
in vec2 Position;
|
in vec2 Position;
|
||||||
in vec2 Texcoord;
|
in vec2 Texcoord;
|
||||||
in uvec4 Color;
|
in vec4 Color;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out vec2 uv;
|
out vec2 uv;
|
||||||
@ -18,7 +18,7 @@ out vec4 col;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
col = vec4(Color) / 255.;
|
col = Color.zyxw;
|
||||||
uv = Texcoord * texsize + texcenter;
|
uv = Texcoord * texsize + texcenter;
|
||||||
gl_Position = vec4(Position * size + center, 0., 1.);
|
gl_Position = vec4(Position * size + center, 0., 1.);
|
||||||
}
|
}
|
||||||
|
@ -93,41 +93,12 @@ class ColoredTextureRectShader : public TextureShader<ColoredTextureRectShader,
|
|||||||
core::vector2df, core::vector2df,
|
core::vector2df, core::vector2df,
|
||||||
core::vector2df, core::vector2df>
|
core::vector2df, core::vector2df>
|
||||||
{
|
{
|
||||||
#ifdef XX
|
|
||||||
private:
|
|
||||||
GLuint m_quad_buffer;
|
|
||||||
|
|
||||||
void initQuadBuffer()
|
|
||||||
{
|
|
||||||
const float quad_vertex[] = { -1., -1., -1., 1., // UpperLeft
|
|
||||||
-1., 1., -1., -1., // LowerLeft
|
|
||||||
1., -1., 1., 1., // UpperRight
|
|
||||||
1., 1., 1., -1. }; // LowerRight
|
|
||||||
glGenBuffers(1, &m_quad_buffer);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex,
|
|
||||||
GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &SharedObject::UIVAO);
|
|
||||||
glBindVertexArray(SharedObject::UIVAO);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glEnableVertexAttribArray(3);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
|
||||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
|
||||||
(GLvoid *)(2 * sizeof(float)));
|
|
||||||
glBindVertexArray(0);
|
|
||||||
} // initQuadBuffer
|
|
||||||
#endif
|
|
||||||
public:
|
public:
|
||||||
GLuint m_color_vbo;
|
GLuint m_color_vbo;
|
||||||
GLuint m_vao;
|
GLuint m_vao;
|
||||||
|
|
||||||
ColoredTextureRectShader()
|
ColoredTextureRectShader()
|
||||||
{
|
{
|
||||||
#ifdef XX
|
|
||||||
initQuadBuffer();
|
|
||||||
#endif
|
|
||||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert",
|
loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert",
|
||||||
GL_FRAGMENT_SHADER, "colortexturedquad.frag");
|
GL_FRAGMENT_SHADER, "colortexturedquad.frag");
|
||||||
assignUniforms("center", "size", "texcenter", "texsize");
|
assignUniforms("center", "size", "texcenter", "texsize");
|
||||||
@ -143,16 +114,15 @@ public:
|
|||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
||||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||||
(GLvoid *)(2 * sizeof(float)));
|
(GLvoid *)(2 * sizeof(float)));
|
||||||
const unsigned quad_color[] = { 0, 0, 0, 255,
|
glBindVertexArray(0);
|
||||||
|
const uint8_t quad_color[] = { 0, 0, 0, 255,
|
||||||
255, 0, 0, 255,
|
255, 0, 0, 255,
|
||||||
0, 255, 0, 255,
|
0, 255, 0, 255,
|
||||||
0, 0, 255, 255 };
|
0, 0, 255, 255 };
|
||||||
glGenBuffers(1, &m_color_vbo);
|
glGenBuffers(1, &m_color_vbo);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_color_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_color_vbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color,
|
glBufferData(GL_ARRAY_BUFFER, 16, quad_color, GL_DYNAMIC_DRAW);
|
||||||
GL_DYNAMIC_DRAW);
|
|
||||||
glVertexAttribIPointer(2, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
} // ColoredTextureRectShader
|
} // ColoredTextureRectShader
|
||||||
}; // ColoredTextureRectShader
|
}; // ColoredTextureRectShader
|
||||||
|
|
||||||
@ -164,16 +134,11 @@ static void drawTexColoredQuad(const video::ITexture *texture,
|
|||||||
float tex_center_pos_y, float tex_width,
|
float tex_center_pos_y, float tex_width,
|
||||||
float tex_height)
|
float tex_height)
|
||||||
{
|
{
|
||||||
unsigned colors[] = {
|
glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao);
|
||||||
col[0].getRed(), col[0].getGreen(), col[0].getBlue(), col[0].getAlpha(),
|
|
||||||
col[1].getRed(), col[1].getGreen(), col[1].getBlue(), col[1].getAlpha(),
|
|
||||||
col[2].getRed(), col[2].getGreen(), col[2].getBlue(), col[2].getAlpha(),
|
|
||||||
col[3].getRed(), col[3].getGreen(), col[3].getBlue(), col[3].getAlpha(),
|
|
||||||
};
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER,
|
glBindBuffer(GL_ARRAY_BUFFER,
|
||||||
ColoredTextureRectShader::getInstance()->m_color_vbo);
|
ColoredTextureRectShader::getInstance()->m_color_vbo);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(unsigned), colors);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, 16, col);
|
||||||
|
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, 4 , 0);
|
||||||
|
|
||||||
ColoredTextureRectShader::getInstance()->use();
|
ColoredTextureRectShader::getInstance()->use();
|
||||||
glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao);
|
glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao);
|
||||||
@ -186,8 +151,9 @@ static void drawTexColoredQuad(const video::ITexture *texture,
|
|||||||
core::vector2df(tex_width, tex_height));
|
core::vector2df(tex_width, tex_height));
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
glGetError();
|
glGetError();
|
||||||
} // drawTexColoredQuad
|
} // drawTexColoredQuad
|
||||||
|
Loading…
x
Reference in New Issue
Block a user