2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-06-13 22:08:01 +00:00
|
|
|
#include "GLUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-10-13 06:12:58 +00:00
|
|
|
#include "RasterFont.h"
|
2012-12-27 23:52:44 +00:00
|
|
|
#include "PixelShaderCache.h"
|
|
|
|
#include "ProgramShaderCache.h"
|
|
|
|
#include "VertexShaderCache.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
|
|
|
|
|
|
|
static const u32 char_width = 8;
|
|
|
|
static const u32 char_height = 13;
|
|
|
|
static const u32 char_offset = 32;
|
|
|
|
static const u32 char_count = 95;
|
|
|
|
|
|
|
|
const u8 rasters[char_count][char_height] = {
|
2008-12-08 05:25:12 +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,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 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
|
|
|
|
{0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
|
|
|
|
{0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
|
|
|
|
{0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
|
|
|
|
{0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 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, 0xc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x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xc0, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x03, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x00, 0x00, 0xfe, 0x03, 0x03, 0x7e, 0xc0, 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}
|
|
|
|
};
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
static const char *s_vertexShaderSrc =
|
2012-12-28 10:46:00 +00:00
|
|
|
"#version 130\n"
|
|
|
|
"uniform vec2 charSize;\n"
|
2013-01-11 10:59:42 +00:00
|
|
|
"in vec2 vposition;\n"
|
|
|
|
"in vec2 texture0;\n"
|
|
|
|
"out vec2 uv0;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"void main(void) {\n"
|
2013-01-11 10:59:42 +00:00
|
|
|
" gl_Position = vec4(vposition,0,1);\n"
|
|
|
|
" uv0 = texture0 * charSize;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"}\n";
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
static const char *s_fragmentShaderSrc =
|
2012-12-28 10:46:00 +00:00
|
|
|
"#version 130\n"
|
|
|
|
"uniform sampler2D samp0;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"uniform vec4 color;\n"
|
2013-01-11 10:59:42 +00:00
|
|
|
"in vec2 uv0;\n"
|
2012-12-28 10:46:00 +00:00
|
|
|
"out vec4 ocol0;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"void main(void) {\n"
|
2013-01-11 10:59:42 +00:00
|
|
|
" ocol0 = texture2D(samp0,uv0) * color;\n"
|
2012-12-11 21:08:53 +00:00
|
|
|
"}\n";
|
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
|
|
|
|
static FRAGMENTSHADER s_fragmentShader;
|
|
|
|
static VERTEXSHADER s_vertexShader;
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
RasterFont::RasterFont()
|
|
|
|
{
|
2012-12-11 11:37:08 +00:00
|
|
|
// generate the texture
|
|
|
|
glGenTextures(1, &texture);
|
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];
|
|
|
|
for(u32 y=0; y<char_height; y++) {
|
|
|
|
for(u32 c=0; c<char_count; c++) {
|
|
|
|
for(u32 x=0; x<char_width; x++) {
|
|
|
|
bool pixel = rasters[c][y] & (1<<(char_width-x-1));
|
|
|
|
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 16:33:59 +00:00
|
|
|
}
|
2012-12-28 10:46:00 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
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;
|
|
|
|
|
2012-12-11 21:08:53 +00:00
|
|
|
// generate shader
|
2012-12-27 23:52:44 +00:00
|
|
|
VertexShaderCache::CompileVertexShader(s_vertexShader, s_vertexShaderSrc);
|
|
|
|
PixelShaderCache::CompilePixelShader(s_fragmentShader, s_fragmentShaderSrc);
|
|
|
|
ProgramShaderCache::SetBothShaders(s_fragmentShader.glprogid, s_vertexShader.glprogid);
|
|
|
|
GLuint shader_program = ProgramShaderCache::GetCurrentProgram();
|
2012-12-11 21:08:53 +00:00
|
|
|
|
|
|
|
// bound uniforms
|
2012-12-28 10:46:00 +00:00
|
|
|
glUniform2f(glGetUniformLocation(shader_program,"charSize"), 1.0f / GLfloat(char_count), 1.0f);
|
2012-12-11 21:08:53 +00:00
|
|
|
uniform_color_id = glGetUniformLocation(shader_program,"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;
|
2012-12-13 14:48:42 +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);
|
|
|
|
glVertexAttribPointer(SHADER_POSITION_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, NULL);
|
|
|
|
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
|
|
|
|
glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2);
|
2012-12-25 11:22:02 +00:00
|
|
|
|
2012-12-13 14:48:42 +00:00
|
|
|
// TODO: this after merging with graphic_update
|
|
|
|
glBindVertexArray(0);
|
2012-12-29 11:50:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
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);
|
2012-12-27 23:52:44 +00:00
|
|
|
s_fragmentShader.Destroy();
|
|
|
|
s_vertexShader.Destroy();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-12-28 10:46:00 +00:00
|
|
|
size_t length = strlen(text);
|
2012-12-11 11:37:08 +00:00
|
|
|
|
|
|
|
glBindVertexArray(VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, length*4*6*sizeof(GLfloat), NULL, GL_STREAM_DRAW);
|
|
|
|
GLfloat *vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
|
|
|
|
|
|
|
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);
|
|
|
|
GLfloat border_x = 2.0/GLfloat(bbWidth);
|
|
|
|
GLfloat border_y = 4.0/GLfloat(bbHeight);
|
2012-12-11 11:37:08 +00:00
|
|
|
|
2012-12-28 10:46:00 +00:00
|
|
|
GLfloat x = GLfloat(start_x);
|
|
|
|
GLfloat y = GLfloat(start_y);
|
2012-12-11 11:37:08 +00:00
|
|
|
|
2012-12-28 10:46:00 +00:00
|
|
|
for(size_t i=0; i<length; i++) {
|
2012-12-11 11:37:08 +00:00
|
|
|
u8 c = text[i];
|
|
|
|
|
|
|
|
if(c == '\n') {
|
2009-02-28 16:33:59 +00:00
|
|
|
x = start_x;
|
2012-12-11 11:37:08 +00:00
|
|
|
y -= delta_y + border_y;
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2012-12-11 11:37:08 +00:00
|
|
|
|
|
|
|
// do not print spaces, they can be skipped easyly
|
|
|
|
if(c == ' ') {
|
|
|
|
x += delta_x + border_x;
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2012-12-11 11:37:08 +00:00
|
|
|
|
|
|
|
if(c < char_offset || c >= char_count+char_offset) continue;
|
|
|
|
|
|
|
|
vertices[usage++] = x;
|
|
|
|
vertices[usage++] = y;
|
2012-12-28 10:46:00 +00:00
|
|
|
vertices[usage++] = GLfloat(c-char_offset);
|
|
|
|
vertices[usage++] = 0.0f;
|
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;
|
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;
|
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;
|
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;
|
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;
|
2012-12-11 11:37:08 +00:00
|
|
|
|
|
|
|
x += delta_x + border_x;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2012-12-11 11:37:08 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
2009-02-28 16:33:59 +00:00
|
|
|
|
2012-12-27 23:52:44 +00:00
|
|
|
ProgramShaderCache::SetBothShaders(s_fragmentShader.glprogid, s_vertexShader.glprogid);
|
2012-12-11 21:08:53 +00:00
|
|
|
|
|
|
|
if(color != cached_color) {
|
2013-01-07 19:11:26 +00:00
|
|
|
glUniform4f(uniform_color_id, GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>16)&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
|
|
|
}
|
2012-12-11 21:08:53 +00:00
|
|
|
|
2012-12-11 11:37:08 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2012-12-28 10:46:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2012-12-11 11:37:08 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, usage/4);
|
2012-12-11 21:08:53 +00:00
|
|
|
|
2012-12-13 14:48:42 +00:00
|
|
|
// TODO: this after merging with graphic_update
|
|
|
|
glBindVertexArray(0);
|
2012-12-29 11:50:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2012-12-13 14:48:42 +00:00
|
|
|
|
2012-12-11 21:08:53 +00:00
|
|
|
glUseProgram(0);
|
2008-08-24 21:50:41 +00:00
|
|
|
}
|
2012-12-27 23:52:44 +00:00
|
|
|
|
2013-01-07 19:11:26 +00:00
|
|
|
}
|