e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/* Copyright (c) 2001, Stanford University
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * All rights reserved
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * See the file LICENSE.txt for information on redistributing this software.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Clip the rectangle q against the given image window.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrServerViewportClipToWindow( const CRrecti *imagewindow, CRrecti *q)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->x1 < imagewindow->x1) q->x1 = imagewindow->x1;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->x1 > imagewindow->x2) q->x1 = imagewindow->x2;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->x2 > imagewindow->x2) q->x2 = imagewindow->x2;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->x2 < imagewindow->x1) q->x2 = imagewindow->x1;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->y1 < imagewindow->y1) q->y1 = imagewindow->y1;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->y1 > imagewindow->y2) q->y1 = imagewindow->y2;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->y2 > imagewindow->y2) q->y2 = imagewindow->y2;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (q->y2 < imagewindow->y1) q->y2 = imagewindow->y1;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Translate the rectangle q from the image window space to the outputwindow
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrServerConvertToOutput( const CRrecti *imagewindow,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync q->x1 = q->x1 - imagewindow->x1 + outputwindow->x1;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync q->x2 = q->x2 - imagewindow->x2 + outputwindow->x2;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync q->y1 = q->y1 - imagewindow->y1 + outputwindow->y1;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync q->y2 = q->y2 - imagewindow->y2 + outputwindow->y2;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Compute clipped image window, scissor, viewport and base projection
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * info for each tile in the mural.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Need to call this when either the viewport or mural is changed.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrServerComputeViewportBounds(const CRViewportState *v, CRMuralInfo *mural)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* If the scissor is disabled set it to the whole output.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync ** We might as well use the actual scissorTest rather than
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync ** scissorValid - it never gets reset anyway.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crServerViewportClipToWindow(&(extent->imagewindow), &q);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* if the viewport is not valid,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync ** set it to the entire output.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* This is where the viewport gets clamped to the max size. */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crServerViewportClipToWindow(&(extent->imagewindow), &q);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync ** Now, compute the base projection.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (extent->clippedImagewindow.x1 == extent->clippedImagewindow.x2 ||
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync extent->clippedImagewindow.y1 == extent->clippedImagewindow.y2) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* zero-area extent, use identity matrix (doesn't really matter) */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * We need to take account of the current viewport parameters,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * and they are passed to this function as x, y, w, h.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * In the default case (from main.c) we pass the the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * full muralsize of 0, 0, width, height
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync p.x1 = (GLfloat) (extent->clippedImagewindow.x1 - vpx) / vpw;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync p.y1 = (GLfloat) (extent->clippedImagewindow.y1 - vpy) / vph;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync p.x2 = (GLfloat) (extent->clippedImagewindow.x2 - vpx) / vpw;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync p.y2 = (GLfloat) (extent->clippedImagewindow.y2 - vpy) / vph;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /* XXX not sure this clamping is really need anymore
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Rescale [0,1] -> [-1,1] */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Issue the glScissor, glViewport and projection matrix needed for
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * rendering the tile specified by extNum. We computed the scissor,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * viewport and projection parameters above in crServerComputeViewportBounds.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrServerSetOutputBounds( const CRMuralInfo *mural, int extNum )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Serial Number info:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Everytime we compute new scissor, viewport, projection matrix info for
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * a tile, we give that tile a new serial number.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * When we're about to render into a tile, we only update the scissor,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * viewport and projection matrix if the tile's serial number doesn't match
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * the current serial number. This avoids a _LOT_ of redundant calls to
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * those three functions.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (extent->serialNo != cr_server.currentSerialNo) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.Scissor(extent->scissorBox.x1,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.Viewport(extent->viewport.x1,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crServerApplyBaseProjection(&(extent->baseProjection));
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Pre-multiply the current projection matrix with the current client's
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * base projection. I.e. P' = b * P. Note that OpenGL's glMultMatrix
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * POST-multiplies.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrServerApplyBaseProjection(const CRmatrix *baseProj)
f53ba2efceac1847585b2052ee98569305e9802dvboxsync projMatrix = cr_server.curClient->currentCtxInfo->pContext->transform.projectionStack.top;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.PushAttrib( GL_TRANSFORM_BIT );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.MatrixMode( GL_PROJECTION );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.LoadMatrixf( (const GLfloat *) baseProj );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.MultMatrixf( cr_server.alignment_matrix );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.MultMatrixf( (const GLfloat *) projMatrix );
f53ba2efceac1847585b2052ee98569305e9802dvboxsync const CRmatrix *modelview = cr_server.curClient->currentCtxInfo->pContext->transform.modelViewStack.top;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.PushAttrib( GL_TRANSFORM_BIT );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.MatrixMode( GL_MODELVIEW );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.LoadMatrixf( (const GLfloat *) view );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_server.head_spu->dispatch_table.MultMatrixf( (const GLfloat *) modelview );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Called via unpacker module.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Note: when there's a tilesort SPU upstream, the viewport dimensions
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * will typically match the mural size. That is, the viewport dimensions
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * probably won't be the same values that the application issues.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid SERVER_DISPATCH_APIENTRY crServerDispatchViewport( GLint x, GLint y, GLsizei width, GLsizei height )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync CRMuralInfo *mural = cr_server.curClient->currentMural;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Note -- If there are tiles, this will be overridden in the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * process of decoding the BoundsInfo packet, so no worries. */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* always dispatch to be safe */