summaryrefslogtreecommitdiffstats
path: root/applications/rview/cube_render_line.c
blob: 6c40e6ddfa98b7b0ba05916ef21af97854b02c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* This file is part of rasdaman community.
*
* Rasdaman community 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 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community 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 rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/

/**
 *  COMMENTS:
 *
 *  This is called from within cube_render.c to render a line. It has been
 *  moved out here to be able to easily optimise the whole system for various
 *  settings and simplify the use of different texture base sizes.
 */



    i = (8 - (ge->midx + renderDesc->left_p)) & 7;
    if ((i > width) || (width < 8)) i = width;
    while (i > 0)
    {
      width -= i;
      nom -= ((real_t)i) * left_g->z; den -= ((real_t)i) * deltaLR_g.z; h = 0.0;
      if (den != 0)
      {
        h = -nom/den;
	if (h < 0.0) h = 0.0;
        if (h > 1.0) h = 1.0;
      }
#ifndef TEXEL_CONST_X
      dtx = ((int32)(left_t->x + h * deltaLR_t.x) - tx) / i;
#endif
#ifndef TEXEL_CONST_Y
      dty = ((int32)(left_t->y + h * deltaLR_t.y) - ty) / i;
#endif
#ifndef TEXEL_CONST_Z
      dtz = ((int32)(left_t->z + h * deltaLR_t.z) - tz) / i;
#endif
      while (i > 0)
      {
#if (CUBE_RENDER_DEBUG > 2)
	printf("\t(%d, %d, %d: %d)\n", (tx>>FIXPOINT_PREC), (ty>>FIXPOINT_PREC), (tz>>FIXPOINT_PREC), ((tx>>FIXPOINT_PREC)*dimy + (ty>>FIXPOINT_PREC))*dimz + (tz>>FIXPOINT_PREC)); fflush(stdout);
#endif
#if (CUBE_RENDER_DEBUG > 0)
	if (((tx>>FIXPOINT_PREC)*dimy + (ty>>FIXPOINT_PREC))*dimz + (tz>>FIXPOINT_PREC) > high_tide_src)
	{
	  printf("Texture buffer overflow (%d, %d, %d) | (%f, %f, %f)!\n", (tx>>FIXPOINT_PREC), (ty>>FIXPOINT_PREC), (tz>>FIXPOINT_PREC), left_t->x + deltaLR_t.x, left_t->y + deltaLR_t.y, left_t->z + deltaLR_t.z); fflush(stdout); break;
	}
        if (dest.c > high_tide_dest)
	{
	  printf("Screen buffer overflow (%d)!\n", (int)(high_tide_dest - (uint8*)(ge->dest)));
          fflush(stdout); break;
	}
#endif
	TEXEL_ASSIGN;
	i--;
      }
      if (width < 8) i = width;
    }
    if (width <= 0) continue;
    /* The above loop guarantees that at this point width >= 8 */
    dn = (real_t)(-8.0 * left_g->z); dd = (real_t)(-8.0 * deltaLR_g.z);
    nom += dn; den += dd; h = 0.0;
    if (den != 0)
    {
      h = -nom/den;
      if (h < 0.0) h = 0.0;
      if (h > 1.0) h = 1.0;
    }
#ifndef TEXEL_CONST_X
    dtx = ((int32)(left_t->x + h * deltaLR_t.x) - tx) / 8;
#endif
#ifndef TEXEL_CONST_Y
    dty = ((int32)(left_t->y + h * deltaLR_t.y) - ty) / 8;
#endif
#ifndef TEXEL_CONST_Z
    dtz = ((int32)(left_t->z + h * deltaLR_t.z) - tz) / 8;
#endif

    /* Help the compiler do efficient Int/FP parallelism. */
    while (width >= 16)
    {
      width -= 8; h = 0.0;
      nom += dn;
      TEXEL_ACCU_0(accu_t);
      den += dd;
      TEXEL_ACCU_1(accu_t);
      if (den != 0) h = -nom/den;
      TEXEL_ACCU_2(accu_t);
      if (h < 0.0) h = 0.0;
      TEXEL_ACCU_3(accu_t);
      if (h > 1.0) h = 1.0;
      TEXEL_ACCU_0(accu_t);
#ifndef TEXEL_CONST_X
      ntx = (int32)(left_t->x + h * deltaLR_t.x);
#endif
      TEXEL_ACCU_1(accu_t);
#ifndef TEXEL_CONST_Y
      nty = (int32)(left_t->y + h * deltaLR_t.y);
#endif
      TEXEL_ACCU_2(accu_t);
#ifndef TEXEL_CONST_Z
      ntz = (int32)(left_t->z + h * deltaLR_t.z);
#endif
      TEXEL_ACCU_3(accu_t);
#ifndef TEXEL_CONST_X
      dtx = (ntx - tx) / 8;
#endif
#ifndef TEXEL_CONST_Y
      dty = (nty - ty) / 8;
#endif
#ifndef TEXEL_CONST_Z
      dtz = (ntz - tz) / 8;
#endif
    }
    /* 8 <= width <= 15 here! */
    width -= 8; h = 0.0;
    nom -= ((real_t)width) * left_g->z;
    TEXEL_ACCU_0(accu_t);
    den -= ((real_t)width) * deltaLR_g.z;
    TEXEL_ACCU_1(accu_t);
    if (den != 0) h = -nom/den;
    TEXEL_ACCU_2(accu_t);
    if (h < 0.0) h = 0.0;
    TEXEL_ACCU_3(accu_t);
    if (h > 1.0) h = 1.0;
    TEXEL_ACCU_0(accu_t);
#ifndef TEXEL_CONST_X
    ntx = (int32)(left_t->x + h * deltaLR_t.x);
#endif
    TEXEL_ACCU_1(accu_t);
#ifndef TEXEL_CONST_Y
    nty = (int32)(left_t->y + h * deltaLR_t.y);
#endif
    TEXEL_ACCU_2(accu_t);
#ifndef TEXEL_CONST_Z
    ntz = (int32)(left_t->z + h * deltaLR_t.z);
#endif
    TEXEL_ACCU_3(accu_t);
    if (width > 0)
    {
#ifndef TEXEL_CONST_X
      dtx = (ntx - tx) / width;
#endif
#ifndef TEXEL_CONST_Y
      dty = (nty - ty) / width;
#endif
#ifndef TEXEL_CONST_Z
      dtz = (ntz - tz) / width;
#endif
      while (width > 0)
      {
	TEXEL_ASSIGN;
	width--;
      }
    }