VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_tiles.c@ 15532

Last change on this file since 15532 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include <stdlib.h>
8#include "server.h"
9#include "cr_mem.h"
10#include "cr_warp.h"
11#include "cr_hull.h"
12#include "cr_string.h"
13
14
15/*
16 * Given the mural->extents[i].imagewindow parameters, compute the
17 * mural->extents[i].bounds and outputwindow parameters.
18 * This includes allocating space in the render SPU's window for each
19 * of the tiles.
20 */
21static void
22initializeExtents(CRMuralInfo *mural)
23{
24 const int leftMargin = cr_server.useL2 ? 2 : 0;
25 int i;
26 int x, y, w, h, maxTileHeight;
27
28 x = leftMargin;
29 y = 0;
30 maxTileHeight = 0;
31
32 /* Basically just copy the server's list of tiles to the RunQueue
33 * and compute some derived tile information.
34 */
35 for ( i = 0; i < mural->numExtents; i++ )
36 {
37 CRExtent *extent = &mural->extents[i];
38
39 CRASSERT(mural->width > 0);
40 CRASSERT(mural->height > 0);
41
42 /* extent->display = find_output_display( extent->imagewindow ); */
43
44 /* Compute normalized tile bounds.
45 * That is, x1, y1, x2, y2 will be in the range [-1, 1] where
46 * x1=-1, y1=-1, x2=1, y2=1 corresponds to the whole mural.
47 */
48 extent->bounds.x1 = ( (GLfloat) (2*extent->imagewindow.x1) /
49 mural->width - 1.0f );
50 extent->bounds.y1 = ( (GLfloat) (2*extent->imagewindow.y1) /
51 mural->height - 1.0f );
52 extent->bounds.x2 = ( (GLfloat) (2*extent->imagewindow.x2) /
53 mural->width - 1.0f );
54 extent->bounds.y2 = ( (GLfloat) (2*extent->imagewindow.y2) /
55 mural->height - 1.0f );
56
57 /* Width and height of tile, in mural pixels */
58 w = mural->extents[i].imagewindow.x2 - mural->extents[i].imagewindow.x1;
59 h = mural->extents[i].imagewindow.y2 - mural->extents[i].imagewindow.y1;
60
61 if (cr_server.useDMX) {
62 /* Tile layout is easy!
63 * Remember, the X window we're drawing into (tileosort::xsubwin)
64 * is already adjusted to the right mural position.
65 */
66 extent->outputwindow.x1 = 0;
67 extent->outputwindow.y1 = 0;
68 extent->outputwindow.x2 = w;
69 extent->outputwindow.y2 = h;
70#if 0
71 printf("OutputWindow %d, %d .. %d, %d\n",
72 extent->outputwindow.x1,
73 extent->outputwindow.y1,
74 extent->outputwindow.x2,
75 extent->outputwindow.y2);
76#endif
77 }
78 else {
79 /* Carve space out of the underlying (render SPU) window for this tile.
80 */
81 if ( x + w > (int) mural->underlyingDisplay[2] )
82 {
83 if (x == leftMargin) {
84 crWarning("No room for %dx%d tile in this server's window (%d x %d)!",
85 w, h,
86 mural->underlyingDisplay[2], mural->underlyingDisplay[3]);
87 }
88 y += maxTileHeight;
89 x = leftMargin;
90 maxTileHeight = 0;
91 }
92
93 /* Allocate space from window in bottom-to-top order.
94 * This allows multi-level tilesort configurations to work better.
95 */
96 extent->outputwindow.x1 = x;
97 extent->outputwindow.y1 = y;
98 extent->outputwindow.x2 = x + w;
99 extent->outputwindow.y2 = y + h;
100
101 if ((unsigned int)extent->outputwindow.y2 > mural->underlyingDisplay[3])
102 crWarning("No room for %dx%d tile in this server's window (%d x %d)!",
103 w, h,
104 mural->underlyingDisplay[2], mural->underlyingDisplay[3]);
105
106 if (h > maxTileHeight)
107 maxTileHeight = h;
108
109 x += w + leftMargin;
110 } /* useDMX */
111 }
112}
113
114
115/*
116 * This needs to be called when the tiling changes. Compute max tile
117 * height and check if optimized bucketing can be used, etc.
118 */
119void
120crServerInitializeTiling(CRMuralInfo *mural)
121{
122 int i;
123
124 /* The imagespace rect is useful in a few places (but redundant) */
125 /* XXX not used anymore??? (grep) */
126 mural->imagespace.x1 = 0;
127 mural->imagespace.y1 = 0;
128 mural->imagespace.x2 = mural->width;
129 mural->imagespace.y2 = mural->height;
130
131 /* find max tile height */
132 mural->maxTileHeight = 0;
133 for (i = 0; i < mural->numExtents; i++)
134 {
135 const int h = mural->extents[i].imagewindow.y2 -
136 mural->extents[i].imagewindow.y1;
137
138 if (h > mural->maxTileHeight)
139 mural->maxTileHeight = h;
140 }
141
142 /* compute extent bounds, outputwindow, etc */
143 initializeExtents(mural);
144
145 /* optimized hash-based bucketing setup */
146 if (cr_server.optimizeBucket) {
147 mural->optimizeBucket = crServerInitializeBucketing(mural);
148 }
149 else {
150 mural->optimizeBucket = GL_FALSE;
151 }
152}
153
154
155/*
156 * Change the tiling for a mural.
157 * The boundaries are specified in mural space.
158 * Input: muralWidth/muralHeight - new window/mural size
159 * numTiles - number of tiles
160 * Input: tileBounds[0] = bounds[0].x
161 * tileBounds[1] = bounds[0].y
162 * tileBounds[2] = bounds[0].width
163 * tileBounds[3] = bounds[0].height
164 * tileBounds[4] = bounds[1].x
165 * ...
166 */
167void
168crServerNewMuralTiling(CRMuralInfo *mural,
169 GLint muralWidth, GLint muralHeight,
170 GLint numTiles, const GLint *tileBounds)
171{
172 int i;
173
174 CRASSERT(numTiles >= 0);
175
176 crDebug("Reconfiguring tiles in crServerNewMuralTiling:");
177 crDebug(" New mural size: %d x %d", muralWidth, muralHeight);
178 for (i = 0; i < numTiles; i++)
179 {
180 crDebug(" Tile %d: %d, %d %d x %d", i,
181 tileBounds[i*4], tileBounds[i*4+1],
182 tileBounds[i*4+2], tileBounds[i*4+3]);
183 }
184
185 /*
186 * This section basically mimics what's done during crServerGetTileInfo()
187 */
188 mural->width = muralWidth;
189 mural->height = muralHeight;
190 mural->numExtents = numTiles;
191 for (i = 0; i < numTiles; i++)
192 {
193 const GLint x = tileBounds[i * 4 + 0];
194 const GLint y = tileBounds[i * 4 + 1];
195 const GLint w = tileBounds[i * 4 + 2];
196 const GLint h = tileBounds[i * 4 + 3];
197 mural->extents[i].imagewindow.x1 = x;
198 mural->extents[i].imagewindow.y1 = y;
199 mural->extents[i].imagewindow.x2 = x + w;
200 mural->extents[i].imagewindow.y2 = y + h;
201 }
202
203 crServerInitializeTiling(mural);
204}
205
206
207static float
208absf(float a)
209{
210 if (a < 0)
211 return -a;
212 return a;
213}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette