8#if defined(GLUP_TESS_GATHER)
11 vec4 vertex_clip_space[glup_nb_vertices_per_GL_v];
12 vec4 color[glup_nb_vertices_per_GL_v];
13 vec4 tex_coord[glup_nb_vertices_per_GL_v];
14#ifndef GLUP_TESS_MULTI_VERTEX
19#elif defined(GLUP_VERTEX_GATHER)
22 vec4 other_vertex_clip_space[glup_nb_vertices_per_GL_v-1];
23 vec4 color[glup_nb_vertices_per_GL_v];
24 vec4 tex_coord[glup_nb_vertices_per_GL_v];
32#if GLUP_PRIMITIVE_DIMENSION==2
40 vec4 vertex_clip_space;
43#if GLUP_PRIMITIVE_DIMENSION==2
49#ifndef GLUP_NO_GL_CLIPPING
50out
float gl_ClipDistance[];
55#if defined(GLUP_VERTEX_GATHER) || defined(GLUP_TESS_GATHER)
57# if defined(GLUP_VERTEX_GATHER)
58vec4 vertex_clip_space_in(in
int i) {
59 int i0 = i / glup_nb_vertices_per_GL_v;
60 int i1 = i % glup_nb_vertices_per_GL_v;
61 return (i1==0) ? gl_in[i0].gl_Position :
62 VertexIn[i0].other_vertex_clip_space[i1-1];
65vec4 vertex_clip_space_in(in
int i) {
66 int i0 = i / glup_nb_vertices_per_GL_v;
67 int i1 = i % glup_nb_vertices_per_GL_v;
68 return VertexIn[i0].vertex_clip_space[i1];
72vec4 color_in(in
int i) {
73 int i0 = i / glup_nb_vertices_per_GL_v;
74 int i1 = i % glup_nb_vertices_per_GL_v;
75 return VertexIn[i0].color[i1];
78vec4 tex_coord_in(in
int i) {
79 int i0 = i / glup_nb_vertices_per_GL_v;
80 int i1 = i % glup_nb_vertices_per_GL_v;
81 return VertexIn[i0].tex_coord[i1];
84bool prim_is_discarded() {
85#if defined(GLUP_TESS_GATHER) && !defined(GLUP_TESS_MULTI_VERTEX)
86 return VertexIn[0].discard_me;
93vec4 vertex_clip_space_in(in
int i) {
94 return gl_in[i].gl_Position;
97vec4 color_in(in
int i) {
98 return VertexIn[i].color;
101vec4 tex_coord_in(in
int i) {
102 return VertexIn[i].tex_coord;
105#if GLUP_PRIMITIVE_DIMENSION==2
106vec3 normal_in(in
int i) {
107 return VertexIn[i].normal;
111bool prim_is_discarded() {
119vec4 vertex_clip_space[glup_primitive_nb_vertices];
122 for(
int v=0; v<glup_primitive_nb_vertices; ++v) {
123 vertex_clip_space[v] = vertex_clip_space_in(v);
125 if(GLUP.cells_shrink != 0.0) {
127 for(
int i=0; i<glup_primitive_nb_vertices; ++i) {
128 g += vertex_clip_space[i];
130 g /= float(glup_primitive_nb_vertices);
131 float s = GLUP.cells_shrink;
132 for(
int i=0; i<glup_primitive_nb_vertices; ++i) {
133 vertex_clip_space[i] = mix(vertex_clip_space[i], g, s);
138float clip_distance(in vec4 V, in
bool do_clip) {
139 return do_clip?
dot(V,GLUP.clip_clip_plane):1.0;
142bool cell_is_clipped() {
143 if(prim_is_discarded()) {
147 (glup_primitive_dimension != 3) ||
148 !glupIsEnabled(GLUP_CLIPPING) ||
149 (GLUP.clipping_mode==GLUP_CLIP_STANDARD) ||
150 (GLUP.clipping_mode==GLUP_CLIP_SLICE_CELLS)
155 for(
int i=0; i<glup_primitive_nb_vertices; ++i) {
156 count += int(clip_distance(vertex_clip_space_in(i),
true) >= 0.0);
159 (GLUP.clipping_mode==GLUP_CLIP_WHOLE_CELLS) && (count == 0)
164 (GLUP.clipping_mode==GLUP_CLIP_STRADDLING_CELLS) &&
165 ((count==0) || (count==glup_primitive_nb_vertices))
173 if(GLUP.clipping_mode==GLUP_CLIP_SLICE_CELLS) {
180void emit_vertex(in
int i, in vec4 mesh_tex_coord, in
bool do_clip) {
181#ifndef GLUP_NO_GL_CLIPPING
182 if(glupIsEnabled(GLUP_CLIPPING)) {
183 gl_ClipDistance[0] = clip_distance(vertex_clip_space_in(i),do_clip);
186 gl_Position = vertex_clip_space[i];
187 VertexOut.vertex_clip_space = gl_Position;
188 if(glupIsEnabled(GLUP_VERTEX_COLORS)) {
189 VertexOut.color = color_in(i);
191 if(glupIsEnabled(GLUP_TEXTURING)) {
192 VertexOut.tex_coord = tex_coord_in(i);
194#if GLUP_PRIMITIVE_DIMENSION==2
196 glupIsEnabled(GLUP_LIGHTING) &&
197 glupIsEnabled(GLUP_VERTEX_NORMALS)) {
198 VertexOut.normal = normal_in(i);
201 if(glupIsEnabled(GLUP_DRAW_MESH)) {
202 VertexOut.mesh_tex_coord = mesh_tex_coord;
207void draw_triangle(in
int i1, in
int i2, in
int i3, in
bool do_clip) {
208 emit_vertex(i1,
vec4(1.0, 0.0, 0.0, 0.0), do_clip);
209 emit_vertex(i2,
vec4(0.0, 1.0, 0.0, 0.0), do_clip);
210 emit_vertex(i3,
vec4(0.0, 0.0, 1.0, 0.0), do_clip);
214void draw_quad(in
int i1, in
int i2, in
int i3, in
int i4, in
bool do_clip) {
215 emit_vertex(i1,
vec4(0.0, 1.0, 0.0, 1.0), do_clip);
216 emit_vertex(i2,
vec4(1.0, 0.0, 0.0, 1.0), do_clip);
217 emit_vertex(i3,
vec4(0.0, 1.0, 1.0, 0.0), do_clip);
218 emit_vertex(i4,
vec4(1.0, 0.0, 1.0, 0.0), do_clip);
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.