Ejemplo n.º 1
0
void GOpenGLBoard::GrabFrameBuffer(const GAABox2& LogicBox, GLGrabbedRect& Shot) {

	GLDisableShaders();

	GReal left, right, bottom, top;
	Projection(left, right, bottom, top);

	if (LogicBox.Min()[G_X] > left)
		left = LogicBox.Min()[G_X];
	if (LogicBox.Max()[G_X] < right)
		right = LogicBox.Max()[G_X];
	if (LogicBox.Min()[G_Y] > bottom)
		bottom = LogicBox.Min()[G_Y];
	if (LogicBox.Max()[G_Y] < top)
		top = LogicBox.Max()[G_Y];

	GAABox2 tmpBox(GPoint2(left, bottom), GPoint2(right, top));

	GPoint<GInt32, 2> p0 = LogicalToPhysicalInt(tmpBox.Min());
	GPoint<GInt32, 2> p1 = LogicalToPhysicalInt(tmpBox.Max());
	p0[G_X] -= 1;
	p0[G_Y] -= 1;
	p1[G_X] += 1;
	p1[G_Y] += 1;
	GGenericAABox<GInt32, 2> intBox(p0, p1);

	GUInt32 width = (GUInt32)GMath::Abs(p1[G_X] - p0[G_X]);
	GUInt32 height = (GUInt32)GMath::Abs(p1[G_Y] - p0[G_Y]);

	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	UpdateGrabBuffer(width, height, Shot);

	G_ASSERT(Shot.TexName > 0);
	G_ASSERT(Shot.TexWidth > 0 && Shot.TexHeight > 0);
	G_ASSERT(Shot.TexWidth >= width && Shot.TexHeight >= height);

	SELECT_AND_DISABLE_TUNIT(1)
	SELECT_AND_DISABLE_TUNIT(0)
	glEnable(Shot.Target);
	glBindTexture(Shot.Target, Shot.TexName);
	glCopyTexSubImage2D(Shot.Target, 0, 0, 0, (GLint)intBox.Min()[G_X], (GLint)intBox.Min()[G_Y], (GLsizei)width, (GLsizei)height);

	Shot.Width = width;
	Shot.Height = height;
	Shot.IsEmpty = G_FALSE;

	Shot.gNotExpandedLogicBox = tmpBox;

	GPoint2 q0 = PhysicalToLogical(p0);
	GPoint2 q1 = PhysicalToLogical(p1);
	Shot.gExpandedLogicBox.SetMinMax(q0, q1);

	SELECT_AND_DISABLE_TUNIT(0)
	glPixelStorei(GL_PACK_ALIGNMENT, 4);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
}
Ejemplo n.º 2
0
void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
{
    if (paintingDisabled())
        return;

    RetainPtr<CFURLRef> urlRef(AdoptCF, link.createCFURL());
    if (!urlRef)
        return;

    CGContextRef context = platformContext();

    // Get the bounding box to handle clipping.
    CGRect box = CGContextGetClipBoundingBox(context);

    IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
    IntRect rect = destRect;
    rect.intersect(intBox);

    CGPDFContextSetURLForRect(context, urlRef.get(),
        CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
}