Precompute g3_draw_line GL color data
This commit is contained in:
parent
e54338ce4e
commit
4fd412b2ea
|
@ -25,6 +25,29 @@ namespace dcx {
|
|||
|
||||
tmap_drawer_type tmap_drawer_ptr = draw_tmap;
|
||||
|
||||
#if DXX_USE_OGL
|
||||
namespace {
|
||||
|
||||
const std::array<GLfloat, 8> build_color_array_from_color_palette_index(const color_palette_index color)
|
||||
{
|
||||
auto &&rgb = PAL2T(color);
|
||||
const GLfloat color_r = rgb.r / 63.0;
|
||||
const GLfloat color_g = rgb.g / 63.0;
|
||||
const GLfloat color_b = rgb.b / 63.0;
|
||||
return {{
|
||||
color_r, color_g, color_b, 1.0,
|
||||
color_r, color_g, color_b, 1.0,
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
g3_draw_line_colors::g3_draw_line_colors(const color_palette_index color) :
|
||||
color_array(build_color_array_from_color_palette_index(color))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
//specifies 2d drawing routines to use instead of defaults. Passing
|
||||
//NULL for either or both restores defaults
|
||||
void g3_set_special_render(tmap_drawer_type tmap_drawer)
|
||||
|
|
|
@ -34,6 +34,10 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "fwd-gr.h"
|
||||
#include <array>
|
||||
|
||||
#if DXX_USE_OGL
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#if DXX_USE_EDITOR
|
||||
namespace dcx {
|
||||
extern int g3d_interp_outline; //if on, polygon models outlined in white
|
||||
|
@ -275,12 +279,26 @@ void g3_draw_rod_tmap(grs_canvas &, grs_bitmap &bitmap, const g3s_point &bot_poi
|
|||
//returns 1 if off screen, 0 if drew
|
||||
void g3_draw_bitmap(grs_canvas &, const vms_vector &pos, fix width, fix height, grs_bitmap &bm);
|
||||
|
||||
#if DXX_USE_OGL
|
||||
struct g3_draw_line_colors
|
||||
{
|
||||
const std::array<GLfloat, 8> color_array;
|
||||
g3_draw_line_colors(color_palette_index color);
|
||||
};
|
||||
#endif
|
||||
|
||||
class g3_draw_line_context
|
||||
#if DXX_USE_OGL
|
||||
: public g3_draw_line_colors
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
grs_canvas &canvas;
|
||||
const color_palette_index color;
|
||||
g3_draw_line_context(grs_canvas &canvas, color_palette_index color) :
|
||||
#if DXX_USE_OGL
|
||||
g3_draw_line_colors(color),
|
||||
#endif
|
||||
canvas(canvas), color(color)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -552,26 +552,15 @@ namespace dcx {
|
|||
|
||||
void g3_draw_line(const g3_draw_line_context &context, const g3s_point &p0, const g3s_point &p1)
|
||||
{
|
||||
GLfloat color_r, color_g, color_b;
|
||||
GLfloat color_array[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
|
||||
|
||||
ogl_client_states<int, GL_VERTEX_ARRAY, GL_COLOR_ARRAY> cs;
|
||||
OGL_DISABLE(TEXTURE_2D);
|
||||
glDisable(GL_CULL_FACE);
|
||||
const auto c = context.color;
|
||||
color_r = PAL2Tr(c);
|
||||
color_g = PAL2Tg(c);
|
||||
color_b = PAL2Tb(c);
|
||||
color_array[0] = color_array[4] = color_r;
|
||||
color_array[1] = color_array[5] = color_g;
|
||||
color_array[2] = color_array[6] = color_b;
|
||||
color_array[3] = color_array[7] = 1.0;
|
||||
std::array<GLfloat, 6> vertices = {{
|
||||
f2glf(p0.p3_vec.x), f2glf(p0.p3_vec.y), -f2glf(p0.p3_vec.z),
|
||||
f2glf(p1.p3_vec.x), f2glf(p1.p3_vec.y), -f2glf(p1.p3_vec.z)
|
||||
}};
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertices.data());
|
||||
glColorPointer(4, GL_FLOAT, 0, color_array);
|
||||
glColorPointer(4, GL_FLOAT, 0, context.color_array.data());
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue