diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-09-26 10:51:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-09-26 10:51:47 +0300 |
commit | 1eb49f8a2fc33b17542eac950ebdc43aadb0f03e (patch) | |
tree | 0b8ce0f383200c5b06a3244136c737b88c432b03 /source/blender/gpu/intern/gpu_immediate_util.c | |
parent | 63dfb5bb97b1a320a0f5e51eaca51d7b25902aa4 (diff) |
GPU_immediate_util: add cube drawing function
Diffstat (limited to 'source/blender/gpu/intern/gpu_immediate_util.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_immediate_util.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c index 45230021435..bad878ef4bf 100644 --- a/source/blender/gpu/intern/gpu_immediate_util.c +++ b/source/blender/gpu/intern/gpu_immediate_util.c @@ -33,6 +33,39 @@ #include "GPU_immediate_util.h" #include "GPU_matrix.h" +static const float cube_coords[8][3] = { + {-1, -1, -1}, + {-1, -1, +1}, + {-1, +1, -1}, + {-1, +1, +1}, + {+1, -1, -1}, + {+1, -1, +1}, + {+1, +1, -1}, + {+1, +1, +1}, +}; +static const int cube_quad_index[6][4] = { + {0, 1, 3, 2}, + {0, 2, 6, 4}, + {0, 4, 5, 1}, + {1, 5, 7, 3}, + {2, 3, 7, 6}, + {4, 6, 7, 5}, +}; +static const int cube_line_index[12][2] = { + {0, 1}, + {0, 2}, + {0, 4}, + {1, 3}, + {1, 5}, + {2, 3}, + {2, 6}, + {3, 7}, + {4, 5}, + {4, 6}, + {5, 7}, + {6, 7}, +}; + /** * Pack color into 3 bytes * @@ -214,6 +247,43 @@ void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2) immUnbindProgram(); } +void imm_draw_cube_fill_3d(uint pos, const float co[3], const float aspect[3]) +{ + float coords[ARRAY_SIZE(cube_coords)][3]; + + for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) { + madd_v3_v3v3v3(coords[i], co, cube_coords[i], aspect); + } + + immBegin(GWN_PRIM_TRIS, ARRAY_SIZE(cube_quad_index) * 3 * 2); + for (int i = 0; i < ARRAY_SIZE(cube_quad_index); i++) { + immVertex3fv(pos, coords[cube_quad_index[i][0]]); + immVertex3fv(pos, coords[cube_quad_index[i][1]]); + immVertex3fv(pos, coords[cube_quad_index[i][2]]); + + immVertex3fv(pos, coords[cube_quad_index[i][0]]); + immVertex3fv(pos, coords[cube_quad_index[i][2]]); + immVertex3fv(pos, coords[cube_quad_index[i][3]]); + } + immEnd(); +} + +void imm_draw_cube_wire_3d(uint pos, const float co[3], const float aspect[3]) +{ + float coords[ARRAY_SIZE(cube_coords)][3]; + + for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) { + madd_v3_v3v3v3(coords[i], co, cube_coords[i], aspect); + } + + immBegin(GWN_PRIM_LINES, ARRAY_SIZE(cube_line_index) * 2); + for (int i = 0; i < ARRAY_SIZE(cube_line_index); i++) { + immVertex3fv(pos, coords[cube_line_index[i][0]]); + immVertex3fv(pos, coords[cube_line_index[i][1]]); + } + immEnd(); +} + /** * Draw a cylinder. Replacement for gluCylinder. * _warning_ : Slow, better use it only if you no other choices. |