2017-02-07 11:20:15 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
*
|
|
|
|
* 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; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file draw_cache.c
|
|
|
|
* \ingroup draw
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_mesh_types.h"
|
2017-04-21 17:58:18 +10:00
|
|
|
#include "DNA_curve_types.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
#include "DNA_object_types.h"
|
2017-05-09 16:23:47 +02:00
|
|
|
#include "DNA_particle_types.h"
|
2017-06-22 19:19:55 +02:00
|
|
|
#include "DNA_modifier_types.h"
|
2017-06-27 15:59:13 +02:00
|
|
|
#include "DNA_lattice_types.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
|
|
#include "GPU_batch.h"
|
|
|
|
|
|
|
|
#include "draw_cache.h"
|
2017-04-21 21:14:11 +10:00
|
|
|
#include "draw_cache_impl.h"
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-02-22 18:52:07 +01:00
|
|
|
static struct DRWShapeCache {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *drw_single_vertice;
|
|
|
|
Gwn_Batch *drw_fullscreen_quad;
|
|
|
|
Gwn_Batch *drw_screenspace_circle;
|
|
|
|
Gwn_Batch *drw_plain_axes;
|
|
|
|
Gwn_Batch *drw_single_arrow;
|
|
|
|
Gwn_Batch *drw_cube;
|
|
|
|
Gwn_Batch *drw_circle;
|
|
|
|
Gwn_Batch *drw_square;
|
|
|
|
Gwn_Batch *drw_line;
|
|
|
|
Gwn_Batch *drw_line_endpoints;
|
|
|
|
Gwn_Batch *drw_empty_sphere;
|
|
|
|
Gwn_Batch *drw_empty_cone;
|
|
|
|
Gwn_Batch *drw_arrows;
|
|
|
|
Gwn_Batch *drw_axis_names;
|
|
|
|
Gwn_Batch *drw_image_plane;
|
|
|
|
Gwn_Batch *drw_image_plane_wire;
|
|
|
|
Gwn_Batch *drw_field_wind;
|
|
|
|
Gwn_Batch *drw_field_force;
|
|
|
|
Gwn_Batch *drw_field_vortex;
|
|
|
|
Gwn_Batch *drw_field_tube_limit;
|
|
|
|
Gwn_Batch *drw_field_cone_limit;
|
|
|
|
Gwn_Batch *drw_lamp;
|
|
|
|
Gwn_Batch *drw_lamp_sunrays;
|
|
|
|
Gwn_Batch *drw_lamp_area;
|
|
|
|
Gwn_Batch *drw_lamp_hemi;
|
|
|
|
Gwn_Batch *drw_lamp_spot;
|
|
|
|
Gwn_Batch *drw_lamp_spot_square;
|
|
|
|
Gwn_Batch *drw_speaker;
|
2017-06-27 14:59:53 +02:00
|
|
|
Gwn_Batch *drw_lightprobe_cube;
|
|
|
|
Gwn_Batch *drw_lightprobe_planar;
|
|
|
|
Gwn_Batch *drw_lightprobe_grid;
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *drw_bone_octahedral;
|
|
|
|
Gwn_Batch *drw_bone_octahedral_wire;
|
|
|
|
Gwn_Batch *drw_bone_box;
|
|
|
|
Gwn_Batch *drw_bone_box_wire;
|
|
|
|
Gwn_Batch *drw_bone_wire_wire;
|
|
|
|
Gwn_Batch *drw_bone_envelope;
|
|
|
|
Gwn_Batch *drw_bone_envelope_distance;
|
|
|
|
Gwn_Batch *drw_bone_envelope_wire;
|
|
|
|
Gwn_Batch *drw_bone_envelope_head_wire;
|
|
|
|
Gwn_Batch *drw_bone_point;
|
|
|
|
Gwn_Batch *drw_bone_point_wire;
|
|
|
|
Gwn_Batch *drw_bone_arrows;
|
|
|
|
Gwn_Batch *drw_camera;
|
|
|
|
Gwn_Batch *drw_camera_tria;
|
|
|
|
Gwn_Batch *drw_camera_focus;
|
|
|
|
Gwn_Batch *drw_particle_cross;
|
|
|
|
Gwn_Batch *drw_particle_circle;
|
|
|
|
Gwn_Batch *drw_particle_axis;
|
2017-02-07 11:20:15 +01:00
|
|
|
} SHC = {NULL};
|
|
|
|
|
|
|
|
void DRW_shape_cache_free(void)
|
|
|
|
{
|
2017-04-13 13:30:53 +10:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_single_vertice);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_fullscreen_quad);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_plain_axes);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_single_arrow);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_cube);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_circle);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_square);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_line);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_line_endpoints);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_empty_sphere);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_empty_cone);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_arrows);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_axis_names);
|
2017-05-20 22:57:47 +10:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_image_plane);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_image_plane_wire);
|
2017-04-13 13:30:53 +10:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_field_wind);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_field_force);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_field_vortex);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_field_tube_limit);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_field_cone_limit);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_sunrays);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_area);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_hemi);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_spot);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_spot_square);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_speaker);
|
2017-06-27 14:59:53 +02:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lightprobe_cube);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lightprobe_planar);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_lightprobe_grid);
|
2017-04-13 13:30:53 +10:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_octahedral);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_octahedral_wire);
|
2017-05-03 08:34:24 +02:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_box);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_box_wire);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_wire_wire);
|
2017-05-18 11:41:59 +02:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_envelope);
|
2017-05-17 12:34:06 +02:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_envelope_distance);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_envelope_wire);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_envelope_head_wire);
|
2017-04-13 13:30:53 +10:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_point);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_point_wire);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_arrows);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_camera);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_camera_tria);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_camera_focus);
|
2017-05-19 17:13:48 +02:00
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_particle_cross);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_particle_circle);
|
|
|
|
BATCH_DISCARD_ALL_SAFE(SHC.drw_particle_axis);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Helper functions
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
static void add_fancy_edge(
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo, unsigned int pos_id, unsigned int n1_id, unsigned int n2_id,
|
2017-04-15 14:24:30 +10:00
|
|
|
unsigned int *v_idx, const float co1[3], const float co2[3],
|
|
|
|
const float n1[3], const float n2[3])
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, n1_id, *v_idx, n1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, n2_id, *v_idx, n2);
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++, co1);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, n1_id, *v_idx, n1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, n2_id, *v_idx, n2);
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++, co2);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
static void add_lat_lon_vert(
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo, unsigned int pos_id, unsigned int nor_id,
|
2017-04-15 14:24:30 +10:00
|
|
|
unsigned int *v_idx, const float rad, const float lat, const float lon)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
float pos[3], nor[3];
|
|
|
|
nor[0] = sinf(lat) * cosf(lon);
|
|
|
|
nor[1] = cosf(lat);
|
|
|
|
nor[2] = sinf(lat) * sinf(lon);
|
|
|
|
mul_v3_v3fl(pos, nor, rad);
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, nor_id, *v_idx, nor);
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++, pos);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertBuf *fill_arrows_vbo(const float scale)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-22 13:00:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Line */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 6 * 3);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
float v1[3] = {0.0, 0.0, 0.0};
|
|
|
|
float v2[3] = {0.0, 0.0, 0.0};
|
|
|
|
float vtmp1[3], vtmp2[3];
|
|
|
|
|
|
|
|
for (int axis = 0; axis < 3; axis++) {
|
|
|
|
const int arrow_axis = (axis == 0) ? 1 : 0;
|
|
|
|
|
|
|
|
v2[axis] = 1.0f;
|
|
|
|
mul_v3_v3fl(vtmp1, v1, scale);
|
|
|
|
mul_v3_v3fl(vtmp2, v2, scale);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 0, vtmp1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 1, vtmp2);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
v1[axis] = 0.85f;
|
|
|
|
v1[arrow_axis] = -0.08f;
|
|
|
|
mul_v3_v3fl(vtmp1, v1, scale);
|
|
|
|
mul_v3_v3fl(vtmp2, v2, scale);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 2, vtmp1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 3, vtmp2);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
v1[arrow_axis] = 0.08f;
|
|
|
|
mul_v3_v3fl(vtmp1, v1, scale);
|
|
|
|
mul_v3_v3fl(vtmp2, v2, scale);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 4, vtmp1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 5, vtmp2);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
/* reset v1 & v2 to zero */
|
|
|
|
v1[arrow_axis] = v1[axis] = v2[axis] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vbo;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertBuf *sphere_wire_vbo(const float rad)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
2017-06-09 01:14:39 +02:00
|
|
|
#define NSEGMENTS 32
|
2017-02-22 13:00:15 +01:00
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-22 13:00:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 2 * 3);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
/* a single ring of vertices */
|
|
|
|
float p[NSEGMENTS][2];
|
|
|
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
|
|
|
float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
|
|
|
|
p[i][0] = rad * cosf(angle);
|
|
|
|
p[i][1] = rad * sinf(angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int axis = 0; axis < 3; ++axis) {
|
|
|
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
|
|
|
for (int j = 0; j < 2; ++j) {
|
|
|
|
float cv[2], v[3];
|
|
|
|
|
2017-02-22 18:52:07 +01:00
|
|
|
cv[0] = p[(i + j) % NSEGMENTS][0];
|
|
|
|
cv[1] = p[(i + j) % NSEGMENTS][1];
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
if (axis == 0)
|
|
|
|
v[0] = cv[0], v[1] = cv[1], v[2] = 0.0f;
|
|
|
|
else if (axis == 1)
|
|
|
|
v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
|
|
|
|
else
|
|
|
|
v[0] = 0.0f, v[1] = cv[0], v[2] = cv[1];
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 2 + j + (NSEGMENTS * 2 * axis), v);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vbo;
|
|
|
|
#undef NSEGMENTS
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Quads */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_fullscreen_quad_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_fullscreen_quad) {
|
2017-05-09 21:46:04 +02:00
|
|
|
/* Use a triangle instead of a real quad */
|
|
|
|
/* https://www.slideshare.net/DevCentralAMD/vertex-shader-tricks-bill-bilodeau - slide 14 */
|
|
|
|
float pos[3][2] = {{-1.0f, -1.0f}, { 3.0f, -1.0f}, {-1.0f, 3.0f}};
|
|
|
|
float uvs[3][2] = {{ 0.0f, 0.0f}, { 2.0f, 0.0f}, { 0.0f, 2.0f}};
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-02-22 19:58:55 +01:00
|
|
|
/* Position Only 2D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, uvs; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 3);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-05-09 21:46:04 +02:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i, pos[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, uvs[i]);
|
2017-03-16 23:58:30 +01:00
|
|
|
}
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_fullscreen_quad = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_fullscreen_quad;
|
|
|
|
}
|
|
|
|
|
2017-06-14 13:45:54 +02:00
|
|
|
/* Sphere */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_sphere_get(void)
|
2017-06-14 13:45:54 +02:00
|
|
|
{
|
|
|
|
return Batch_get_sphere(2);
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Common
|
|
|
|
* \{ */
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_cube_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_cube) {
|
|
|
|
const GLfloat verts[8][3] = {
|
|
|
|
{-1.0f, -1.0f, -1.0f},
|
|
|
|
{-1.0f, -1.0f, 1.0f},
|
|
|
|
{-1.0f, 1.0f, -1.0f},
|
|
|
|
{-1.0f, 1.0f, 1.0f},
|
|
|
|
{ 1.0f, -1.0f, -1.0f},
|
|
|
|
{ 1.0f, -1.0f, 1.0f},
|
|
|
|
{ 1.0f, 1.0f, -1.0f},
|
|
|
|
{ 1.0f, 1.0f, 1.0f}
|
|
|
|
};
|
|
|
|
|
2017-02-22 18:52:07 +01:00
|
|
|
const GLubyte indices[24] = {0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 4, 5, 5, 7, 7, 6, 6, 4, 1, 5, 3, 7, 2, 6};
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 24);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 24; ++i) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i, verts[indices[i]]);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_cube = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_cube;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_circle_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_circle) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
2017-02-15 00:49:51 +01:00
|
|
|
v[2] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 2, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
2017-02-15 00:49:51 +01:00
|
|
|
v[2] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 2 + 1, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_circle = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_circle;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_square_get(void)
|
2017-03-05 05:22:40 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_square) {
|
|
|
|
float p[4][3] = {{ 1.0f, 0.0f, 1.0f},
|
|
|
|
{ 1.0f, 0.0f, -1.0f},
|
|
|
|
{-1.0f, 0.0f, -1.0f},
|
|
|
|
{-1.0f, 0.0f, 1.0f}};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-05 05:22:40 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 8);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 2, p[i % 4]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 2 + 1, p[(i+1) % 4]);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_square = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_square;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_single_line_get(void)
|
2017-02-09 17:27:01 +01:00
|
|
|
{
|
|
|
|
/* Z axis line */
|
|
|
|
if (!SHC.drw_line) {
|
|
|
|
float v1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
float v2[3] = {0.0f, 0.0f, 1.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-09 17:27:01 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-09 17:27:01 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 2);
|
2017-02-09 17:27:01 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
|
2017-02-09 17:27:01 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_line = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-09 17:27:01 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_line;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_single_line_endpoints_get(void)
|
2017-03-04 00:09:22 +01:00
|
|
|
{
|
|
|
|
/* Z axis line */
|
|
|
|
if (!SHC.drw_line_endpoints) {
|
|
|
|
float v1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
float v2[3] = {0.0f, 0.0f, 1.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-04 00:09:22 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-03-04 00:09:22 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 2);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_line_endpoints = GWN_batch_create(GWN_PRIM_POINTS, vbo, NULL);
|
2017-03-04 00:09:22 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_line_endpoints;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_screenspace_circle_get(void)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_screenspace_circle) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-04-10 22:22:37 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL + 1);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
for (int a = 0; a <= CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_screenspace_circle = GWN_batch_create(GWN_PRIM_LINE_STRIP, vbo, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_screenspace_circle;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
2017-04-21 02:18:14 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Common Object API
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_object_wire_outline_get(Object *ob)
|
2017-04-28 22:30:21 +10:00
|
|
|
{
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return DRW_cache_mesh_wire_outline_get(ob);
|
|
|
|
|
|
|
|
/* TODO, should match 'DRW_cache_object_surface_get' */
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_object_surface_get(Object *ob)
|
2017-04-21 02:18:14 +10:00
|
|
|
{
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return DRW_cache_mesh_surface_get(ob);
|
|
|
|
case OB_CURVE:
|
|
|
|
return DRW_cache_curve_surface_get(ob);
|
|
|
|
case OB_SURF:
|
|
|
|
return DRW_cache_surf_surface_get(ob);
|
|
|
|
case OB_FONT:
|
|
|
|
return DRW_cache_text_surface_get(ob);
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch **DRW_cache_object_surface_material_get(struct Object *ob)
|
2017-04-25 18:46:59 +02:00
|
|
|
{
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return DRW_cache_mesh_surface_shaded_get(ob);
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 02:18:14 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Empties
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_plain_axes_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_plain_axes) {
|
|
|
|
int axis;
|
|
|
|
float v1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
float v2[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 6);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
for (axis = 0; axis < 3; axis++) {
|
|
|
|
v1[axis] = 1.0f;
|
|
|
|
v2[axis] = -1.0f;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 2, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 2 + 1, v2);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
/* reset v1 & v2 to zero for next axis */
|
|
|
|
v1[axis] = v2[axis] = 0.0f;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_plain_axes = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_plain_axes;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_single_arrow_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
2017-02-09 17:27:01 +01:00
|
|
|
if (!SHC.drw_single_arrow) {
|
2017-02-15 00:49:51 +01:00
|
|
|
float v1[3] = {0.0f, 0.0f, 1.0f}, v2[3], v3[3];
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Square Pyramid */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 12);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
v2[0] = 0.035f; v2[1] = 0.035f;
|
|
|
|
v3[0] = -0.035f; v3[1] = 0.035f;
|
|
|
|
v2[2] = v3[2] = 0.75f;
|
|
|
|
|
|
|
|
for (int sides = 0; sides < 4; sides++) {
|
|
|
|
if (sides % 2 == 1) {
|
|
|
|
v2[0] = -v2[0];
|
|
|
|
v3[1] = -v3[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
v2[1] = -v2[1];
|
|
|
|
v3[0] = -v3[0];
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, sides * 3 + 0, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, sides * 3 + 1, v2);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, sides * 3 + 2, v3);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_single_arrow = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_single_arrow;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_empty_sphere_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_empty_sphere) {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = sphere_wire_vbo(1.0f);
|
|
|
|
SHC.drw_empty_sphere = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_empty_sphere;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_empty_cone_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
#define NSEGMENTS 8
|
|
|
|
if (!SHC.drw_empty_cone) {
|
|
|
|
/* a single ring of vertices */
|
|
|
|
float p[NSEGMENTS][2];
|
|
|
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
|
|
|
float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
|
|
|
|
p[i][0] = cosf(angle);
|
|
|
|
p[i][1] = sinf(angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 4);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
|
|
|
float cv[2], v[3];
|
|
|
|
cv[0] = p[(i) % NSEGMENTS][0];
|
|
|
|
cv[1] = p[(i) % NSEGMENTS][1];
|
|
|
|
|
|
|
|
/* cone sides */
|
|
|
|
v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
v[0] = 0.0f, v[1] = 2.0f, v[2] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 1, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
/* end ring */
|
|
|
|
v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 2, v);
|
2017-02-22 18:52:07 +01:00
|
|
|
cv[0] = p[(i + 1) % NSEGMENTS][0];
|
|
|
|
cv[1] = p[(i + 1) % NSEGMENTS][1];
|
2017-02-07 11:20:15 +01:00
|
|
|
v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 3, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_empty_cone = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_empty_cone;
|
|
|
|
#undef NSEGMENTS
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_arrows_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_arrows) {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = fill_arrows_vbo(1.0f);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_arrows = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_arrows;
|
2017-02-15 02:54:52 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_axis_names_get(void)
|
2017-02-15 02:54:52 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_axis_names) {
|
|
|
|
const float size = 0.1f;
|
|
|
|
float v1[3], v2[3];
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-15 02:54:52 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
|
|
|
/* Using 3rd component as axis indicator */
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-15 02:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Line */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 14);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
/* X */
|
|
|
|
copy_v3_fl3(v1, -size, size, 0.0f);
|
|
|
|
copy_v3_fl3(v2, size, -size, 0.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
copy_v3_fl3(v1, size, size, 0.0f);
|
|
|
|
copy_v3_fl3(v2, -size, -size, 0.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 2, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 3, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
/* Y */
|
|
|
|
copy_v3_fl3(v1, -size + 0.25f * size, size, 1.0f);
|
|
|
|
copy_v3_fl3(v2, 0.0f, 0.0f, 1.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 4, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 5, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
copy_v3_fl3(v1, size - 0.25f * size, size, 1.0f);
|
|
|
|
copy_v3_fl3(v2, -size + 0.25f * size, -size, 1.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 6, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 7, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
/* Z */
|
|
|
|
copy_v3_fl3(v1, -size, size, 2.0f);
|
|
|
|
copy_v3_fl3(v2, size, size, 2.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 8, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 9, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
copy_v3_fl3(v1, size, size, 2.0f);
|
|
|
|
copy_v3_fl3(v2, -size, -size, 2.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 10, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 11, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
|
|
|
copy_v3_fl3(v1, -size, -size, 2.0f);
|
|
|
|
copy_v3_fl3(v2, size, -size, 2.0f);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 12, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 13, v2);
|
2017-02-15 02:54:52 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_axis_names = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-15 02:54:52 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_axis_names;
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_image_plane_get(void)
|
2017-05-20 22:57:47 +10:00
|
|
|
{
|
|
|
|
if (!SHC.drw_image_plane) {
|
|
|
|
const float quad[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-20 22:57:47 +10:00
|
|
|
static struct { uint pos, texCoords; } attr_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.texCoords = GWN_vertformat_attr_add(&format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
2017-05-20 22:57:47 +10:00
|
|
|
}
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 4);
|
2017-05-20 22:57:47 +10:00
|
|
|
for (uint j = 0; j < 4; j++) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, j, quad[j]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.texCoords, j, quad[j]);
|
2017-05-20 22:57:47 +10:00
|
|
|
}
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_image_plane = GWN_batch_create(GWN_PRIM_TRI_FAN, vbo, NULL);
|
2017-05-20 22:57:47 +10:00
|
|
|
}
|
|
|
|
return SHC.drw_image_plane;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_image_plane_wire_get(void)
|
2017-05-20 22:57:47 +10:00
|
|
|
{
|
|
|
|
if (!SHC.drw_image_plane_wire) {
|
|
|
|
const float quad[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-20 22:57:47 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
2017-05-20 22:57:47 +10:00
|
|
|
}
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 4);
|
2017-05-20 22:57:47 +10:00
|
|
|
for (uint j = 0; j < 4; j++) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, j, quad[j]);
|
2017-05-20 22:57:47 +10:00
|
|
|
}
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_image_plane_wire = GWN_batch_create(GWN_PRIM_LINE_LOOP, vbo, NULL);
|
2017-05-20 22:57:47 +10:00
|
|
|
}
|
|
|
|
return SHC.drw_image_plane_wire;
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:22:37 +02:00
|
|
|
/* Force Field */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_field_wind_get(void)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_field_wind) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-04-10 22:22:37 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 4);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
float z = 0.05f * (float)i;
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2 + 1, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_field_wind = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_field_wind;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_field_force_get(void)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_field_force) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-04-10 22:22:37 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 3);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
float radius = 1.0f + 0.5f * (float)i;
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = radius * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = radius * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
v[0] = radius * sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = radius * cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2 + 1, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_field_force = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_field_force;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_field_vortex_get(void)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
|
|
|
#define SPIRAL_RESOL 32
|
|
|
|
if (!SHC.drw_field_vortex) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-04-10 22:22:37 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, SPIRAL_RESOL * 2 + 1);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
for (int a = SPIRAL_RESOL; a > -1; a--) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int a = 1; a <= SPIRAL_RESOL; a++) {
|
|
|
|
v[0] = -sinf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
|
|
|
|
v[1] = -cosf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_field_vortex = GWN_batch_create(GWN_PRIM_LINE_STRIP, vbo, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_field_vortex;
|
|
|
|
#undef SPIRAL_RESOL
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_field_tube_limit_get(void)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_field_tube_limit) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-04-10 22:22:37 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 2 + 8);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
/* Caps */
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
float z = (float)i * 2.0f - 1.0f;
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Side Edges */
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
float z = (float)i * 2.0f - 1.0f;
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / 4.0f);
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / 4.0f);
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_field_tube_limit = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_field_tube_limit;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_field_cone_limit_get(void)
|
2017-04-10 22:22:37 +02:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_field_cone_limit) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-04-10 22:22:37 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 2 + 8);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
/* Caps */
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
float z = (float)i * 2.0f - 1.0f;
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
|
|
|
|
v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Side Edges */
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
float z = (float)i * 2.0f - 1.0f;
|
|
|
|
v[0] = z * sinf((2.0f * M_PI * a) / 4.0f);
|
|
|
|
v[1] = z * cosf((2.0f * M_PI * a) / 4.0f);
|
|
|
|
v[2] = z;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_field_cone_limit = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-04-10 22:22:37 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_field_cone_limit;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Lamps
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lamp_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
#define NSEGMENTS 8
|
|
|
|
if (!SHC.drw_lamp) {
|
|
|
|
float v[2];
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 2);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
for (int a = 0; a < NSEGMENTS; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)NSEGMENTS));
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)NSEGMENTS));
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 2, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)NSEGMENTS));
|
|
|
|
v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)NSEGMENTS));
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 2 + 1, v);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_lamp = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_lamp;
|
|
|
|
#undef NSEGMENTS
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lamp_sunrays_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_lamp_sunrays) {
|
|
|
|
float v[2], v1[2], v2[2];
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 16);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
|
|
|
for (int a = 0; a < 8; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / 8.0f);
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / 8.0f);
|
|
|
|
|
|
|
|
mul_v2_v2fl(v1, v, 1.2f);
|
|
|
|
mul_v2_v2fl(v2, v, 2.5f);
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 2, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 2 + 1, v2);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_lamp_sunrays = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_lamp_sunrays;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lamp_area_get(void)
|
2017-03-05 05:22:40 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_lamp_area) {
|
|
|
|
float v1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-05 05:22:40 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 8);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
v1[0] = v1[1] = 0.5f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
|
2017-03-05 05:22:40 +01:00
|
|
|
v1[0] = -0.5f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 2, v1);
|
2017-03-05 05:22:40 +01:00
|
|
|
v1[1] = -0.5f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 3, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 4, v1);
|
2017-03-05 05:22:40 +01:00
|
|
|
v1[0] = 0.5f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 5, v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 6, v1);
|
2017-03-05 05:22:40 +01:00
|
|
|
v1[1] = 0.5f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 7, v1);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_lamp_area = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_lamp_area;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lamp_hemi_get(void)
|
2017-03-05 05:22:40 +01:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_lamp_hemi) {
|
|
|
|
float v[3];
|
|
|
|
int vidx = 0;
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-05 05:22:40 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 2 - 6 * 2 * 2);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
/* XZ plane */
|
|
|
|
for (int a = 3; a < CIRCLE_RESOL / 2 - 3; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL) - M_PI / 2);
|
|
|
|
v[2] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL) - M_PI / 2) - 1.0f;
|
|
|
|
v[1] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL) - M_PI / 2);
|
|
|
|
v[2] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL) - M_PI / 2) - 1.0f;
|
|
|
|
v[1] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XY plane */
|
|
|
|
for (int a = 3; a < CIRCLE_RESOL / 2 - 3; a++) {
|
|
|
|
v[2] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL)) - 1.0f;
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[0] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
v[2] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL)) - 1.0f;
|
|
|
|
v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[0] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* YZ plane full circle */
|
|
|
|
/* lease v[2] as it is */
|
|
|
|
const float rad = cosf((2.0f * M_PI * 3) / ((float)CIRCLE_RESOL));
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[1] = rad * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[0] = rad * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
v[1] = rad * sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
|
|
|
v[0] = rad * cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_lamp_hemi = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_lamp_hemi;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lamp_spot_get(void)
|
2017-03-05 05:22:40 +01:00
|
|
|
{
|
|
|
|
#define NSEGMENTS 32
|
|
|
|
if (!SHC.drw_lamp_spot) {
|
|
|
|
/* a single ring of vertices */
|
|
|
|
float p[NSEGMENTS][2];
|
|
|
|
float n[NSEGMENTS][3];
|
|
|
|
float neg[NSEGMENTS][3];
|
|
|
|
float half_angle = 2 * M_PI / ((float)NSEGMENTS * 2);
|
|
|
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
|
|
|
float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
|
|
|
|
p[i][0] = cosf(angle);
|
|
|
|
p[i][1] = sinf(angle);
|
|
|
|
|
|
|
|
n[i][0] = cosf(angle - half_angle);
|
|
|
|
n[i][1] = sinf(angle - half_angle);
|
|
|
|
n[i][2] = cosf(M_PI / 16.0f); /* slope of the cone */
|
|
|
|
normalize_v3(n[i]); /* necessary ? */
|
|
|
|
negate_v3_v3(neg[i], n[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, n1, n2; } attr_id;
|
2017-03-05 05:22:40 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 4);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < NSEGMENTS; ++i) {
|
|
|
|
float cv[2], v[3];
|
|
|
|
cv[0] = p[i % NSEGMENTS][0];
|
|
|
|
cv[1] = p[i % NSEGMENTS][1];
|
|
|
|
|
|
|
|
/* cone sides */
|
|
|
|
v[0] = cv[0], v[1] = cv[1], v[2] = -1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
v[0] = 0.0f, v[1] = 0.0f, v[2] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 1, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4, n[(i) % NSEGMENTS]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4 + 1, n[(i) % NSEGMENTS]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4, n[(i+1) % NSEGMENTS]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4 + 1, n[(i+1) % NSEGMENTS]);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
/* end ring */
|
|
|
|
v[0] = cv[0], v[1] = cv[1], v[2] = -1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 2, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
cv[0] = p[(i + 1) % NSEGMENTS][0];
|
|
|
|
cv[1] = p[(i + 1) % NSEGMENTS][1];
|
|
|
|
v[0] = cv[0], v[1] = cv[1], v[2] = -1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 3, v);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4 + 2, n[(i) % NSEGMENTS]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4 + 3, n[(i) % NSEGMENTS]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4 + 2, neg[(i) % NSEGMENTS]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4 + 3, neg[(i) % NSEGMENTS]);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_lamp_spot = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_lamp_spot;
|
|
|
|
#undef NSEGMENTS
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lamp_spot_square_get(void)
|
2017-03-05 05:22:40 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_lamp_spot_square) {
|
|
|
|
float p[5][3] = {{ 0.0f, 0.0f, 0.0f},
|
|
|
|
{ 1.0f, 1.0f, -1.0f},
|
|
|
|
{ 1.0f, -1.0f, -1.0f},
|
|
|
|
{-1.0f, -1.0f, -1.0f},
|
|
|
|
{-1.0f, 1.0f, -1.0f}};
|
|
|
|
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-05 05:22:40 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 16);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
|
|
|
/* piramid sides */
|
|
|
|
for (int i = 1; i <= 4; ++i) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[0]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[i]);
|
2017-03-05 05:22:40 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[(i % 4)+1]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[((i+1) % 4)+1]);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_lamp_spot_square = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-03-05 05:22:40 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_lamp_spot_square;
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Speaker
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_speaker_get(void)
|
2017-02-15 03:38:21 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_speaker) {
|
|
|
|
float v[3];
|
|
|
|
const int segments = 16;
|
|
|
|
int vidx = 0;
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-15 03:38:21 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-15 03:38:21 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 3 * segments * 2 + 4 * 4);
|
2017-02-15 03:38:21 +01:00
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
float z = 0.25f * j - 0.125f;
|
|
|
|
float r = (j == 0 ? 0.5f : 0.25f);
|
|
|
|
|
|
|
|
copy_v3_fl3(v, r, 0.0f, z);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-02-15 03:38:21 +01:00
|
|
|
for (int i = 1; i < segments; i++) {
|
|
|
|
float x = cosf(2.f * (float)M_PI * i / segments) * r;
|
|
|
|
float y = sinf(2.f * (float)M_PI * i / segments) * r;
|
|
|
|
copy_v3_fl3(v, x, y, z);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-02-15 03:38:21 +01:00
|
|
|
}
|
|
|
|
copy_v3_fl3(v, r, 0.0f, z);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-02-15 03:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
float x = (((j + 1) % 2) * (j - 1)) * 0.5f;
|
|
|
|
float y = ((j % 2) * (j - 2)) * 0.5f;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (i == 1) {
|
|
|
|
x *= 0.5f;
|
|
|
|
y *= 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float z = 0.25f * i - 0.125f;
|
|
|
|
copy_v3_fl3(v, x, y, z);
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-02-15 03:38:21 +01:00
|
|
|
if (i == 1) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
|
2017-02-15 03:38:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_speaker = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-15 03:38:21 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_speaker;
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2017-06-07 16:00:10 +02:00
|
|
|
/** \name Probe
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
Gwn_Batch *DRW_cache_lightprobe_cube_get(void)
|
2017-06-07 16:00:10 +02:00
|
|
|
{
|
2017-06-27 14:59:53 +02:00
|
|
|
if (!SHC.drw_lightprobe_cube) {
|
2017-06-07 16:00:10 +02:00
|
|
|
int v_idx = 0;
|
2017-06-27 14:59:53 +02:00
|
|
|
const float sin_pi_3 = 0.86602540378f;
|
|
|
|
const float cos_pi_3 = 0.5f;
|
|
|
|
float v[7][3] = {
|
|
|
|
{0.0f, 1.0f, 0.0f},
|
|
|
|
{sin_pi_3, cos_pi_3, 0.0f},
|
|
|
|
{sin_pi_3, -cos_pi_3, 0.0f},
|
|
|
|
{0.0f, -1.0f, 0.0f},
|
|
|
|
{-sin_pi_3, -cos_pi_3, 0.0f},
|
|
|
|
{-sin_pi_3, cos_pi_3, 0.0f},
|
|
|
|
{0.0f, 0.0f, 0.0f},
|
|
|
|
};
|
2017-06-07 16:00:10 +02:00
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-06-07 16:00:10 +02:00
|
|
|
static struct { uint pos; } attr_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-06-07 16:00:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
2017-06-27 14:59:53 +02:00
|
|
|
GWN_vertbuf_data_alloc(vbo, (6 + 3) * 2);
|
2017-06-07 16:00:10 +02:00
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[(i + 1) % 6]);
|
|
|
|
}
|
2017-06-07 16:00:10 +02:00
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[1]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
|
|
|
|
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[5]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
|
|
|
|
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[3]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
|
|
|
|
|
|
|
|
SHC.drw_lightprobe_cube = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
|
|
|
}
|
|
|
|
return SHC.drw_lightprobe_cube;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gwn_Batch *DRW_cache_lightprobe_grid_get(void)
|
|
|
|
{
|
|
|
|
if (!SHC.drw_lightprobe_grid) {
|
|
|
|
int v_idx = 0;
|
|
|
|
const float sin_pi_3 = 0.86602540378f;
|
|
|
|
const float cos_pi_3 = 0.5f;
|
|
|
|
const float v[7][3] = {
|
|
|
|
{0.0f, 1.0f, 0.0f},
|
|
|
|
{sin_pi_3, cos_pi_3, 0.0f},
|
|
|
|
{sin_pi_3, -cos_pi_3, 0.0f},
|
|
|
|
{0.0f, -1.0f, 0.0f},
|
|
|
|
{-sin_pi_3, -cos_pi_3, 0.0f},
|
|
|
|
{-sin_pi_3, cos_pi_3, 0.0f},
|
|
|
|
{0.0f, 0.0f, 0.0f},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
|
|
|
static Gwn_VertFormat format = { 0 };
|
|
|
|
static struct { uint pos; } attr_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, (6 * 3 + 3) * 2);
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
float tmp_v1[3], tmp_v2[3], tmp_tr[3];
|
|
|
|
copy_v3_v3(tmp_v1, v[i]);
|
|
|
|
copy_v3_v3(tmp_v2, v[(i + 1) % 6]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v2);
|
|
|
|
|
|
|
|
/* Internal wires. */
|
|
|
|
for (int j = 1; j < 2; ++j) {
|
|
|
|
mul_v3_v3fl(tmp_tr, v[(i / 2) * 2 + 1], -0.5f * j);
|
|
|
|
add_v3_v3v3(tmp_v1, v[i], tmp_tr);
|
|
|
|
add_v3_v3v3(tmp_v2, v[(i + 1) % 6], tmp_tr);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v2);
|
2017-06-07 16:00:10 +02:00
|
|
|
}
|
2017-06-27 14:59:53 +02:00
|
|
|
}
|
2017-06-07 16:00:10 +02:00
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[1]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
|
|
|
|
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[5]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
|
|
|
|
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[3]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
|
|
|
|
|
|
|
|
SHC.drw_lightprobe_grid = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
|
|
|
}
|
|
|
|
return SHC.drw_lightprobe_grid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gwn_Batch *DRW_cache_lightprobe_planar_get(void)
|
|
|
|
{
|
|
|
|
if (!SHC.drw_lightprobe_planar) {
|
|
|
|
int v_idx = 0;
|
|
|
|
const float sin_pi_3 = 0.86602540378f;
|
|
|
|
float v[4][3] = {
|
|
|
|
{0.0f, 0.5f, 0.0f},
|
|
|
|
{sin_pi_3, 0.0f, 0.0f},
|
|
|
|
{0.0f, -0.5f, 0.0f},
|
|
|
|
{-sin_pi_3, 0.0f, 0.0f},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
|
|
|
static Gwn_VertFormat format = { 0 };
|
|
|
|
static struct { uint pos; } attr_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-06-07 16:00:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 14:59:53 +02:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 4 * 2);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[(i + 1) % 4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SHC.drw_lightprobe_planar = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-06-07 16:00:10 +02:00
|
|
|
}
|
2017-06-27 14:59:53 +02:00
|
|
|
return SHC.drw_lightprobe_planar;
|
2017-06-07 16:00:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \name Armature Bones
|
|
|
|
* \{ */
|
|
|
|
|
2017-02-22 13:00:15 +01:00
|
|
|
static const float bone_octahedral_verts[6][3] = {
|
|
|
|
{ 0.0f, 0.0f, 0.0f},
|
|
|
|
{ 0.1f, 0.1f, 0.1f},
|
|
|
|
{ 0.1f, 0.1f, -0.1f},
|
|
|
|
{-0.1f, 0.1f, -0.1f},
|
|
|
|
{-0.1f, 0.1f, 0.1f},
|
|
|
|
{ 0.0f, 1.0f, 0.0f}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int bone_octahedral_wire[24] = {
|
|
|
|
0, 1, 1, 5, 5, 3, 3, 0,
|
|
|
|
0, 4, 4, 5, 5, 2, 2, 0,
|
|
|
|
1, 2, 2, 3, 3, 4, 4, 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* aligned with bone_octahedral_wire
|
|
|
|
* Contains adjacent normal index */
|
|
|
|
static const unsigned int bone_octahedral_wire_adjacent_face[24] = {
|
|
|
|
0, 3, 4, 7, 5, 6, 1, 2,
|
|
|
|
2, 3, 6, 7, 4, 5, 0, 1,
|
|
|
|
0, 4, 1, 5, 2, 6, 3, 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int bone_octahedral_solid_tris[8][3] = {
|
|
|
|
{2, 1, 0}, /* bottom */
|
|
|
|
{3, 2, 0},
|
|
|
|
{4, 3, 0},
|
|
|
|
{1, 4, 0},
|
|
|
|
|
|
|
|
{5, 1, 2}, /* top */
|
|
|
|
{5, 2, 3},
|
|
|
|
{5, 3, 4},
|
|
|
|
{5, 4, 1}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* aligned with bone_octahedral_solid_tris */
|
|
|
|
static const float bone_octahedral_solid_normals[8][3] = {
|
|
|
|
{ M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
|
|
|
|
{-0.00000000f, -M_SQRT1_2, -M_SQRT1_2},
|
|
|
|
{-M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
|
|
|
|
{ 0.00000000f, -M_SQRT1_2, M_SQRT1_2},
|
|
|
|
{ 0.99388373f, 0.11043154f, -0.00000000f},
|
|
|
|
{ 0.00000000f, 0.11043154f, -0.99388373f},
|
|
|
|
{-0.99388373f, 0.11043154f, 0.00000000f},
|
|
|
|
{ 0.00000000f, 0.11043154f, 0.99388373f}
|
|
|
|
};
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_octahedral_get(void)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_octahedral) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, nor; } attr_id;
|
2017-02-22 13:00:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 24);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_octahedral_solid_normals[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_octahedral_verts[bone_octahedral_solid_tris[i][0]]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_octahedral_solid_normals[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_octahedral_verts[bone_octahedral_solid_tris[i][1]]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_octahedral_solid_normals[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_octahedral_verts[bone_octahedral_solid_tris[i][2]]);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_octahedral = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_octahedral;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_octahedral_wire_outline_get(void)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_octahedral_wire) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, n1, n2; } attr_id;
|
2017-02-22 13:00:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 12 * 2);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
2017-02-22 18:52:07 +01:00
|
|
|
const float *co1 = bone_octahedral_verts[bone_octahedral_wire[i * 2]];
|
|
|
|
const float *co2 = bone_octahedral_verts[bone_octahedral_wire[i * 2 + 1]];
|
|
|
|
const float *n1 = bone_octahedral_solid_normals[bone_octahedral_wire_adjacent_face[i * 2]];
|
|
|
|
const float *n2 = bone_octahedral_solid_normals[bone_octahedral_wire_adjacent_face[i * 2 + 1]];
|
2017-05-17 12:22:22 +10:00
|
|
|
add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n1, n2);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_octahedral_wire = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_octahedral_wire;
|
|
|
|
}
|
|
|
|
|
2017-05-03 08:34:24 +02:00
|
|
|
|
|
|
|
/* XXX TODO move that 1 unit cube to more common/generic place? */
|
|
|
|
static const float bone_box_verts[8][3] = {
|
|
|
|
{ 1.0f, 0.0f, 1.0f},
|
|
|
|
{ 1.0f, 0.0f, -1.0f},
|
|
|
|
{-1.0f, 0.0f, -1.0f},
|
|
|
|
{-1.0f, 0.0f, 1.0f},
|
|
|
|
{ 1.0f, 1.0f, 1.0f},
|
|
|
|
{ 1.0f, 1.0f, -1.0f},
|
|
|
|
{-1.0f, 1.0f, -1.0f},
|
|
|
|
{-1.0f, 1.0f, 1.0f}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int bone_box_wire[24] = {
|
|
|
|
0, 1, 1, 2, 2, 3, 3, 0,
|
|
|
|
4, 5, 5, 6, 6, 7, 7, 4,
|
|
|
|
0, 4, 1, 5, 2, 6, 3, 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* aligned with bone_octahedral_wire
|
|
|
|
* Contains adjacent normal index */
|
|
|
|
static const unsigned int bone_box_wire_adjacent_face[24] = {
|
|
|
|
0, 2, 0, 4, 1, 6, 1, 8,
|
|
|
|
3, 10, 5, 10, 7, 11, 9, 11,
|
|
|
|
3, 8, 2, 5, 4, 7, 6, 9,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int bone_box_solid_tris[12][3] = {
|
|
|
|
{0, 1, 2}, /* bottom */
|
|
|
|
{0, 2, 3},
|
|
|
|
|
|
|
|
{0, 1, 5}, /* sides */
|
|
|
|
{0, 5, 4},
|
|
|
|
|
|
|
|
{1, 2, 6},
|
|
|
|
{1, 6, 5},
|
|
|
|
|
|
|
|
{2, 3, 7},
|
|
|
|
{2, 7, 6},
|
|
|
|
|
|
|
|
{3, 0, 4},
|
|
|
|
{3, 4, 7},
|
|
|
|
|
|
|
|
{4, 5, 6}, /* top */
|
|
|
|
{4, 6, 7},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* aligned with bone_octahedral_solid_tris */
|
|
|
|
static const float bone_box_solid_normals[12][3] = {
|
|
|
|
{ 0.0f, -1.0f, 0.0f},
|
|
|
|
{ 0.0f, -1.0f, 0.0f},
|
|
|
|
|
|
|
|
{ 1.0f, 0.0f, 0.0f},
|
|
|
|
{ 1.0f, 0.0f, 0.0f},
|
|
|
|
|
|
|
|
{ 0.0f, 0.0f, -1.0f},
|
|
|
|
{ 0.0f, 0.0f, -1.0f},
|
|
|
|
|
|
|
|
{-1.0f, 0.0f, 0.0f},
|
|
|
|
{-1.0f, 0.0f, 0.0f},
|
|
|
|
|
|
|
|
{ 0.0f, 0.0f, 1.0f},
|
|
|
|
{ 0.0f, 0.0f, 1.0f},
|
|
|
|
|
|
|
|
{ 0.0f, 1.0f, 0.0f},
|
|
|
|
{ 0.0f, 1.0f, 0.0f},
|
|
|
|
};
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_box_get(void)
|
2017-05-03 08:34:24 +02:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_box) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, nor; } attr_id;
|
2017-05-03 08:34:24 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 36);
|
2017-05-03 08:34:24 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_box_solid_normals[i]);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_box_verts[bone_box_solid_tris[i][j]]);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_box = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_box;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_box_wire_outline_get(void)
|
2017-05-03 08:34:24 +02:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_box_wire) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, n1, n2; } attr_id;
|
2017-05-03 08:34:24 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 12 * 2);
|
2017-05-03 08:34:24 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
const float *co1 = bone_box_verts[bone_box_wire[i * 2]];
|
|
|
|
const float *co2 = bone_box_verts[bone_box_wire[i * 2 + 1]];
|
|
|
|
const float *n1 = bone_box_solid_normals[bone_box_wire_adjacent_face[i * 2]];
|
|
|
|
const float *n2 = bone_box_solid_normals[bone_box_wire_adjacent_face[i * 2 + 1]];
|
2017-05-17 12:22:22 +10:00
|
|
|
add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n1, n2);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_box_wire = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_box_wire;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_wire_wire_outline_get(void)
|
2017-05-03 08:34:24 +02:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_wire_wire) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, n1, n2; } attr_id;
|
2017-05-03 08:34:24 +02:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 2);
|
2017-05-03 08:34:24 +02:00
|
|
|
|
|
|
|
const float co1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
const float co2[3] = {0.0f, 1.0f, 0.0f};
|
|
|
|
const float n[3] = {1.0f, 0.0f, 0.0f};
|
2017-05-17 12:22:22 +10:00
|
|
|
add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n, n);
|
2017-05-03 08:34:24 +02:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_wire_wire = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-05-03 08:34:24 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_wire_wire;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-18 11:41:59 +02:00
|
|
|
/* Helpers for envelope bone's solid sphere-with-hidden-equatorial-cylinder.
|
|
|
|
* Note that here we only encode head/tail in forth component of the vector. */
|
|
|
|
static void benv_lat_lon_to_co(const float lat, const float lon, float r_nor[3])
|
|
|
|
{
|
|
|
|
/* Poles are along Y axis. */
|
|
|
|
r_nor[0] = sinf(lat) * cosf(lon);
|
|
|
|
r_nor[1] = cosf(lat);
|
|
|
|
r_nor[2] = sinf(lat) * sinf(lon);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static void benv_add_tri(Gwn_VertBuf *vbo, uint pos_id, uint *v_idx, float *co1, float *co2, float *co3)
|
2017-05-18 11:41:59 +02:00
|
|
|
{
|
|
|
|
/* Given tri and its seven other mirrors along X/Y/Z axes. */
|
|
|
|
for (int x = -1; x <= 1; x += 2) {
|
|
|
|
for (int y = -1; y <= 1; y += 2) {
|
|
|
|
const float head_tail = (y == -1) ? 0.0f : 1.0f;
|
|
|
|
for (int z = -1; z <= 1; z += 2) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++,
|
|
|
|
(const float[4]){co1[0] * x, co1[1] * y, co1[2] * z, head_tail});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++,
|
|
|
|
(const float[4]){co2[0] * x, co2[1] * y, co2[2] * z, head_tail});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++,
|
|
|
|
(const float[4]){co3[0] * x, co3[1] * y, co3[2] * z, head_tail});
|
2017-05-18 11:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_envelope_solid_get(void)
|
2017-05-18 11:41:59 +02:00
|
|
|
{
|
|
|
|
#define CIRCLE_RESOL 32 /* Must be multiple of 4 */
|
|
|
|
if (!SHC.drw_bone_envelope) {
|
|
|
|
const int lon_res = CIRCLE_RESOL / 4;
|
|
|
|
const int lat_res = CIRCLE_RESOL / 4;
|
|
|
|
const float lon_inc = M_PI_2 / lon_res;
|
|
|
|
const float lat_inc = M_PI_2 / lat_res;
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-18 11:41:59 +02:00
|
|
|
static struct { uint pos; } attr_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
|
2017-05-18 11:41:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, lat_res * lon_res * 8 * 6);
|
2017-05-18 11:41:59 +02:00
|
|
|
|
|
|
|
float lon = 0.0f;
|
|
|
|
for (int i = 0; i < lon_res; i++, lon += lon_inc) {
|
|
|
|
float lat = 0.0f;
|
|
|
|
float co1[3], co2[3], co3[3], co4[3];
|
|
|
|
|
|
|
|
for (int j = 0; j < lat_res; j++, lat += lat_inc) {
|
|
|
|
benv_lat_lon_to_co(lat , lon , co1);
|
|
|
|
benv_lat_lon_to_co(lat , lon + lon_inc, co2);
|
|
|
|
benv_lat_lon_to_co(lat + lat_inc, lon + lon_inc, co3);
|
|
|
|
benv_lat_lon_to_co(lat + lat_inc, lon , co4);
|
|
|
|
|
|
|
|
if (j != 0) { /* At pole, n1 and n2 are identical. */
|
|
|
|
benv_add_tri(vbo, attr_id.pos, &v_idx, co1, co2, co3);
|
|
|
|
}
|
|
|
|
benv_add_tri(vbo, attr_id.pos, &v_idx, co1, co3, co4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lat is at equator (i.e. lat == pi / 2). */
|
|
|
|
/* We need to add 'cylinder' part between the equators (along XZ plane). */
|
|
|
|
for (int x = -1; x <= 1; x += 2) {
|
|
|
|
for (int z = -1; z <= 1; z += 2) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++,
|
|
|
|
(const float[4]){co3[0] * x, co3[1], co3[2] * z, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++,
|
|
|
|
(const float[4]){co4[0] * x, co4[1], co4[2] * z, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++,
|
|
|
|
(const float[4]){co4[0] * x, co4[1], co4[2] * z, 1.0f});
|
|
|
|
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++,
|
|
|
|
(const float[4]){co3[0] * x, co3[1], co3[2] * z, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++,
|
|
|
|
(const float[4]){co4[0] * x, co4[1], co4[2] * z, 1.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++,
|
|
|
|
(const float[4]){co3[0] * x, co3[1], co3[2] * z, 1.0f});
|
2017-05-18 11:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_envelope = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-05-18 11:41:59 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_envelope;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_envelope_distance_outline_get(void)
|
2017-05-17 12:34:06 +02:00
|
|
|
{
|
2017-05-18 11:41:59 +02:00
|
|
|
#define CIRCLE_RESOL 32 /* Must be multiple of 2 */
|
2017-05-17 12:34:06 +02:00
|
|
|
if (!SHC.drw_bone_envelope_distance) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:34:06 +02:00
|
|
|
static unsigned int pos_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 + 6);
|
2017-05-17 12:34:06 +02:00
|
|
|
|
|
|
|
/* Encoded triangle strip, vertex shader gives them final correct value. */
|
|
|
|
for (int i = 0; i < CIRCLE_RESOL + 1; i++) {
|
|
|
|
const bool is_headtail_transition = ELEM(i, CIRCLE_RESOL / 2, CIRCLE_RESOL);
|
|
|
|
const float head_tail = (i > CIRCLE_RESOL / 2) ? 1.0f : 0.0f;
|
|
|
|
const float alpha = 2.0f * M_PI * i / CIRCLE_RESOL;
|
|
|
|
const float x = cosf(alpha);
|
|
|
|
const float y = -sinf(alpha);
|
|
|
|
|
|
|
|
/* { X, Y, head/tail, inner/outer border } */
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){x, y, head_tail, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){x, y, head_tail, 1.0f});
|
2017-05-17 12:34:06 +02:00
|
|
|
if (is_headtail_transition) {
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){x, y, 1.0f - head_tail, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){x, y, 1.0f - head_tail, 1.0f});
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_envelope_distance = GWN_batch_create(GWN_PRIM_TRI_STRIP, vbo, NULL);
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_envelope_distance;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-18 11:41:59 +02:00
|
|
|
/* Bone body. */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_envelope_wire_outline_get(void)
|
2017-05-17 12:34:06 +02:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_envelope_wire) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:34:06 +02:00
|
|
|
static unsigned int pos_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 4);
|
2017-05-17 12:34:06 +02:00
|
|
|
|
|
|
|
/* Two lines between head and tail circles. */
|
|
|
|
/* Encoded lines, vertex shader gives them final correct value. */
|
|
|
|
/* { X, Y, head/tail, inner/outer border } */
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){ 1.0f, 0.0f, 0.0f, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){ 1.0f, 0.0f, 1.0f, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){-1.0f, 0.0f, 0.0f, 0.0f});
|
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){-1.0f, 0.0f, 1.0f, 0.0f});
|
2017-05-17 12:34:06 +02:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_envelope_wire = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_envelope_wire;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-18 11:41:59 +02:00
|
|
|
/* Bone head and tail. */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_envelope_head_wire_outline_get(void)
|
2017-05-17 12:34:06 +02:00
|
|
|
{
|
2017-05-18 11:41:59 +02:00
|
|
|
#define CIRCLE_RESOL 32 /* Must be multiple of 2 */
|
2017-05-17 12:34:06 +02:00
|
|
|
if (!SHC.drw_bone_envelope_head_wire) {
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:34:06 +02:00
|
|
|
static unsigned int pos_id;
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL);
|
2017-05-17 12:34:06 +02:00
|
|
|
|
|
|
|
/* Encoded lines, vertex shader gives them final correct value. */
|
|
|
|
/* Only head circle (tail is drawn in disp_tail_mat space as a head one by draw_armature.c's draw_point()). */
|
|
|
|
for (int i = 0; i < CIRCLE_RESOL; i++) {
|
|
|
|
const float alpha = 2.0f * M_PI * i / CIRCLE_RESOL;
|
|
|
|
const float x = cosf(alpha);
|
|
|
|
const float y = -sinf(alpha);
|
|
|
|
|
|
|
|
/* { X, Y, head/tail, inner/outer border } */
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, v_idx++, (const float[4]){ x, y, 0.0f, 0.0f});
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_envelope_head_wire = GWN_batch_create(GWN_PRIM_LINE_LOOP, vbo, NULL);
|
2017-05-17 12:34:06 +02:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_envelope_head_wire;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_point_get(void)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_point) {
|
|
|
|
const int lon_res = 16;
|
|
|
|
const int lat_res = 8;
|
|
|
|
const float rad = 0.05f;
|
|
|
|
const float lon_inc = 2 * M_PI / lon_res;
|
|
|
|
const float lat_inc = M_PI / lat_res;
|
|
|
|
unsigned int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos, nor; } attr_id;
|
2017-02-22 13:00:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, (lat_res - 1) * lon_res * 6);
|
2017-02-22 13:00:15 +01:00
|
|
|
|
|
|
|
float lon = 0.0f;
|
2017-02-22 18:52:07 +01:00
|
|
|
for (int i = 0; i < lon_res; i++, lon += lon_inc) {
|
2017-02-22 13:00:15 +01:00
|
|
|
float lat = 0.0f;
|
2017-02-22 18:52:07 +01:00
|
|
|
for (int j = 0; j < lat_res; j++, lat += lat_inc) {
|
2017-02-22 13:00:15 +01:00
|
|
|
if (j != lat_res - 1) { /* Pole */
|
2017-05-17 12:22:22 +10:00
|
|
|
add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat + lat_inc, lon + lon_inc);
|
|
|
|
add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat + lat_inc, lon);
|
|
|
|
add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat, lon);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (j != 0) { /* Pole */
|
2017-05-17 12:22:22 +10:00
|
|
|
add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat, lon + lon_inc);
|
|
|
|
add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat + lat_inc, lon + lon_inc);
|
|
|
|
add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat, lon);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_bone_point = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_point;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_point_wire_outline_get(void)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_point_wire) {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = sphere_wire_vbo(0.05f);
|
|
|
|
SHC.drw_bone_point_wire = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_point_wire;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_bone_arrows_get(void)
|
2017-02-22 13:00:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_bone_arrows) {
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = fill_arrows_vbo(0.25f);
|
|
|
|
SHC.drw_bone_arrows = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-02-22 13:00:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_bone_arrows;
|
|
|
|
}
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Camera
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_camera_get(void)
|
2017-03-04 00:09:22 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_camera) {
|
|
|
|
float v0 = 0.0f; /* Center point */
|
|
|
|
float v1 = 1.0f; /* + X + Y */
|
|
|
|
float v2 = 2.0f; /* + X - Y */
|
|
|
|
float v3 = 3.0f; /* - X - Y */
|
|
|
|
float v4 = 4.0f; /* - X + Y */
|
|
|
|
float v5 = 5.0f; /* tria + X */
|
|
|
|
float v6 = 6.0f; /* tria - X */
|
|
|
|
float v7 = 7.0f; /* tria + Y */
|
|
|
|
int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-04 00:09:22 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
|
|
|
/* use x coordinate to identify the vertex
|
|
|
|
* the vertex shader take care to place it
|
|
|
|
* appropriatelly */
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
|
2017-03-04 00:09:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 22);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v0);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v1);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v0);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v2);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v0);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v3);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v0);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v4);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
|
|
|
/* camera frame */
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v1);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v2);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v2);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v3);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v3);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v4);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v4);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v1);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
|
|
|
/* tria */
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v5);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v6);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v6);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v7);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v7);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v5);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_camera = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-03-04 00:09:22 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_camera;
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_camera_tria_get(void)
|
2017-03-04 00:09:22 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_camera_tria) {
|
|
|
|
float v5 = 5.0f; /* tria + X */
|
|
|
|
float v6 = 6.0f; /* tria - X */
|
|
|
|
float v7 = 7.0f; /* tria + Y */
|
|
|
|
int v_idx = 0;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-03-04 00:09:22 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
|
|
|
/* use x coordinate to identify the vertex
|
|
|
|
* the vertex shader take care to place it
|
|
|
|
* appropriatelly */
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
|
2017-03-04 00:09:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Vertices */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 6);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
|
|
|
/* tria */
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v5);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v6);
|
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, &v7);
|
2017-03-04 00:09:22 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_camera_tria = GWN_batch_create(GWN_PRIM_TRIS, vbo, NULL);
|
2017-03-04 00:09:22 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_camera_tria;
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Object Mode Helpers
|
|
|
|
* \{ */
|
|
|
|
|
2017-02-07 11:20:15 +01:00
|
|
|
/* Object Center */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_single_vert_get(void)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
if (!SHC.drw_single_vertice) {
|
|
|
|
float v1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
/* Position Only 3D format */
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-17 12:22:22 +10:00
|
|
|
static struct { uint pos; } attr_id;
|
2017-02-07 11:20:15 +01:00
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 1);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_single_vertice = GWN_batch_create(GWN_PRIM_POINTS, vbo, NULL);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
return SHC.drw_single_vertice;
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Meshes
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_surface_overlay_get(Object *ob)
|
2017-04-21 21:14:11 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_all_triangles(me);
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:07:57 +10:00
|
|
|
void DRW_cache_mesh_wire_overlay_get(
|
|
|
|
Object *ob,
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch **r_tris, Gwn_Batch **r_ledges, Gwn_Batch **r_lverts)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-03-01 14:07:04 +01:00
|
|
|
|
2017-04-21 21:14:11 +10:00
|
|
|
*r_tris = DRW_mesh_batch_cache_get_overlay_triangles(me);
|
|
|
|
*r_ledges = DRW_mesh_batch_cache_get_overlay_loose_edges(me);
|
|
|
|
*r_lverts = DRW_mesh_batch_cache_get_overlay_loose_verts(me);
|
2017-03-02 01:07:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-13 16:45:06 +02:00
|
|
|
void DRW_cache_mesh_normals_overlay_get(
|
|
|
|
Object *ob,
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch **r_tris, Gwn_Batch **r_ledges, Gwn_Batch **r_lverts)
|
2017-05-13 16:45:06 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
|
|
|
|
*r_tris = DRW_mesh_batch_cache_get_overlay_triangles_nor(me);
|
|
|
|
*r_ledges = DRW_mesh_batch_cache_get_overlay_loose_edges_nor(me);
|
|
|
|
*r_lverts = DRW_mesh_batch_cache_get_overlay_loose_verts(me);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_face_centers_get(Object *ob)
|
2017-03-02 01:07:03 +01:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-03-01 14:07:04 +01:00
|
|
|
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_mesh_batch_cache_get_overlay_facedots(me);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_wire_outline_get(Object *ob)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_mesh_batch_cache_get_fancy_edges(me);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_surface_get(Object *ob)
|
2017-02-07 11:20:15 +01:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_mesh_batch_cache_get_triangles_with_normals(me);
|
2017-02-07 11:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_surface_weights_get(Object *ob)
|
2017-05-03 18:55:40 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(me, ob->actdef - 1);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_surface_vert_colors_get(Object *ob)
|
2017-05-04 19:59:27 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(me);
|
|
|
|
}
|
|
|
|
|
2017-04-25 18:46:59 +02:00
|
|
|
/* Return list of batches */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch **DRW_cache_mesh_surface_shaded_get(Object *ob)
|
2017-04-25 18:46:59 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_surface_shaded(me);
|
|
|
|
}
|
|
|
|
|
2017-05-22 23:31:46 +10:00
|
|
|
/* Return list of batches */
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch **DRW_cache_mesh_surface_texpaint_get(Object *ob)
|
2017-05-22 23:31:46 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_surface_texpaint(me);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_surface_texpaint_single_get(Object *ob)
|
2017-05-22 23:31:46 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_surface_texpaint_single(me);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_surface_verts_get(Object *ob)
|
2017-03-09 01:29:58 +01:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_mesh_batch_cache_get_points_with_normals(me);
|
2017-03-09 01:29:58 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_edges_get(Object *ob)
|
2017-04-28 22:30:21 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_all_edges(me);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_verts_get(Object *ob)
|
2017-03-09 01:29:58 +01:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_mesh_batch_cache_get_all_verts(me);
|
2017-03-09 01:29:58 +01:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_edges_paint_overlay_get(Object *ob, bool use_wire, bool use_sel)
|
2017-05-03 18:55:40 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
2017-05-05 14:25:43 +02:00
|
|
|
return DRW_mesh_batch_cache_get_weight_overlay_edges(me, use_wire, use_sel);
|
2017-05-03 18:55:40 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_faces_weight_overlay_get(Object *ob)
|
2017-05-03 18:55:40 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_weight_overlay_faces(me);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_mesh_verts_weight_overlay_get(Object *ob)
|
2017-05-03 18:55:40 +02:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return DRW_mesh_batch_cache_get_weight_overlay_verts(me);
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2017-04-15 16:46:17 +10:00
|
|
|
/** \name Curve
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_curve_edge_wire_get(Object *ob)
|
2017-04-15 16:46:17 +10:00
|
|
|
{
|
2017-04-21 17:58:18 +10:00
|
|
|
BLI_assert(ob->type == OB_CURVE);
|
2017-04-15 16:46:17 +10:00
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_wire_edge(cu, ob->curve_cache);
|
2017-04-15 16:46:17 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_curve_edge_normal_get(Object *ob, float normal_size)
|
2017-04-20 05:23:48 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_CURVE);
|
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_normal_edge(cu, ob->curve_cache, normal_size);
|
2017-04-20 05:23:48 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_curve_edge_overlay_get(Object *ob)
|
2017-04-15 16:46:17 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_CURVE);
|
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_overlay_edges(cu);
|
2017-04-15 16:46:17 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_curve_vert_overlay_get(Object *ob)
|
2017-04-15 16:46:17 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_CURVE);
|
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_overlay_verts(cu);
|
2017-04-15 16:46:17 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_curve_surface_get(Object *ob)
|
2017-04-21 02:18:14 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_CURVE);
|
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
|
2017-04-21 02:18:14 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Font
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_text_edge_wire_get(Object *ob)
|
2017-04-21 02:18:14 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_FONT);
|
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_wire_edge(cu, ob->curve_cache);
|
2017-04-21 17:58:18 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_text_surface_get(Object *ob)
|
2017-04-21 17:58:18 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_FONT);
|
|
|
|
struct Curve *cu = ob->data;
|
|
|
|
if (cu->editfont && (cu->flag & CU_FAST)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
|
2017-04-21 02:18:14 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_text_cursor_overlay_get(Object *ob)
|
2017-04-21 17:58:18 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_FONT);
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_overlay_cursor(cu);
|
2017-04-21 17:58:18 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_text_select_overlay_get(Object *ob)
|
2017-04-21 17:58:18 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_FONT);
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_overlay_select(cu);
|
2017-04-21 17:58:18 +10:00
|
|
|
}
|
|
|
|
|
2017-04-21 02:18:14 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Surface
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_surf_surface_get(Object *ob)
|
2017-04-21 02:18:14 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_SURF);
|
|
|
|
|
|
|
|
struct Curve *cu = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
|
2017-04-21 02:18:14 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
2017-04-15 16:46:17 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2017-04-15 14:24:30 +10:00
|
|
|
/** \name Lattice
|
|
|
|
* \{ */
|
2017-04-13 22:09:59 +10:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lattice_verts_get(Object *ob)
|
2017-04-13 22:09:59 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_LATTICE);
|
|
|
|
|
|
|
|
struct Lattice *lt = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_lattice_batch_cache_get_all_verts(lt);
|
2017-04-13 22:09:59 +10:00
|
|
|
}
|
|
|
|
|
2017-06-27 15:59:13 +02:00
|
|
|
Gwn_Batch *DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
|
2017-04-13 22:09:59 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_LATTICE);
|
|
|
|
|
2017-06-27 15:59:13 +02:00
|
|
|
Lattice *lt = ob->data;
|
|
|
|
int actdef = -1;
|
|
|
|
|
|
|
|
if (use_weight && ob->defbase.first && lt->editlatt->latt->dvert) {
|
|
|
|
actdef = ob->actdef - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DRW_lattice_batch_cache_get_all_edges(lt, use_weight, actdef);
|
2017-04-13 22:09:59 +10:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_lattice_vert_overlay_get(Object *ob)
|
2017-04-13 23:29:45 +10:00
|
|
|
{
|
|
|
|
BLI_assert(ob->type == OB_LATTICE);
|
|
|
|
|
|
|
|
struct Lattice *lt = ob->data;
|
2017-04-21 21:14:11 +10:00
|
|
|
return DRW_lattice_batch_cache_get_overlay_verts(lt);
|
2017-04-13 23:29:45 +10:00
|
|
|
}
|
|
|
|
|
2017-05-03 08:34:24 +02:00
|
|
|
/** \} */
|
2017-05-09 16:23:47 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** \name Particles
|
|
|
|
* \{ */
|
|
|
|
|
2017-06-22 19:19:55 +02:00
|
|
|
Gwn_Batch *DRW_cache_particles_get_hair(ParticleSystem *psys, ModifierData *md)
|
2017-05-09 16:23:47 +02:00
|
|
|
{
|
2017-06-22 19:19:55 +02:00
|
|
|
return DRW_particles_batch_cache_get_hair(psys, md);
|
2017-05-09 16:23:47 +02:00
|
|
|
}
|
2017-05-19 17:13:48 +02:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_particles_get_dots(ParticleSystem *psys)
|
2017-05-19 17:13:48 +02:00
|
|
|
{
|
|
|
|
return DRW_particles_batch_cache_get_dots(psys);
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_Batch *DRW_cache_particles_get_prim(int type)
|
2017-05-19 17:13:48 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case PART_DRAW_CROSS:
|
|
|
|
if (!SHC.drw_particle_cross) {
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-19 17:13:48 +02:00
|
|
|
static unsigned pos_id, axis_id;
|
|
|
|
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
pos_id = GWN_vertformat_attr_add(&format, "inst_pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
axis_id = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_I32, 1, GWN_FETCH_INT);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 6);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
/* X axis */
|
|
|
|
float co[3] = {-1.0f, 0.0f, 0.0f};
|
|
|
|
int axis = -1;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 0, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 0, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
co[0] = 1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 1, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 1, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
/* Y axis */
|
|
|
|
co[0] = 0.0f;
|
|
|
|
co[1] = -1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 2, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 2, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
co[1] = 1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 3, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 3, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
/* Z axis */
|
|
|
|
co[1] = 0.0f;
|
|
|
|
co[2] = -1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 4, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 4, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
co[2] = 1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 5, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 5, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_particle_cross = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return SHC.drw_particle_cross;
|
|
|
|
case PART_DRAW_AXIS:
|
|
|
|
if (!SHC.drw_particle_axis) {
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-19 17:13:48 +02:00
|
|
|
static unsigned pos_id, axis_id;
|
|
|
|
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
pos_id = GWN_vertformat_attr_add(&format, "inst_pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
axis_id = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_I32, 1, GWN_FETCH_INT);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, 6);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
/* X axis */
|
|
|
|
float co[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
int axis = 0;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 0, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 0, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
co[0] = 1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 1, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 1, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
/* Y axis */
|
|
|
|
co[0] = 0.0f;
|
|
|
|
axis = 1;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 2, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 2, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
co[1] = 1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 3, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 3, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
/* Z axis */
|
|
|
|
co[1] = 0.0f;
|
|
|
|
axis = 2;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 4, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 4, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
co[2] = 1.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, 5, co);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, 5, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_particle_axis = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return SHC.drw_particle_axis;
|
|
|
|
case PART_DRAW_CIRC:
|
|
|
|
#define CIRCLE_RESOL 32
|
|
|
|
if (!SHC.drw_particle_circle) {
|
|
|
|
float v[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
int axis = -1;
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
static Gwn_VertFormat format = { 0 };
|
2017-05-19 17:13:48 +02:00
|
|
|
static unsigned pos_id, axis_id;
|
|
|
|
|
|
|
|
if (format.attrib_ct == 0) {
|
2017-06-19 20:18:04 +10:00
|
|
|
pos_id = GWN_vertformat_attr_add(&format, "inst_pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
|
|
|
|
axis_id = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_I32, 1, GWN_FETCH_INT);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
|
|
|
|
GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL);
|
2017-05-19 17:13:48 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < CIRCLE_RESOL; a++) {
|
|
|
|
v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
|
|
|
|
v[2] = 0.0f;
|
2017-06-19 20:18:04 +10:00
|
|
|
GWN_vertbuf_attr_set(vbo, pos_id, a, v);
|
|
|
|
GWN_vertbuf_attr_set(vbo, axis_id, a, &axis);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
SHC.drw_particle_circle = GWN_batch_create(GWN_PRIM_LINE_LOOP, vbo, NULL);
|
2017-05-19 17:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return SHC.drw_particle_circle;
|
|
|
|
#undef CIRCLE_RESOL
|
|
|
|
default:
|
|
|
|
BLI_assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|