示例#1
0
/**
 * Fill in the span.zArray array from the span->z, zStep values.
 */
void
_swrast_span_interpolate_z( const struct gl_context *ctx, SWspan *span )
{
   const GLuint n = span->end;
   GLuint i;

   ASSERT(!(span->arrayMask & SPAN_Z));

   if (ctx->DrawBuffer->Visual.depthBits <= 16) {
      GLfixed zval = span->z;
      GLuint *z = span->array->z; 
      for (i = 0; i < n; i++) {
         z[i] = FixedToInt(zval);
         zval += span->zStep;
      }
   }
   else {
      /* Deep Z buffer, no fixed->int shift */
      GLuint zval = span->z;
      GLuint *z = span->array->z;
      for (i = 0; i < n; i++) {
         z[i] = zval;
         zval += span->zStep;
      }
   }
   span->interpMask &= ~SPAN_Z;
   span->arrayMask |= SPAN_Z;
}
示例#2
0
extern	Bool
ValueToBool(
	ValueStruct	*val)
{
	Bool	ret;

	if		(  val  ==  NULL  ) {
		ret = FALSE;
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		ret = ( *ValueString(val) == 'T' ) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_NUMBER:
		ret = FixedToInt(&ValueFixed(val)) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_INT:
		ret = ValueInteger(val) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_FLOAT:
		ret = (int)ValueFloat(val) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_BOOL:
		ret = ValueBool(val);
		break;
	  default:
		ret = FALSE;
	}
	return	(ret);
}
SOM_Scope void  SOMLINK ShapePartDrawFrame(ShapePart *somSelf,
                                            Environment *ev,
                                            ODFacet* facet,
                                            ODShape* invalidShape)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartDrawFrame");

    ODFrame* displayFrame = facet->GetFrame(ev);
    TempODShape shape = displayFrame->AcquireFrameShape(ev, facet->GetCanvas(ev));
    ODRect rect;
    shape->GetBoundingBox(ev, &rect);


#if defined(_PLATFORM_WIN32_)
    Rect frameRect;
    SetRect(&frameRect, FixedToInt(rect.left),
                       FixedToInt(rect.top),
                       FixedToInt(rect.right),
                       FixedToInt(rect.bottom));

    HDC hdc;
    CFocus focus(facet, invalidShape, &hdc);

    HBRUSH hbr = CreateSolidBrush (_fBackgroundColor);
    FillRect (hdc, &frameRect, hbr);
    DeleteObject (hbr);

#elif defined (_PLATFORM_OS2_)

    RECTL frameRect;
    frameRect.xLeft = FixedToInt(rect.left);
    frameRect.yTop  = FixedToInt(rect.top);
    frameRect.xRight  = FixedToInt(rect.right);
    frameRect.yBottom  = FixedToInt(rect.bottom);

    HPS hdc;
    CFocus focus(facet, invalidShape, &hdc);

    GpiCreateLogColorTable (hdc, 0L, LCOLF_RGB, 0L, 0L, 0L);
    GpiSetColor(hdc, _fBackgroundColor);
    POINTL orig = {0, 0};
    GpiMove(hdc, &orig);
    POINTL ptl = {frameRect.xRight, frameRect.yTop};
    GpiBox(hdc, DRO_FILL, &ptl, 0, 0);


#endif
}
示例#4
0
static struct opengl_sc_bounding_box_t *opengl_sc_bounding_box_create(struct opengl_pa_triangle_t *triangle)
{
	struct opengl_sc_bounding_box_t *bbox;
	float xmin;
	float xmax;
	float ymin;
	float ymax;
	float span;
	int snapMask;
	int s;
	int k;

	/* Allocate */
	bbox = xcalloc(1, sizeof(struct opengl_sc_bounding_box_t));	

	/* Find the length of the span */
	xmin = MIN(triangle->vtx0->pos[X_COMP], MIN(triangle->vtx1->pos[X_COMP], triangle->vtx2->pos[X_COMP]));
	xmax = MAX(triangle->vtx0->pos[X_COMP], MAX(triangle->vtx1->pos[X_COMP], triangle->vtx2->pos[X_COMP]));
	ymin = MIN(triangle->vtx0->pos[Y_COMP], MIN(triangle->vtx1->pos[Y_COMP], triangle->vtx2->pos[Y_COMP]));
	ymax = MAX(triangle->vtx0->pos[Y_COMP], MAX(triangle->vtx1->pos[Y_COMP], triangle->vtx2->pos[Y_COMP]));
	span = MAX(xmax - xmin, ymax - ymin);
	s = IROUND(span);

	/* Calculate bounding box size */
	k = 0;
	do
	{
		k++;
	} while (s > (2<<k));

	/* Snapping to nearest subpixel grid */
	snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1); 
	bbox->x0 = FixedToInt(FloatToFixed(xmin - 0.5F) & snapMask);
	bbox->y0 = FixedToInt(FloatToFixed(ymin - 0.5F) & snapMask);
	bbox->size = 2<<k;

	/* Return */
	return bbox;
}
void
qtCanvas::Impl::setupSCComponent()
{
	OSErr err;
	
    err = EnterMovies();
    CheckError (err, "EnterMovies error" );

	mSCComponent = OpenDefaultComponent(
						StandardCompressionType,
						StandardCompressionSubType);
	CheckMoviesError("OpenDefaultComponent");

	if (sSCSettings) {
		SCSetInfo(mSCComponent, scSettingsStateType, &sSCSettings);
	}
	else {
		SCSpatialSettings	spatial;
		SCTemporalSettings	temporal;
		long				preference;
		CodecFlags			codecFlags;
		
		spatial.codecType = kAnimationCodecType;
		spatial.codec = NULL;
		spatial.depth = 32; // reset when the preview is set up
		spatial.spatialQuality = codecNormalQuality;
		
		temporal.temporalQuality = codecNormalQuality;
		temporal.frameRate = FloatToFixed(15.0);
		temporal.keyFrameRate = FixedToInt(temporal.frameRate) * 2;
		
		preference = scListEveryCodec;
		//preference |= scShowBestDepth;
		//preference |= scUseMovableModal;
		
		codecFlags = codecFlagUpdatePreviousComp;
		
		SCSetInfo(mSCComponent, scSpatialSettingsType, &spatial);
		SCSetInfo(mSCComponent, scTemporalSettingsType, &temporal);
		SCSetInfo(mSCComponent, scPreferenceFlagsType, &preference);
		SCSetInfo(mSCComponent, scCodecFlagsType, &codecFlags);
	}
}
示例#6
0
extern	int
ValueToInteger(
	ValueStruct	*val)
{
	int		ret;

	if		(  val  ==  NULL  ) {
		ret = 0;
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		ret = StrToInt(ValueString(val),strlen(ValueString(val)));
		break;
	  case	GL_TYPE_NUMBER:
		ret = FixedToInt(&ValueFixed(val));
		break;
	  case	GL_TYPE_INT:
		ret = ValueInteger(val);
		break;
	  case	GL_TYPE_FLOAT:
		ret = (int)ValueFloat(val);
		break;
	  case	GL_TYPE_BOOL:
		ret = ValueBool(val);
		break;
	  case	GL_TYPE_OBJECT:
		ret = ValueObjectId(val);
		break;
	  case	GL_TYPE_TIMESTAMP:
	  case	GL_TYPE_DATE:
	  case	GL_TYPE_TIME:
		ret = (int)mktime(&ValueDateTime(val));
		break;
	  default:
		ret = 0;
	}
	return	(ret);
}
示例#7
0
PlatformFont::CharInfo& MacCarbFont::getCharInfo(const UTF16 ch) const
{
   // We use some static data here to avoid re allocating the same variable in a loop.
   // this func is primarily called by GFont::loadCharInfo(),
   Rect                 imageRect;
   CGContextRef         imageCtx;
   U32                  bitmapDataSize;
   ATSUTextMeasurement  tbefore, tafter, tascent, tdescent;
   OSStatus             err;

   // 16 bit character buffer for the ATUSI calls.
   // -- hey... could we cache this at the class level, set style and loc *once*, 
   //    then just write to this buffer and clear the layout cache, to speed up drawing?
   static UniChar chUniChar[1];
   chUniChar[0] = ch;

   // Declare and clear out the CharInfo that will be returned.
   static PlatformFont::CharInfo c;
   dMemset(&c, 0, sizeof(c));
   
   // prep values for GFont::addBitmap()
   c.bitmapIndex = 0;
   c.xOffset = 0;
   c.yOffset = 0;

   // put the text in the layout.
   // we've hardcoded a string length of 1 here, but this could work for longer strings... (hint hint)
   // note: ATSUSetTextPointerLocation() also clears the previous cached layout information.
   ATSUSetTextPointerLocation( mLayout, chUniChar, 0, 1, 1);
   ATSUSetRunStyle( mLayout, mStyle, 0,1);
   
   // get the typographic bounds. this tells us how characters are placed relative to other characters.
   ATSUGetUnjustifiedBounds( mLayout, 0, 1, &tbefore, &tafter, &tascent, &tdescent);
   c.xIncrement =  FixedToInt(tafter);
   
   // find out how big of a bitmap we'll need.
   // as a bonus, we also get the origin where we should draw, encoded in the Rect.
   ATSUMeasureTextImage( mLayout, 0, 1, 0, 0, &imageRect);
   U32 xFudge = 2;
   U32 yFudge = 1;
   c.width  = imageRect.right - imageRect.left + xFudge; // add 2 because small fonts don't always have enough room
   c.height = imageRect.bottom - imageRect.top + yFudge;
   c.xOrigin = imageRect.left; // dist x0 -> center line
   c.yOrigin = -imageRect.top; // dist y0 -> base line
   
   // kick out early if the character is undrawable
   if( c.width == xFudge || c.height == yFudge)
      return c;
   
   // allocate a greyscale bitmap and clear it.
   bitmapDataSize = c.width * c.height;
   c.bitmapData = new U8[bitmapDataSize];
   dMemset(c.bitmapData,0x00,bitmapDataSize);
   
   // get a graphics context on the bitmap
   imageCtx = CGBitmapContextCreate( c.bitmapData, c.width, c.height, 8, c.width, mColorSpace, kCGImageAlphaNone);
   if(!imageCtx) {
      Con::errorf("Error: failed to create a graphics context on the CharInfo bitmap! Drawing a blank block.");
      c.xIncrement = c.width;
      dMemset(c.bitmapData,0x0F,bitmapDataSize);
      return c;
   }

   // Turn off antialiasing for monospaced console fonts. yes, this is cheating.
   if(mSize < 12  && ( dStrstr(mName,"Monaco")!=NULL || dStrstr(mName,"Courier")!=NULL ))
      CGContextSetShouldAntialias(imageCtx, false);

   // Set up drawing options for the context.
   // Since we're not going straight to the screen, we need to adjust accordingly
   CGContextSetShouldSmoothFonts(imageCtx, false);
   CGContextSetRenderingIntent(imageCtx, kCGRenderingIntentAbsoluteColorimetric);
   CGContextSetInterpolationQuality( imageCtx, kCGInterpolationNone);
   CGContextSetGrayFillColor( imageCtx, 1.0, 1.0);
   CGContextSetTextDrawingMode( imageCtx,  kCGTextFill);
   
   // tell ATSUI to substitute fonts as needed for missing glyphs
   ATSUSetTransientFontMatching(mLayout, true); 

   // set up three parrallel arrays for setting up attributes. 
   // this is how most options in ATSUI are set, by passing arrays of options.
   ATSUAttributeTag theTags[] = { kATSUCGContextTag };
   ByteCount theSizes[] = { sizeof(CGContextRef) };
   ATSUAttributeValuePtr theValues[] = { &imageCtx };
   
   // bind the layout to the context.
   ATSUSetLayoutControls( mLayout, 1, theTags, theSizes, theValues );

   // Draw the character!
   int yoff = c.height < 3 ? 1 : 0; // kludge for 1 pixel high characters, such as '-' and '_'
   int xoff = 1;
   err = ATSUDrawText( mLayout, 0, 1, IntToFixed(-imageRect.left + xoff), IntToFixed(imageRect.bottom + yoff ) );
   CGContextRelease(imageCtx);
   
   if(err != noErr) {
      Con::errorf("Error: could not draw the character! Drawing a blank box.");
      dMemset(c.bitmapData,0x0F,bitmapDataSize);
   }


#if TORQUE_DEBUG
//   Con::printf("Font Metrics: Rect = %2i %2i %2i %2i  Char= %C, 0x%x  Size= %i, Baseline= %i, Height= %i",imageRect.top, imageRect.bottom, imageRect.left, imageRect.right,ch,ch, mSize,mBaseline, mHeight);
//   Con::printf("Font Bounds:  left= %2i right= %2i  Char= %C, 0x%x  Size= %i",FixedToInt(tbefore), FixedToInt(tafter), ch,ch, mSize);
#endif
      
   return c;
}
示例#8
0
/**
 * Interpolate primary colors to fill in the span->array->rgba8 (or rgb16)
 * color array.
 */
static inline void
interpolate_int_colors(struct gl_context *ctx, SWspan *span)
{
#if CHAN_BITS != 32
   const GLuint n = span->end;
   GLuint i;

   ASSERT(!(span->arrayMask & SPAN_RGBA));
#endif

   switch (span->array->ChanType) {
#if CHAN_BITS != 32
   case GL_UNSIGNED_BYTE:
      {
         GLubyte (*rgba)[4] = span->array->rgba8;
         if (span->interpMask & SPAN_FLAT) {
            GLubyte color[4];
            color[RCOMP] = FixedToInt(span->red);
            color[GCOMP] = FixedToInt(span->green);
            color[BCOMP] = FixedToInt(span->blue);
            color[ACOMP] = FixedToInt(span->alpha);
            for (i = 0; i < n; i++) {
               COPY_4UBV(rgba[i], color);
            }
         }
         else {
            GLfixed r = span->red;
            GLfixed g = span->green;
            GLfixed b = span->blue;
            GLfixed a = span->alpha;
            GLint dr = span->redStep;
            GLint dg = span->greenStep;
            GLint db = span->blueStep;
            GLint da = span->alphaStep;
            for (i = 0; i < n; i++) {
               rgba[i][RCOMP] = FixedToChan(r);
               rgba[i][GCOMP] = FixedToChan(g);
               rgba[i][BCOMP] = FixedToChan(b);
               rgba[i][ACOMP] = FixedToChan(a);
               r += dr;
               g += dg;
               b += db;
               a += da;
            }
         }
      }
      break;
   case GL_UNSIGNED_SHORT:
      {
         GLushort (*rgba)[4] = span->array->rgba16;
         if (span->interpMask & SPAN_FLAT) {
            GLushort color[4];
            color[RCOMP] = FixedToInt(span->red);
            color[GCOMP] = FixedToInt(span->green);
            color[BCOMP] = FixedToInt(span->blue);
            color[ACOMP] = FixedToInt(span->alpha);
            for (i = 0; i < n; i++) {
               COPY_4V(rgba[i], color);
            }
         }
         else {
            GLushort (*rgba)[4] = span->array->rgba16;
            GLfixed r, g, b, a;
            GLint dr, dg, db, da;
            r = span->red;
            g = span->green;
            b = span->blue;
            a = span->alpha;
            dr = span->redStep;
            dg = span->greenStep;
            db = span->blueStep;
            da = span->alphaStep;
            for (i = 0; i < n; i++) {
               rgba[i][RCOMP] = FixedToChan(r);
               rgba[i][GCOMP] = FixedToChan(g);
               rgba[i][BCOMP] = FixedToChan(b);
               rgba[i][ACOMP] = FixedToChan(a);
               r += dr;
               g += dg;
               b += db;
               a += da;
            }
         }
      }
      break;
#endif
   case GL_FLOAT:
      interpolate_active_attribs(ctx, span, FRAG_BIT_COL);
      break;
   default:
      _mesa_problem(ctx, "bad datatype 0x%x in interpolate_int_colors",
                    span->array->ChanType);
   }
   span->arrayMask |= SPAN_RGBA;
}
示例#9
0
void raster_tri_rgb_swap_rb(CRasterRGBTriangle2DInfo& info)
{
	if (info.clip_left < 0)
		info.clip_left = 0;
	if (info.clip_right > info.dest_width)
		info.clip_right = info.dest_width;
	if (info.clip_top < 0)
		info.clip_top = 0;
	if (info.clip_bottom > info.dest_height)
		info.clip_bottom = info.dest_height;

	typedef struct
	{
		float* v0, *v1;			/* Y(v0) < Y(v1) */
		float* tv0, *tv1;
		BYTE* cv0, *cv1;
		float dx;				/* X(v1) - X(v0) */
		float dy;				/* Y(v1) - Y(v0) */
		int fdxdy;				/* dx/dy in fixed-point */
		int fsx;				/* first sample point x coord */
		int fsy;
		float adjy;				/* adjust from v[0]->fy to fsy, scaled */
		int lines;				/* number of lines to be sampled on this edge */
		int fx0;				/* fixed pt X of lower endpoint */
	} EdgeT;

	EdgeT eMaj, eTop, eBot;
	float oneOverArea;

	float* vMin, *vMid, *vMax;       /* vertex indices:  Y(vMin)<=Y(vMid)<=Y(vMax) */
	float* tvMin, *tvMid, *tvMax;
	BYTE* cvMin, *cvMid, *cvMax;

	/* find the order of the 3 vertices along the Y axis */
	float y0 = info.v0[1];
	float y1 = info.v1[1];
	float y2 = info.v2[1];

	if (y0 <= y1) {
		if (y1 <= y2) {
			vMin = info.v0;   vMid = info.v1;   vMax = info.v2;   /* y0<=y1<=y2 */
			tvMin = info.tv0;   tvMid = info.tv1;   tvMax = info.tv2;   /* y0<=y1<=y2 */
			cvMin = info.cv0;   cvMid = info.cv1;   cvMax = info.cv2;   /* y0<=y1<=y2 */
		}
		else if (y2 <= y0) {
			vMin = info.v2;   vMid = info.v0;   vMax = info.v1;   /* y2<=y0<=y1 */
			tvMin = info.tv2;   tvMid = info.tv0;   tvMax = info.tv1;   /* y2<=y0<=y1 */
			cvMin = info.cv2;   cvMid = info.cv0;   cvMax = info.cv1;   /* y2<=y0<=y1 */
		}
		else {
			vMin = info.v0;   vMid = info.v2;   vMax = info.v1;   /* y0<=y2<=y1 */
			tvMin = info.tv0;   tvMid = info.tv2;   tvMax = info.tv1;   /* y0<=y2<=y1 */
			cvMin = info.cv0;   cvMid = info.cv2;   cvMax = info.cv1;   /* y0<=y2<=y1 */
		}
	}
	else {
		if (y0 <= y2) {
			vMin = info.v1;   vMid = info.v0;   vMax = info.v2;   /* y1<=y0<=y2 */
			tvMin = info.tv1;   tvMid = info.tv0;   tvMax = info.tv2;   /* y1<=y0<=y2 */
			cvMin = info.cv1;   cvMid = info.cv0;   cvMax = info.cv2;   /* y1<=y0<=y2 */
		}
		else if (y2 <= y1) {
			vMin = info.v2;   vMid = info.v1;   vMax = info.v0;   /* y2<=y1<=y0 */
			tvMin = info.tv2;  tvMid = info.tv1;   tvMax = info.tv0;   /* y2<=y1<=y0 */
			cvMin = info.cv2;  cvMid = info.cv1;   cvMax = info.cv0;   /* y2<=y1<=y0 */
		}
		else {
			vMin = info.v1;   vMid = info.v2;   vMax = info.v0;   /* y1<=y2<=y0 */
			tvMin = info.tv1;   tvMid = info.tv2;   tvMax = info.tv0;   /* y1<=y2<=y0 */
			cvMin = info.cv1;   cvMid = info.cv2;   cvMax = info.cv0;   /* y1<=y2<=y0 */
		}
	}

	/* vertex/edge relationship */
	eMaj.v0 = vMin;   eMaj.v1 = vMax;
	eTop.v0 = vMid;   eTop.v1 = vMax;
	eBot.v0 = vMin;   eBot.v1 = vMid;

	eMaj.tv0 = tvMin;   eMaj.tv1 = tvMax;
	eTop.tv0 = tvMid;   eTop.tv1 = tvMax;
	eBot.tv0 = tvMin;   eBot.tv1 = tvMid;

	eMaj.cv0 = cvMin;   eMaj.cv1 = cvMax;
	eTop.cv0 = cvMid;   eTop.cv1 = cvMax;
	eBot.cv0 = cvMin;   eBot.cv1 = cvMid;

	/* compute deltas for each edge:  vertex[v1] - vertex[v0] */
	eMaj.dx = vMax[0] - vMin[0];
	eMaj.dy = vMax[1] - vMin[1];
	eTop.dx = vMax[0] - vMid[0];
	eTop.dy = vMax[1] - vMid[1];
	eBot.dx = vMid[0] - vMin[0];
	eBot.dy = vMid[1] - vMin[1];

	float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
	if (area > -0.05f && area < 0.05f)
		return;  /* very small; CULLED */

	oneOverArea = 1.0F / area;

	/* fixed point Y coordinates */
	int vMin_fx = FloatToFixed(vMin[0] + 0.5F);
	int vMin_fy = FloatToFixed(vMin[1] - 0.5F);
	int vMid_fx = FloatToFixed(vMid[0] + 0.5F);
	int vMid_fy = FloatToFixed(vMid[1] - 0.5F);
	int vMax_fy = FloatToFixed(vMax[1] - 0.5F);

	eMaj.fsy = FixedCeil(vMin_fy);
	eMaj.lines = FixedToInt(vMax_fy + FIXED_ONE - FIXED_EPSILON - eMaj.fsy);
	if (eMaj.lines > 0)
	{
		float dxdy = eMaj.dx / eMaj.dy;
		eMaj.fdxdy = SignedFloatToFixed(dxdy);
		eMaj.adjy = (float)(eMaj.fsy - vMin_fy);  /* SCALED! */
		eMaj.fx0 = vMin_fx;
		eMaj.fsx = eMaj.fx0 + (int)(eMaj.adjy * dxdy);
	}
	else
		return;  /*CULLED*/

	eTop.fsy = FixedCeil(vMid_fy);
	eTop.lines = FixedToInt(vMax_fy + FIXED_ONE - FIXED_EPSILON - eTop.fsy);
	if (eTop.lines > 0) {
		float dxdy = eTop.dx / eTop.dy;
		eTop.fdxdy = SignedFloatToFixed(dxdy);
		eTop.adjy = (float)(eTop.fsy - vMid_fy); /* SCALED! */
		eTop.fx0 = vMid_fx;
		eTop.fsx = eTop.fx0 + (int)(eTop.adjy * dxdy);
	}

	eBot.fsy = FixedCeil(vMin_fy);
	eBot.lines = FixedToInt(vMid_fy + FIXED_ONE - FIXED_EPSILON - eBot.fsy);
	if (eBot.lines > 0) {
		float dxdy = eBot.dx / eBot.dy;
		eBot.fdxdy = SignedFloatToFixed(dxdy);
		eBot.adjy = (float)(eBot.fsy - vMin_fy);  /* SCALED! */
		eBot.fx0 = vMin_fx;
		eBot.fsx = eBot.fx0 + (int)(eBot.adjy * dxdy);
	}

	int ltor = (oneOverArea < 0.0F);

	float drdx, drdy;      int fdrdx;
	float dgdx, dgdy;      int fdgdx;
	float dbdx, dbdy;      int fdbdx;
	float dadx, dady;      int fdadx;
	{
		float eMaj_dr, eBot_dr;
		eMaj_dr = (int)cvMax[0] - (int)cvMin[0];
		eBot_dr = (int)cvMid[0] - (int)cvMin[0];
		drdx = oneOverArea * (eMaj_dr * eBot.dy - eMaj.dy * eBot_dr);
		fdrdx = SignedFloatToFixed(drdx);
		drdy = oneOverArea * (eMaj.dx * eBot_dr - eMaj_dr * eBot.dx);
	}
	{
		float eMaj_dg, eBot_dg;
		eMaj_dg = (int)cvMax[1] - (int)cvMin[1];
		eBot_dg = (int)cvMid[1] - (int)cvMin[1];
		dgdx = oneOverArea * (eMaj_dg * eBot.dy - eMaj.dy * eBot_dg);
		fdgdx = SignedFloatToFixed(dgdx);
		dgdy = oneOverArea * (eMaj.dx * eBot_dg - eMaj_dg * eBot.dx);
	}
	{
		float eMaj_db, eBot_db;
		eMaj_db = (int)cvMax[2] - (int)cvMin[2];
		eBot_db = (int)cvMid[2] - (int)cvMin[2];
		dbdx = oneOverArea * (eMaj_db * eBot.dy - eMaj.dy * eBot_db);
		fdbdx = SignedFloatToFixed(dbdx);
		dbdy = oneOverArea * (eMaj.dx * eBot_db - eMaj_db * eBot.dx);
	}

	{
		float eMaj_da, eBot_da;
		eMaj_da = (int)cvMax[3] - (int)cvMin[3];
		eBot_da = (int)cvMid[3] - (int)cvMin[3];
		dadx = oneOverArea * (eMaj_da * eBot.dy - eMaj.dy * eBot_da);
		fdadx = SignedFloatToFixed(dadx);
		dady = oneOverArea * (eMaj.dx * eBot_da - eMaj_da * eBot.dx);
	}



	float wMax = 1.0F;
	float wMin = 1.0F;
	float wMid = 1.0F;

	float eMaj_ds = tvMax[0] * wMax - tvMin[0] * wMin;
	float eBot_ds = tvMid[0] * wMid - tvMin[0] * wMin;
	float eMaj_dt = tvMax[1] * wMax - tvMin[1] * wMin;
	float eBot_dt = tvMid[1] * wMid - tvMin[1] * wMin;

	float dsdx = oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds);
	float dsdy = oneOverArea * (eMaj.dx * eBot_ds - eMaj_ds * eBot.dx);
	float dtdx = oneOverArea * (eMaj_dt * eBot.dy - eMaj.dy * eBot_dt);
	float dtdy = oneOverArea * (eMaj.dx * eBot_dt - eMaj_dt * eBot.dx);

	int fx, fxLeftEdge, fxRightEdge, fdxLeftEdge, fdxRightEdge;
	int fdxOuter;
	int idxOuter;
	float dxOuter;
	int fError, fdError;
	float adjx, adjy;
	int fy;
	int iy;

	int fr, fdrOuter, fdrInner;
	int fg, fdgOuter, fdgInner;
	int fb, fdbOuter, fdbInner;
	int fa, fdaOuter, fdaInner;

	float sLeft, dsOuter, dsInner;
	float tLeft, dtOuter, dtInner;


	for (int subTriangle = 0; subTriangle <= 1; subTriangle++)
	{
		EdgeT *eLeft, *eRight;
		int setupLeft, setupRight;
		int lines;

		if (subTriangle == 0) {
			/* bottom half */
			if (ltor) {
				eLeft = &eMaj;
				eRight = &eBot;
				lines = eRight->lines;
				setupLeft = 1;
				setupRight = 1;
			}
			else {
				eLeft = &eBot;
				eRight = &eMaj;
				lines = eLeft->lines;
				setupLeft = 1;
				setupRight = 1;
			}
		}
		else {
			/* top half */
			if (ltor)
			{
				eLeft = &eMaj;
				eRight = &eTop;
				lines = eRight->lines;
				setupLeft = 0;
				setupRight = 1;
			}
			else
			{
				eLeft = &eTop;
				eRight = &eMaj;
				lines = eLeft->lines;
				setupLeft = 1;
				setupRight = 0;
			}
			if (lines == 0) return;
		}

		if (setupLeft && eLeft->lines > 0)
		{
			int fsx = eLeft->fsx;
			fx = FixedCeil(fsx);
			fError = fx - fsx - FIXED_ONE;
			fxLeftEdge = fsx - FIXED_EPSILON;
			fdxLeftEdge = eLeft->fdxdy;
			fdxOuter = FixedFloor(fdxLeftEdge - FIXED_EPSILON);
			fdError = fdxOuter - fdxLeftEdge + FIXED_ONE;
			idxOuter = FixedToInt(fdxOuter);
			dxOuter = (float)idxOuter;

			fy = eLeft->fsy;
			iy = FixedToInt(fy);

			adjx = (float)(fx - eLeft->fx0);  /* SCALED! */
			adjy = eLeft->adjy;				 /* SCALED! */

			float* vLower = eLeft->v0;
			float* tvLower = eLeft->tv0;
			BYTE* cvLower = eLeft->cv0;

			sLeft = tvLower[0] * 1.0F + (dsdx * adjx + dsdy * adjy) * (1.0F / FIXED_SCALE);
			dsOuter = dsdy + dxOuter * dsdx;

			tLeft = tvLower[1] * 1.0F + (dtdx * adjx + dtdy * adjy) * (1.0F / FIXED_SCALE);
			dtOuter = dtdy + dxOuter * dtdx;

			fr = (int)(IntToFixed(cvLower[0]) + drdx * adjx + drdy * adjy) + FIXED_HALF;
			fdrOuter = SignedFloatToFixed(drdy + dxOuter * drdx);

			fg = (int)(IntToFixed(cvLower[1]) + dgdx * adjx + dgdy * adjy) + FIXED_HALF;
			fdgOuter = SignedFloatToFixed(dgdy + dxOuter * dgdx);

			fb = (int)(IntToFixed(cvLower[2]) + dbdx * adjx + dbdy * adjy) + FIXED_HALF;
			fdbOuter = SignedFloatToFixed(dbdy + dxOuter * dbdx);

			fa = (int)(IntToFixed(cvLower[3]) + dadx * adjx + dady * adjy) + FIXED_HALF;
			fdaOuter = SignedFloatToFixed(dady + dxOuter * dadx);
		}

		if (setupRight && eRight->lines > 0)
		{
			fxRightEdge = eRight->fsx - FIXED_EPSILON;
			fdxRightEdge = eRight->fdxdy;
		}

		if (lines == 0)
			continue;

		fdrInner = fdrOuter + fdrdx;
		fdgInner = fdgOuter + fdgdx;
		fdbInner = fdbOuter + fdbdx;
		fdaInner = fdaOuter + fdadx;

		dsInner = dsOuter + dsdx;
		dtInner = dtOuter + dtdx;

		if (iy + lines >= info.clip_bottom)
			lines = info.clip_bottom - iy;

		while (lines > 0)
		{
			float ss = sLeft, tt = tLeft;
			int ffr = fr, ffg = fg, ffb = fb;
			int ffa = fa;

			int left = FixedToInt(fxLeftEdge);
			int right = FixedToInt(fxRightEdge);

			int ffrend = ffr + (right - left - 1)*fdrdx;
			int ffgend = ffg + (right - left - 1)*fdgdx;
			int ffbend = ffb + (right - left - 1)*fdbdx;
			if (ffrend < 0) ffr -= ffrend;
			if (ffgend < 0) ffg -= ffgend;
			if (ffbend < 0) ffb -= ffbend;
			if (ffr < 0) ffr = 0;
			if (ffg < 0) ffg = 0;
			if (ffb < 0) ffb = 0;

			int ffaend = ffa + (right - left - 1)*fdadx;
			if (ffaend < 0) ffa -= ffaend;
			if (ffa < 0) ffa = 0;

			int i;
			int n = right - left;

			if (iy >= info.clip_top)
			{

				if (n > 0)
					if (left < info.clip_left)
					{
						int diff = info.clip_left - left;
						ss += dsdx	 *diff;
						tt += dtdx	 *diff;
						ffr += fdrdx *diff;
						ffg += fdgdx *diff;
						ffb += fdbdx *diff;
						ffa += fdadx *diff;

						n -= diff;

						left = info.clip_left;
					}

				if (n > 0)
					if (left + n >= info.clip_right)
					{
						n = info.clip_right - left;
					}

				if (n > 0)
					for (i = 0; i < n; i++)
					{
						int i0, j0, i1, j1;
						float u, v;

						u = ss * info.tex_width;
						v = tt * info.tex_height;



						i0 = (int)floor(u - 0.5F);
						i1 = i0 + 1;
						j0 = (int)floor(v - 0.5F);
						j1 = j0 + 1;


						float a = frac(u - 0.5F);
						float b = frac(v - 0.5F);

						int w00 = (int)((1.0F - a)*(1.0F - b) * 256.0F);
						int w10 = (int)(a *(1.0F - b) * 256.0F);
						int w01 = (int)((1.0F - a)*      b  * 256.0F);
						int w11 = (int)(a *      b  * 256.0F);

						unsigned char red00, green00, blue00, alpha00;
						unsigned char red10, green10, blue10, alpha10;
						unsigned char red01, green01, blue01, alpha01;
						unsigned char red11, green11, blue11, alpha11;

						const unsigned char* texel;

						if (info.tex_repeat)
						{
							if (i0 < 0)
								i0 = info.tex_width + i0;
							else
								if (i0 >= info.tex_width)
									i0 = i0 - info.tex_width;

							if (i1 < 0)
								i1 = info.tex_width + i0;
							else
								if (i1 >= info.tex_width)
									i1 = i1 - info.tex_width;

							if (j0 < 0)
								j0 = info.tex_height + j0;
							else
								if (j0 >= info.tex_height)
									j0 = j0 - info.tex_height;

							if (j1 < 0)
								j1 = info.tex_height + j1;
							else
								if (j1 >= info.tex_height)
									j1 = j1 - info.tex_height;
						}

						BYTE* ppix = (BYTE*)(info.dest + (iy*info.dest_width + left) * 4);
						BYTE pix_r = ppix[i * 4 + 0];
						BYTE pix_g = ppix[i * 4 + 1];
						BYTE pix_b = ppix[i * 4 + 2];
						BYTE pix_a = ppix[i * 4 + 3];

						BYTE border_r = pix_r; //mesa3d cannot do this :)
						BYTE border_g = pix_g;
						BYTE border_b = pix_b;
						BYTE border_a = 0;

						bool i0_border = (i0 < 0 || i0 >= info.tex_width);
						bool i1_border = (i1 < 0 || i1 >= info.tex_width);
						bool j0_border = (j0 < 0 || j0 >= info.tex_height);
						bool j1_border = (j1 < 0 || j1 >= info.tex_height);

						if (i0_border | j0_border)
						{
							red00 = border_r;
							green00 = border_g;
							blue00 = border_b;
							alpha00 = border_a;
						}
						else
						{
							texel = info.tex + (info.tex_width * j0 + i0) * 4;
							red00 = texel[0];
							green00 = texel[1];
							blue00 = texel[2];
							alpha00 = texel[3];
						}

						if (i1_border | j0_border)
						{
							red10 = border_r;
							green10 = border_g;
							blue10 = border_b;
							alpha10 = border_a;
						}
						else
						{
							texel = info.tex + (info.tex_width * j0 + i1) * 4;
							red10 = texel[0];
							green10 = texel[1];
							blue10 = texel[2];
							alpha10 = texel[3];
						}

						if (j1_border | i0_border)
						{
							red01 = border_r;
							green01 = border_g;
							blue01 = border_b;
							alpha01 = border_a;
						}
						else
						{
							texel = info.tex + (info.tex_width * j1 + i0) * 4;
							red01 = texel[0];
							green01 = texel[1];
							blue01 = texel[2];
							alpha01 = texel[3];
						}

						if (i1_border | j1_border)
						{
							red11 = border_r;
							green11 = border_g;
							blue11 = border_b;
							alpha11 = border_a;
						}
						else
						{
							texel = info.tex + (info.tex_width * j1 + i1) * 4;
							red11 = texel[0];
							green11 = texel[1];
							blue11 = texel[2];
							alpha11 = texel[3];
						}

						BYTE _r = (w00*red00 + w10*red10 + w01*red01 + w11*red11) / 256;
						BYTE _g = (w00*green00 + w10*green10 + w01*green01 + w11*green11) / 256;
						BYTE _b = (w00*blue00 + w10*blue10 + w01*blue01 + w11*blue11) / 256;
						BYTE _a = (w00*alpha00 + w10*alpha10 + w01*alpha01 + w11*alpha11) / 256;


						_r = (_r * FixedToInt(ffr)) / 256;
						_g = (_g * FixedToInt(ffg)) / 256;
						_b = (_b * FixedToInt(ffb)) / 256;
						_a = (_a * FixedToInt(ffa)) / 256;

						int t = _a;
						int s = 255 - t;

						ppix[i * 4 + 0] = (_b * t + pix_r * s) / 256; //swap rb
						ppix[i * 4 + 1] = (_g * t + pix_g * s) / 256;
						ppix[i * 4 + 2] = (_r * t + pix_b * s) / 256;
						ppix[i * 4 + 3] = (_a * t + pix_a * s) / 256;

						ss += dsdx;
						tt += dtdx;
						ffr += fdrdx;
						ffg += fdgdx;
						ffb += fdbdx;
						ffa += fdadx;
					}
			}

			iy++;
			lines--;

			fxLeftEdge += fdxLeftEdge;
			fxRightEdge += fdxRightEdge;


			fError += fdError;
			if (fError >= 0)
			{
				fError -= FIXED_ONE;

				sLeft += dsOuter;
				tLeft += dtOuter;
				fr += fdrOuter;
				fg += fdgOuter;
				fb += fdbOuter;
				fa += fdaOuter;
			}
			else {
				sLeft += dsInner;
				tLeft += dtInner;
				fr += fdrInner;
				fg += fdgInner;
				fb += fdbInner;
				fa += fdaInner;
			}
		}
	}
}
示例#10
0
extern	Bool
SetValueFixed(
	ValueStruct	*val,
	Fixed		*fval)
{
	Bool	rc;
	char	*str;

	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
			rc = SetValueString(val,fval->sval,NULL);
			break;
		  case	GL_TYPE_NUMBER:
			FixedRescale(&ValueFixed(val),fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_INT:
			ValueInteger(val) = FixedToInt(fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			ValueFloat(val) = FixedToFloat(fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
			str = fval->sval;
			ValueDateTimeYear(val) = StrToInt(str,4);		str += 4;
			ValueDateTimeMon(val) = StrToInt(str,2) - 1;	str += 2;
			ValueDateTimeMDay(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeHour(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeMin(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeSec(val) = StrToInt(str,2);		str += 2;
			rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
			break;
		  case	GL_TYPE_DATE:
			str = fval->sval;
			ValueDateTimeYear(val) = StrToInt(str,4);		str += 4;
			ValueDateTimeMon(val) = StrToInt(str,2) - 1;	str += 2;
			ValueDateTimeMDay(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeHour(val) = 0;
			ValueDateTimeMin(val) = 0;
			ValueDateTimeSec(val) = 0;
			rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
			break;
		  case	GL_TYPE_TIME:
			str = fval->sval;
			ValueDateTimeYear(val) = 0;
			ValueDateTimeMon(val) = 0;
			ValueDateTimeMDay(val) = 0;
			ValueDateTimeHour(val) = StrToInt(str,2);	str += 2;
			ValueDateTimeMin(val) = StrToInt(str,2);	str += 2;
			ValueDateTimeSec(val) = StrToInt(str,2);	str += 2;
			rc = TRUE;
			break;
#if	0
		  case	GL_TYPE_BOOL:
			val->body.BoolData = ( *fval->sval == 0 ) ? FALSE : TRUE;
			rc = TRUE;
			break;
#endif
		  default:
			ValueIsNil(val);
			rc = FALSE;
			break;
		}
	}
	return	(rc);
}
示例#11
0
struct list_t *opengl_sc_rast_triangle_gen_pixel_info(struct opengl_pa_triangle_t *triangle, struct opengl_depth_buffer_t *db)
{
	/* List contains info of pixels inside this triangle */
	struct list_t *pxl_lst;
	struct opengl_sc_pixel_info_t *pxl_info;

	struct opengl_sc_edge_t *edge_major;
	struct opengl_sc_edge_t *edge_top;
	struct opengl_sc_edge_t *edge_bottom;

	struct opengl_pa_vertex_t *vtx_max;
	struct opengl_pa_vertex_t *vtx_mid;
	struct opengl_pa_vertex_t *vtx_min;

	struct opengl_sc_span_t *spn;

	pxl_lst = list_create();
	spn = opengl_sc_span_create();

	float one_over_area;
	int vtx_min_fx, vtx_min_fy;
	int vtx_mid_fx, vtx_mid_fy;
	int vtx_max_fx, vtx_max_fy;
	int scan_from_left_to_right;

	const int snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1); /* for x/y coord snapping */

	const int fy0 = FloatToFixed(triangle->vtx0->pos[Y_COMP] - 0.5F) & snapMask;
	const int fy1 = FloatToFixed(triangle->vtx1->pos[Y_COMP] - 0.5F) & snapMask;
	const int fy2 = FloatToFixed(triangle->vtx2->pos[Y_COMP] - 0.5F) & snapMask;

	/* Find the order of vertex */
	if (fy0 <= fy1)
	{
		if (fy1 <= fy2)
		{
			/* y0 < y1 < y2 */
			vtx_max = triangle->vtx2; vtx_mid = triangle->vtx1; vtx_min = triangle->vtx0;
			vtx_max_fy = fy2; vtx_mid_fy = fy1; vtx_min_fy = fy0;

		}
		else if (fy2 <= fy0)
		{
			/* y2 < y0 < y1 */
			vtx_max = triangle->vtx1; vtx_mid = triangle->vtx0; vtx_min = triangle->vtx2;
			vtx_max_fy = fy1; vtx_mid_fy = fy0; vtx_min_fy = fy2;
		}
		else {
			/* y0 < y2 < y1 */
			vtx_max = triangle->vtx1; vtx_mid = triangle->vtx2; vtx_min = triangle->vtx0;
			vtx_max_fy = fy1; vtx_mid_fy = fy2; vtx_min_fy = fy0;
		}
	}
	else {
		if (fy0 <= fy2)
		{
			/* y1 < y0 < y2 */
			vtx_max = triangle->vtx2; vtx_mid = triangle->vtx0; vtx_min = triangle->vtx1;
			vtx_max_fy = fy2; vtx_mid_fy = fy0; vtx_min_fy = fy1;
		}
		else if (fy2 <= fy1)
		{
			/* y2 < y1 < y0 */
			vtx_max = triangle->vtx0; vtx_mid = triangle->vtx1; vtx_min = triangle->vtx2;
			vtx_max_fy = fy0; vtx_mid_fy = fy1; vtx_min_fy = fy2;
		}
		else {
			/* y1 < y2 < y0 */
			vtx_max = triangle->vtx0; vtx_mid = triangle->vtx2; vtx_min = triangle->vtx1;
			vtx_max_fy = fy0; vtx_mid_fy = fy2; vtx_min_fy = fy1;
		}
	}

	vtx_min_fx = FloatToFixed(vtx_min->pos[X_COMP] + 0.5F) & snapMask;
	vtx_mid_fx = FloatToFixed(vtx_mid->pos[X_COMP] + 0.5F) & snapMask;
	vtx_max_fx = FloatToFixed(vtx_max->pos[X_COMP] + 0.5F) & snapMask;

	/* Create edges */
	edge_major = opengl_sc_edge_create(vtx_max, vtx_min);
	edge_top = opengl_sc_edge_create(vtx_max, vtx_mid);
	edge_bottom = opengl_sc_edge_create(vtx_mid, vtx_min);

	/* compute deltas for each edge:  vertex[upper] - vertex[lower] */
	edge_major->dx = FixedToFloat(vtx_max_fx - vtx_min_fx);
	edge_major->dy = FixedToFloat(vtx_max_fy - vtx_min_fy);
	edge_top->dx = FixedToFloat(vtx_max_fx - vtx_mid_fx);
	edge_top->dy = FixedToFloat(vtx_max_fy - vtx_mid_fy);
	edge_bottom->dx = FixedToFloat(vtx_mid_fx - vtx_min_fx);
	edge_bottom->dy = FixedToFloat(vtx_mid_fy - vtx_min_fy);

	/* Compute area */	
	const float area = edge_major->dx * edge_bottom->dy - edge_bottom->dx * edge_major->dy;
	one_over_area = 1.0f / area;

	/* Edge setup */
	edge_major->fsy = FixedCeil(vtx_min_fy);
	edge_major->lines = FixedToInt(FixedCeil(vtx_max_fy - edge_major->fsy));
	if (edge_major->lines > 0) {
		edge_major->dxdy = edge_major->dx / edge_major->dy;
		edge_major->fdxdy = SignedFloatToFixed(edge_major->dxdy);		
		edge_major->adjy = (float) (edge_major->fsy - vtx_min_fy);  /* SCALED! */
		edge_major->fx0 = vtx_min_fx;
		edge_major->fsx = edge_major->fx0 + (int) (edge_major->adjy * edge_major->dxdy);
	}
	else
	{
		/* Free edges */
		opengl_sc_edge_free(edge_major);
		opengl_sc_edge_free(edge_top);
		opengl_sc_edge_free(edge_bottom);

		/* Free span*/
		opengl_sc_span_free(spn);
		list_free(pxl_lst);

		/*CULLED*/
		return NULL;  
	}

	edge_top->fsy = FixedCeil(vtx_mid_fy);
	edge_top->lines = FixedToInt(FixedCeil(vtx_max_fy - edge_top->fsy));
	if (edge_top->lines > 0)
	{
		edge_top->dxdy = edge_top->dx / edge_top->dy;
		edge_top->fdxdy = SignedFloatToFixed(edge_top->dxdy);		
		edge_top->adjy = (float) (edge_top->fsy - vtx_mid_fy); /* SCALED! */
		edge_top->fx0 = vtx_mid_fx;
		edge_top->fsx = edge_top->fx0 + (int) (edge_top->adjy * edge_top->dxdy);
	}

	edge_bottom->fsy = FixedCeil(vtx_min_fy);
	edge_bottom->lines = FixedToInt(FixedCeil(vtx_mid_fy - edge_bottom->fsy));
	if (edge_bottom->lines > 0)
	{
		edge_bottom->dxdy = edge_bottom->dx / edge_bottom->dy;
		edge_bottom->fdxdy = SignedFloatToFixed(edge_bottom->dxdy);		
		edge_bottom->adjy = (float) (edge_bottom->fsy - vtx_min_fy);  /* SCALED! */
		edge_bottom->fx0 = vtx_min_fx;
		edge_bottom->fsx = edge_bottom->fx0 + (int) (edge_bottom->adjy * edge_bottom->dxdy);
	}

	/* Decide scan direction */
	scan_from_left_to_right = (one_over_area < 0.0F);

	/* Interpolate depth */
	float edge_major_dz = vtx_max->pos[Z_COMP] - vtx_min->pos[Z_COMP];
	float edge_bottom_dz = vtx_mid->pos[Z_COMP] - vtx_min->pos[Z_COMP];
	spn->attrStepX[2] = one_over_area * (edge_major_dz * edge_bottom->dy - edge_major->dy * edge_bottom_dz);
	spn->attrStepY[2] = one_over_area * (edge_major->dx * edge_bottom_dz - edge_major_dz * edge_bottom->dx);
	spn->zStep = SignedFloatToFixed(spn->attrStepX[2]);

	int subTriangle;
	int fxLeftEdge = 0, fxRightEdge = 0;
	int fdxLeftEdge = 0, fdxRightEdge = 0;
	int fError = 0, fdError = 0;

	unsigned int zLeft = 0;
	int fdzOuter = 0, fdzInner;


	/* Setup order of edges */
	for (subTriangle=0; subTriangle<=1; subTriangle++)
	{
		struct opengl_sc_edge_t *edge_left;
		struct opengl_sc_edge_t *edge_right;
		int setupLeft, setupRight;
		int lines;

		if (subTriangle==0) {
			/* bottom half */
			if (scan_from_left_to_right) {
				edge_left = edge_major;
				edge_right = edge_bottom;
				lines = edge_right->lines;
				setupLeft = 1;
				setupRight = 1;
			}
			else {
				edge_left = edge_bottom;
				edge_right = edge_major;
				lines = edge_left->lines;
				setupLeft = 1;
				setupRight = 1;
			}
		} 
		else {
			/* top half */
			if (scan_from_left_to_right) 
			{
				edge_left = edge_major;
				edge_right = edge_top;
				lines = edge_right->lines;
				setupLeft = 0;
				setupRight = 1;
			}
			else {
				edge_left = edge_top;
				edge_right = edge_major;
				lines = edge_left->lines;
				setupLeft = 1;
				setupRight = 0;
			}
			if (lines == 0)
				return NULL;
		}

		if (setupLeft && edge_left->lines > 0)
		{
			const struct opengl_pa_vertex_t *vtx_lower = edge_left->vtx1;
			const int fsy = edge_left->fsy;
			const int fsx = edge_left->fsx;  /* no fractional part */
			const int fx = FixedCeil(fsx);  /* no fractional part */
			const int adjx = (int) (fx - edge_left->fx0); /* SCALED! */
			const int adjy = (int) edge_left->adjy;      /* SCALED! */			
			int idxOuter;
			float dxOuter;			
			int fdxOuter;

			fError = fx - fsx - FIXED_ONE;
			fxLeftEdge = fsx - FIXED_EPSILON;
			fdxLeftEdge = edge_left->fdxdy;
			fdxOuter = FixedFloor(fdxLeftEdge - FIXED_EPSILON);
			fdError = fdxOuter - fdxLeftEdge + FIXED_ONE;
			idxOuter = FixedToInt(fdxOuter);
			dxOuter = (float) idxOuter;
			spn->y = FixedToInt(fsy);

			/* Interpolate Z */
			float z0 = vtx_lower->pos[Z_COMP];
			float tmp = (z0 * FIXED_SCALE + spn->attrStepX[2] * adjx + spn->attrStepY[2] * adjy) + FIXED_HALF;
			if (tmp < MAX_GLUINT / 2)
				zLeft = (int) tmp;
			else
				zLeft = MAX_GLUINT / 2;
			fdzOuter = SignedFloatToFixed(spn->attrStepY[2] + dxOuter * spn->attrStepX[2]);								

		}

		if (setupRight && edge_right->lines>0) 
		{
			fxRightEdge = edge_right->fsx - FIXED_EPSILON;
			fdxRightEdge = edge_right->fdxdy;
		}

		if (lines==0)
			continue;

		/* Interpolate Z */
		fdzInner = fdzOuter + spn->zStep;		

		/* Rasterize setup */
		while (lines > 0)
		{

			/* initialize the spn->interpolants to the leftmost value */
			/* ff = fixed-pt fragment */
			const int right = FixedToInt(fxRightEdge);
			spn->x = FixedToInt(fxLeftEdge);
			if (right <= spn->x)
				spn->end = 0;
			else
				spn->end = right - spn->x;

			/* Interpolate Z */
			spn->z = zLeft;

			/* This is where we actually generate fragments */
			if (spn->end > 0 && spn->y >= 0)
			{
				const int len = spn->end;

				int i;
				for (i = 0; i < len; ++i)
				{
					/* Add if pass depth test */
					if(opengl_depth_buffer_test_and_set_pixel(db, spn->x, spn->y, FixedToFloat(spn->z), db->depth_func))
					{
						pxl_info = opengl_sc_pixel_info_create();
						opengl_sc_pixel_info_set_wndw_cood(pxl_info, spn->x, spn->y, spn->z);
						opengl_sc_pixel_info_set_brctrc_cood(pxl_info, triangle);
						list_add(pxl_lst, pxl_info);
					}
					spn->z += spn->zStep;
					spn->x++;
				}
			}

			/*
			* Advance to the next scan line.  Compute the new edge coordinates, and adjust the
			* pixel-center x coordinate so that it stays on or inside the major edge.
			*/
			spn->y++;
			lines--;

			fxLeftEdge += fdxLeftEdge;
			fxRightEdge += fdxRightEdge;

			fError += fdError;

			if (fError >= 0)
			{
				zLeft += fdzOuter;
				fError -= FIXED_ONE;				
			}
			else
				zLeft += fdzInner;
			
		} /*while lines>0*/
	}

	/* Free edges */
	opengl_sc_edge_free(edge_major);
	opengl_sc_edge_free(edge_top);
	opengl_sc_edge_free(edge_bottom);

	/* Free span*/
	opengl_sc_span_free(spn);

	/* Return */
	return pxl_lst;
}
SOM_Scope void  SOMLINK ShapePartAdjustViewTypeShapes(ShapePart *somSelf,
                                                       Environment *ev,
                                                       ODFrame* frame)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartAdjustViewTypeShapes");

    try
    {
      // Call parent
      ShapePart_parent_SimplePart_AdjustViewTypeShapes(somSelf, ev, frame);

      ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev); // Get facets for frame
      ODFacet*    facet            = facets->First(ev);              // Assume 1 facet
      delete facets;

      ODRect rect;
      ODTypeToken viewType = frame->GetViewType(ev);

      // Override SimplePart's behavior only if this is an embedded part displaying as frame.
      if((viewType == somThis->fSession->Tokenize(ev,kODViewAsFrame)) &&
         (!frame->IsRoot(ev)))
      {

         // Set the used and active shape to a circle.
         int         width, height;
         ODRgnHandle hrgnUsedAndActive;
         ODRect      box;

         ODCanvas *canvas = facet->GetCanvas(ev);

#ifdef _PLATFORM_OS2_
         HPS       hps;
         hps = ((ODOS2WindowCanvas*) canvas->GetPlatformCanvas(ev, kODPM))->GetPS(ev); // Obtain a PS
#endif //_PLATFORM_OS2_

         TempODShape frameShape = frame->AcquireFrameShape(ev, canvas); // Get bounding box
         frameShape->GetBoundingBox(ev, &box);                          //  of frame
         width  = FixedToInt(box.right)-FixedToInt(box.left);           // circle to be
         height = abs(FixedToInt(box.top)-FixedToInt(box.bottom));      // constructed

#ifdef _PLATFORM_OS2_
         Point center;
         center.x = width/2;
         center.y = height/2;
         int rad  = (width < height) ? center.x : center.y;             // get radius
         GpiBeginPath(hps,1L);                                          // Define GPI path
         GpiSetCurrentPosition(hps , &center);                          // for circle
         GpiFullArc(hps,DRO_OUTLINE,MAKEFIXED(rad,0));
         GpiEndPath(hps);
         hrgnUsedAndActive = GpiPathToRegion(hps, 1, FPATH_ALTERNATE);  // Convert path to GPI region
         ((ODOS2WindowCanvas *)canvas->GetPlatformCanvas(ev, kODPM))->ReleasePS(ev); // Release the canvas
#elif defined(_PLATFORM_WIN32_)

         hrgnUsedAndActive = CreateEllipticRgn(0,0,width,height);       // region from Ellipse box
#endif //_PLATFORM_WIN32_

         if(hrgnUsedAndActive)
         {
            // Use TempODShape so this object won't have to be released.
            TempODShape usedAndActiveShape = frame->CreateShape(ev);       // create a shape
            usedAndActiveShape->SetRegion(ev, hrgnUsedAndActive);          // assign the region to the shape

            // Set used and active shapes to the newly defined shape
            frame->ChangeUsedShape(ev, usedAndActiveShape, kODNULL);
            if(facet)
            {
              facet->ChangeActiveShape(ev, usedAndActiveShape, kODNULL);
            }
         } // hrgnUsedAndActive
      } // viewtype is frame and frame isn't root
      else
      {
         // Reset used and active shapes to frame shape
         frame->ChangeUsedShape(ev, kODNULL, kODNULL);
         if(facet)
         {
           facet->ChangeActiveShape(ev, kODNULL, kODNULL);
         }

      }
    }
    catch(...)
    {
    }
}
示例#13
0
BOOL FAR PASCAL DibTransparentStretch(
	PDIB pdibDst,
	LPVOID lpDst,
	int DstX,
	int DstY,
	int DstXE,
	int DstYE,
	PDIB pdibSrc,
	LPVOID lpSrc,
	int SrcX,
	int SrcY,
	int SrcXE,
	int SrcYE,
	char unsigned Transparent)
{
	int XMax, YMax;
	Fixed fClipRatio;
	int iTemp;

	assert(pdibDst && lpDst);
	assert(pdibSrc && lpSrc);

	//*** Currently, this only works with 8-bit dibs
	assert(pdibDst->biBitCount == 8); 
	assert(pdibSrc->biBitCount == 8);

	//*** This does NOT mirror
	assert (DstXE >= 0 && DstYE >= 0);
	assert (SrcXE >= 0 && SrcYE >= 0);

	XMax = (int)pdibDst->biWidth - 1;
	// [email protected]:  I changed the following line.
	// In the version I was given, the abs was not here.
	// As a result, this did not handle top-down DIBS.
	// The rest of the routine works fine.
	YMax = abs((int)pdibDst->biHeight) - 1;
	///End WWW Change.

	//*** Trivial reject
	if (DstX > XMax || DstY > YMax ||
		(DstX + DstXE) < 0 || (DstY + DstYE) < 0)
		return TRUE;

	/// [email protected]: I duplicated the following line
	// of code.  This is changing the starting position
	// of the blit from a 'standard' Windows top-down
	// coordinate system to a 'standard' DIB bottom-up
	// coordinate system.  Unfortunately, the original
	// source only changed the destination.  This meant
	// that it painted from the wrong spot in the source
	// DIB.  So, I changed the source Y spot as well.
	DstY = YMax + 1 - DstY - DstYE;
	SrcY = abs ((int)pdibSrc->biHeight) - SrcY - SrcYE;

	//*** Clip the left edge
	if (DstX < 0)
	{
		fClipRatio = FixedDivide( IntToFixed(-DstX),
			IntToFixed(DstXE) );

		//*** Remember, DstX is negative!
		DstXE = DstXE + DstX;
		DstX = 0;

		iTemp = FixedToInt( FixedMultiply( fClipRatio, IntToFixed(SrcXE) ) );
		SrcX = SrcX + iTemp;
		SrcXE = SrcXE - iTemp;
	}

	//*** Clip the top edge
	if (DstY < 0)
	{
		fClipRatio = FixedDivide( IntToFixed(-DstY),
			IntToFixed(DstYE) );

		//*** Remember, DstY is negative!
		DstYE = DstYE + DstY;
		DstY = 0;

		iTemp = FixedToInt( FixedMultiply( fClipRatio, IntToFixed(SrcYE) ) );
		SrcY = SrcY + iTemp;
		SrcYE = SrcYE - iTemp;
	}

	
	//
	// [email protected]
	// XMax (and later YMax) are being used as 0 based when
	// they are in fact the width (and height) in pixels of
	// the dib and are 1 based.
	//
	//*** Clip the X extent
	if ((DstX + DstXE) > (XMax + 1))
	{
		fClipRatio = FixedDivide( IntToFixed(XMax - DstX),
			IntToFixed(DstXE) );

		DstXE = XMax - DstX + 1;
		SrcXE = FixedToInt( FixedMultiply(fClipRatio, IntToFixed(SrcXE)) );

		//*** Make sure the round-off is correct
		if ((DstX + DstXE) < XMax)
		  ++DstXE;
	}

	//
	// [email protected]
	// As above, YMax was being used as a 0 based value
	// instead of the 1 based that it is.
	//
	//*** Clip the Y extent
	if ((DstY + DstYE) > (YMax + 1))
	{
		fClipRatio = FixedDivide( IntToFixed(YMax - DstY),
			IntToFixed(DstYE) );

		DstYE = YMax - DstY + 1;
		SrcYE = FixedToInt( FixedMultiply(fClipRatio, IntToFixed(SrcYE)) );

		//*** Make sure the round-off is correct
		if ((DstY + DstYE) < YMax)
		  ++DstYE;
	}

	DoDibTransparentStretch(
		pdibDst, lpDst, DstX, DstY, DstXE, DstYE,
		pdibSrc, lpSrc, SrcX, SrcY, SrcXE, SrcYE,
		Transparent);

	return TRUE;
}
示例#14
0
/***************************************************************************\
  Returns magnitude of point (used as vector) using approximation. 
\***************************************************************************/
int inline IMR_3DPoint::FastMag(void)
{
return (int)((FixedToInt(aX) + FixedToInt(aY) + FixedToInt(aZ)) / 3);
 }
示例#15
0
/***************************************************************************\
  Returns magnitude of point (used as vector)
\***************************************************************************/
int inline IMR_3DPoint::Mag(void)
{
return (int)sqrt((FixedToInt(aX) * FixedToInt(aX)) + 
                 (FixedToInt(aY) * FixedToInt(aY)) + 
                 (FixedToInt(aZ) * FixedToInt(aZ)));
 }