2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/OGL/GLUtil.h"
|
|
|
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
|
|
|
#include "VideoBackends/OGL/RasterFont.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// globals
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
namespace OGL {
|
2012-12-11 11:37:08 +00:00
|
|
|
|
2014-03-17 07:50:59 +00:00
|
|
|
static const int char_width = 8;
|
|
|
|
static const int char_height = 13;
|
|
|
|
static const int char_offset = 32;
|
|
|
|
static const int char_count = 95;
|
2012-12-11 11:37:08 +00:00
|
|
|
|
|
|
|
const u8 rasters[char_count][char_height] = {
|
2013-10-29 05:23:17 +00:00
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
|
|
|
|
{0x00, 0x00, 0x00, 0x66, 0x66, 0xff, 0x66, 0x66, 0xff, 0x66, 0x66, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x18, 0x7e, 0xff, 0x1b, 0x1f, 0x7e, 0xf8, 0xd8, 0xff, 0x7e, 0x18},
|
|
|
|
{0x00, 0x00, 0x0e, 0x1b, 0xdb, 0x6e, 0x30, 0x18, 0x0c, 0x76, 0xdb, 0xd8, 0x70},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc6, 0xcf, 0xd8, 0x70, 0x70, 0xd8, 0xcc, 0xcc, 0x6c, 0x38},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1c, 0x0c, 0x0e},
|
|
|
|
{0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c},
|
|
|
|
{0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x99, 0x5a, 0x3c, 0xff, 0x3c, 0x5a, 0x99, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x60, 0x60, 0x30, 0x30, 0x18, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x03, 0x03},
|
|
|
|
{0x00, 0x00, 0x3c, 0x66, 0xc3, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xc3, 0x66, 0x3c},
|
|
|
|
{0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x38, 0x18},
|
|
|
|
{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0x07, 0x03, 0x03, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xff, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x03, 0x03, 0xff},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x03, 0x7f, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
|
|
|
|
{0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60},
|
|
|
|
{0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x06, 0x03, 0xc3, 0xc3, 0x7e},
|
|
|
|
{0x00, 0x00, 0x3f, 0x60, 0xcf, 0xdb, 0xd3, 0xdd, 0xc3, 0x7e, 0x00, 0x00, 0x00},
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66, 0x66, 0xc3},
|
|
|
|
{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff},
|
|
|
|
{0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c},
|
|
|
|
{0x00, 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60},
|
|
|
|
{0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18},
|
|
|
|
{0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x70},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc3, 0xc3, 0x7f, 0x03, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
|
|
|
|
{0x00, 0x00, 0x7e, 0xc3, 0xc0, 0xc0, 0xc0, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x03, 0x03, 0x03, 0x03, 0x03},
|
|
|
|
{0x00, 0x00, 0x7f, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30,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xc0, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x00},
|
|
|
|
{0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xc3, 0xe7, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xc0, 0x60, 0x60, 0x30, 0x18, 0x3c, 0x66, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xff, 0x60, 0x30, 0x18, 0x0c, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0x0f, 0x18, 0x18, 0x18, 0x38, 0xf0, 0x38, 0x18, 0x18, 0x18, 0x0f},
|
|
|
|
{0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
|
|
|
|
{0x00, 0x00, 0xf0, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0xf0},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00}
|
2008-12-08 05:25:12 +00:00
|
|
|
};
|
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
static const char *s_vertexShaderSrc =
|
2012-12-28 10:46:00 +00:00
|
|
|
"uniform vec2 charSize;\n"
|
2014-02-25 14:52:22 +00:00
|
|
|
"in vec2 rawpos;\n"
|
|
|
|
"in vec2 tex0;\n"
|
|
|
|
"out vec2 uv0;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"void main(void) {\n"
|
2013-01-11 20:24:59 +00:00
|
|
|
" gl_Position = vec4(rawpos,0,1);\n"
|
2013-01-14 21:59:08 +00:00
|
|
|
" uv0 = tex0 * charSize;\n"
|
2013-10-29 05:23:17 +00:00
|
|
|
"}\n";
|
2012-12-11 21:08:53 +00:00
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
static const char *s_fragmentShaderSrc =
|
2014-06-07 05:29:21 +00:00
|
|
|
"SAMPLER_BINDING(8) uniform sampler2D samp8;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"uniform vec4 color;\n"
|
2014-02-25 14:52:22 +00:00
|
|
|
"in vec2 uv0;\n"
|
2013-11-25 00:06:29 +00:00
|
|
|
"out vec4 ocol0;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"void main(void) {\n"
|
2013-01-19 10:07:06 +00:00
|
|
|
" ocol0 = texture(samp8,uv0) * color;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"}\n";
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
static SHADER s_shader;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
RasterFont::RasterFont()
|
|
|
|
{
|
2012-12-11 11:37:08 +00:00
|
|
|
// generate the texture
|
|
|
|
glGenTextures(1, &texture);
|
2013-01-18 23:39:31 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0+8);
|
2012-12-28 10:46:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2012-12-11 11:37:08 +00:00
|
|
|
u32* texture_data = new u32[char_width*char_count*char_height];
|
2014-03-17 07:50:59 +00:00
|
|
|
for (int y = 0; y < char_height; y++)
|
2014-03-12 19:33:41 +00:00
|
|
|
{
|
2014-03-17 07:50:59 +00:00
|
|
|
for (int c = 0; c < char_count; c++)
|
2014-03-12 19:33:41 +00:00
|
|
|
{
|
2014-03-17 07:50:59 +00:00
|
|
|
for (int x = 0; x < char_width; x++)
|
2014-03-12 19:33:41 +00:00
|
|
|
{
|
2013-11-14 07:19:15 +00:00
|
|
|
bool pixel = (0 != (rasters[c][y] & (1<<(char_width-x-1))));
|
2012-12-11 11:37:08 +00:00
|
|
|
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 16:33:59 +00:00
|
|
|
}
|
2013-07-13 22:24:23 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
2012-12-28 10:46:00 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, char_width*char_count, char_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
|
2012-12-11 11:37:08 +00:00
|
|
|
delete [] texture_data;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 21:08:53 +00:00
|
|
|
// generate shader
|
2013-02-13 12:12:19 +00:00
|
|
|
ProgramShaderCache::CompileShader(s_shader, s_vertexShaderSrc, s_fragmentShaderSrc);
|
2014-07-31 17:03:18 +00:00
|
|
|
s_shader.Bind();
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 21:08:53 +00:00
|
|
|
// bound uniforms
|
2013-02-13 12:12:19 +00:00
|
|
|
glUniform2f(glGetUniformLocation(s_shader.glprogid,"charSize"), 1.0f / GLfloat(char_count), 1.0f);
|
|
|
|
uniform_color_id = glGetUniformLocation(s_shader.glprogid,"color");
|
2012-12-28 10:46:00 +00:00
|
|
|
glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f);
|
2012-12-11 21:08:53 +00:00
|
|
|
cached_color = -1;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-25 11:22:02 +00:00
|
|
|
// generate VBO & VAO
|
|
|
|
glGenBuffers(1, &VBO);
|
|
|
|
glGenVertexArrays(1, &VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
|
|
glBindVertexArray(VAO);
|
2013-01-11 10:59:42 +00:00
|
|
|
glEnableVertexAttribArray(SHADER_POSITION_ATTRIB);
|
2014-03-09 20:14:26 +00:00
|
|
|
glVertexAttribPointer(SHADER_POSITION_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, nullptr);
|
2013-01-11 10:59:42 +00:00
|
|
|
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
|
2014-03-09 20:14:26 +00:00
|
|
|
glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)nullptr+2);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RasterFont::~RasterFont()
|
|
|
|
{
|
2012-12-11 11:37:08 +00:00
|
|
|
glDeleteTextures(1, &texture);
|
|
|
|
glDeleteBuffers(1, &VBO);
|
|
|
|
glDeleteVertexArrays(1, &VAO);
|
2013-02-13 12:12:19 +00:00
|
|
|
s_shader.Destroy();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
void RasterFont::printMultilineText(const std::string& text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-03-12 19:33:41 +00:00
|
|
|
GLfloat* vertices = new GLfloat[text.length() * 6 * 4];
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
int usage = 0;
|
2012-12-28 10:46:00 +00:00
|
|
|
GLfloat delta_x = GLfloat(2*char_width)/GLfloat(bbWidth);
|
|
|
|
GLfloat delta_y = GLfloat(2*char_height)/GLfloat(bbHeight);
|
2013-08-30 04:43:21 +00:00
|
|
|
GLfloat border_x = 2.0f/GLfloat(bbWidth);
|
|
|
|
GLfloat border_y = 4.0f/GLfloat(bbHeight);
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-28 10:46:00 +00:00
|
|
|
GLfloat x = GLfloat(start_x);
|
|
|
|
GLfloat y = GLfloat(start_y);
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
for (const char& c : text)
|
|
|
|
{
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
2013-08-30 04:43:21 +00:00
|
|
|
x = GLfloat(start_x);
|
2012-12-11 11:37:08 +00:00
|
|
|
y -= delta_y + border_y;
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2013-04-19 13:21:45 +00:00
|
|
|
// do not print spaces, they can be skipped easily
|
2014-03-12 19:33:41 +00:00
|
|
|
if (c == ' ')
|
|
|
|
{
|
2012-12-11 11:37:08 +00:00
|
|
|
x += delta_x + border_x;
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2014-03-28 03:55:30 +00:00
|
|
|
if ((u32) c < char_offset || (u32) c >= char_count+char_offset)
|
2014-03-12 19:33:41 +00:00
|
|
|
continue;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 0.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x+delta_x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset+1);
|
|
|
|
vertices[usage++] = 0.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x+delta_x;
|
|
|
|
vertices[usage++] = y+delta_y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset+1);
|
|
|
|
vertices[usage++] = 1.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 0.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x+delta_x;
|
|
|
|
vertices[usage++] = y+delta_y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset+1);
|
|
|
|
vertices[usage++] = 1.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y+delta_y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 1.0f;
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
x += delta_x + border_x;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
if (!usage)
|
|
|
|
{
|
2013-01-31 10:30:44 +00:00
|
|
|
delete [] vertices;
|
|
|
|
return;
|
|
|
|
}
|
2013-04-15 20:28:55 +00:00
|
|
|
|
2013-01-31 10:30:44 +00:00
|
|
|
glBindVertexArray(VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, usage*sizeof(GLfloat), vertices, GL_STREAM_DRAW);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-01-31 10:30:44 +00:00
|
|
|
delete [] vertices;
|
2009-02-28 16:33:59 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
s_shader.Bind();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
if (color != cached_color)
|
|
|
|
{
|
2013-01-15 11:25:06 +00:00
|
|
|
glUniform4f(uniform_color_id, GLfloat((color>>16)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>24)&0xff)/255.f);
|
2012-12-11 21:08:53 +00:00
|
|
|
cached_color = color;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-01-18 23:39:31 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0+8);
|
2012-12-11 11:37:08 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, usage/4);
|
2008-08-24 21:50:41 +00:00
|
|
|
}
|
2012-12-27 23:52:44 +00:00
|
|
|
|
2013-01-07 19:11:26 +00:00
|
|
|
}
|