Ejemplo n.º 1
0
void RNRenderADF::Render(Wz4RenderContext *ctx)
{
  RenderChilds(ctx);
  
  if((ctx->RenderMode & sRF_TARGET_MASK)==sRF_TARGET_MAIN)
  {    
    sInt sx = ctx->ScreenX;
    sInt sy = ctx->ScreenY;

    sRay rtl;
    sRay rtr;
    sRay rtb;
    sRay rcp;
       
    ctx->View.MakeRay(-1, 1,rtl);
    ctx->View.MakeRay( 1, 1,rtr);
    ctx->View.MakeRay(-1,-1,rtb);
    ctx->View.MakeRay(0,0,rcp);
  
    sRay ray2;

    sVector30 dnx= (rtr.Start - rtl.Start);
    sVector30 dny= (rtb.Start - rtl.Start);
    sVector31 px=rtl.Start;  
    sVector31 cp=ctx->View.Camera.l;// rcp.Start;

    sTexture2D *dest = sRTMan->WriteScreen();
//    sTexture2D *src = sRTMan->ReadScreen();
    sTexture2D *mask = sRTMan->Acquire(sx,sy,sTEX_2D|sTEX_NOMIPMAPS|sTEX_ARGB16F);
    
    sRTMan->SetTarget(mask);

    //Render Gradient Texture
    sCBuffer<tADFMatVSPara> cbv;
    sCBuffer<tADFMatPSPara> cbp;

    ctx->IppHelper->GetTargetInfo(cbv.Data->mvp);
    cbv.Modify(); 

    sF32 imd=1.0f/sMax(sMax(SDF->DimX, SDF->DimY), SDF->DimZ);

    sAABBox box;
    SDF->GetBox(box);

    cbp.Data->dnx=dnx;
    cbp.Data->dny=dny;
    cbp.Data->px=rtl.Start;
    cbp.Data->cp=cp;
    cbp.Data->sp.Init(SDF->STBX,SDF->STBY,SDF->STBZ,0);
    cbp.Data->op.Init(box.Min.x,box.Min.y,box.Min.z,0);
    cbp.Data->mp.Init(box.Max.x,box.Max.y,box.Max.z,0);
    cbp.Data->id.Init(1.0f/(SDF->DimX-1),1.0f/(SDF->DimY-1),1.0f/(SDF->DimZ-1),imd);
    cbp.Data->d.Init(SDF->DimX,SDF->DimY,SDF->DimZ,0);
    cbp.Data->pstep.Init(SDF->PStepX,SDF->PStepY,SDF->PStepZ,0);

    cbp.Modify();
    Mtrl->Texture[0]=texture;
    Mtrl->Set(&cbv,&cbp);
    ctx->IppHelper->DrawQuad(dest);
    Mtrl->Texture[0]=0;



    sRTMan->SetTarget(dest);
    sCBuffer<tADFShadowMatVSPara> cbv_shadow;
    sCBuffer<tADFShadowMatPSPara> cbp_shadow;

    ctx->IppHelper->GetTargetInfo(cbv_shadow.Data->mvp);
    cbv_shadow.Modify(); 

    cbp_shadow.Data->dnx=dnx;
    cbp_shadow.Data->dny=dny;
    cbp_shadow.Data->px=rtl.Start;
    cbp_shadow.Data->cp=cp;    

    cbp_shadow.Data->sp.Init(SDF->STBX,SDF->STBY,SDF->STBZ,0);
    cbp_shadow.Data->op.Init(box.Min.x,box.Min.y,box.Min.z,0);
    cbp_shadow.Data->mp.Init(box.Max.x,box.Max.y,box.Max.z,0);
    cbp_shadow.Data->id.Init(1.0f/(SDF->DimX-1),1.0f/(SDF->DimY-1),1.0f/(SDF->DimZ-1),imd);
    cbp_shadow.Data->d.Init(SDF->DimX,SDF->DimY,SDF->DimZ,0);
    cbp_shadow.Data->pstep.Init(SDF->PStepX,SDF->PStepY,SDF->PStepZ,0);


    cbp_shadow.Data->light=Para.LightPos;
    cbp_shadow.Data->phongpara.Init(Para.PhongMax,Para.PhongPower,0,0);
    cbp_shadow.Data->diffusecolor.InitColor(Para.DiffuseColor);
    cbp_shadow.Data->ambientcolor.InitColor(Para.AmbientColor);
    cbp_shadow.Data->speccolor.InitColor(Para.SpecColor);



    //cbp_shadow.Data->
    cbp_shadow.Modify();

    MtrlShadow->Texture[0]=texture;
    MtrlShadow->Texture[1]=mask;
    MtrlShadow->Set(&cbv_shadow,&cbp_shadow);
    ctx->IppHelper->DrawQuad(dest,mask);
    MtrlShadow->Texture[0]=0;
    MtrlShadow->Texture[1]=0;

    sRTMan->Release(mask);
  //  sRenderTargetManager->Release(src);    
    sRTMan->Release(dest);
  } 
}
Ejemplo n.º 2
0
void wxSVGCanvas::RenderElement(wxSVGElement* elem, const wxSVGRect* rect, const wxSVGMatrix* parentMatrix,
		const wxCSSStyleDeclaration* parentStyle, wxSVGSVGElement* ownerSVGElement, wxSVGElement* viewportElement,
		wxProgressDialog* progressDlg) {
	wxSVGMatrix matrix(*parentMatrix);
	wxCSSStyleRef style(*parentStyle);
	elem->SetOwnerSVGElement(ownerSVGElement);
	elem->SetViewportElement(viewportElement);

	switch (elem->GetDtd()) {
	case wxSVG_SVG_ELEMENT: {
		wxSVGSVGElement* element = (wxSVGSVGElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		if (element->GetWidth().GetAnimVal().GetUnitType() == wxSVG_LENGTHTYPE_UNKNOWN)
			((wxSVGAnimatedLength&) element->GetWidth()).SetAnimVal( wxSVGLength(wxSVG_LENGTHTYPE_PERCENTAGE, 100));
		if (element->GetHeight().GetAnimVal().GetUnitType() == wxSVG_LENGTHTYPE_UNKNOWN)
			((wxSVGAnimatedLength&) element->GetHeight()).SetAnimVal( wxSVGLength(wxSVG_LENGTHTYPE_PERCENTAGE, 100));
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		if (rect && element->GetParent()) {
			wxSVGRect rect2 = *rect;
			wxSVGElement* parent = (wxSVGElement*) element->GetParent();
			wxSVGTransformable* transformable = wxSVGTransformable::GetSVGTransformable(*parent);
			if (transformable)
				rect2 = rect2.MatrixTransform(transformable->GetCTM().Inverse());
			RenderChilds(elem, &rect2, &matrix, &style, element, element, progressDlg);
		} else
			RenderChilds(elem, rect, &matrix, &style, element, element, progressDlg);
		break;
	}
	case wxSVG_G_ELEMENT: {
		wxSVGGElement* element = (wxSVGGElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		RenderChilds(elem, rect, &matrix, &style, ownerSVGElement, viewportElement, progressDlg);
		break;
	}
	case wxSVG_LINE_ELEMENT: {
		wxSVGLineElement* element = (wxSVGLineElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawLine(element, &matrix, &style);
		break;
	}
	case wxSVG_POLYLINE_ELEMENT: {
		wxSVGPolylineElement* element = (wxSVGPolylineElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawPolyline(element, &matrix, &style);
		break;
	}
	case wxSVG_POLYGON_ELEMENT: {
		wxSVGPolygonElement* element = (wxSVGPolygonElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawPolygon(element, &matrix, &style);
		break;
	}
	case wxSVG_RECT_ELEMENT: {
		wxSVGRectElement* element = (wxSVGRectElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawRect(element, &matrix, &style);
		break;
	}
	case wxSVG_CIRCLE_ELEMENT: {
		wxSVGCircleElement* element = (wxSVGCircleElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawCircle(element, &matrix, &style);
		break;
	}
	case wxSVG_ELLIPSE_ELEMENT: {
		wxSVGEllipseElement* element = (wxSVGEllipseElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawEllipse(element, &matrix, &style);
		break;
	}
	case wxSVG_PATH_ELEMENT: {
		wxSVGPathElement* element = (wxSVGPathElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawPath(element, &matrix, &style);
		break;
	}
	case wxSVG_TSPAN_ELEMENT:
		break;
	case wxSVG_TEXT_ELEMENT: {
		wxSVGTextElement* element = (wxSVGTextElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawText(element, &matrix, &style);
		break;
	}
	case wxSVG_IMAGE_ELEMENT: {
		wxSVGImageElement* element = (wxSVGImageElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN || element->GetOpacity() == 0)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		DrawImage(element, &matrix, &style, rect, progressDlg);
		break;
	}
	case wxSVG_VIDEO_ELEMENT: {
		wxSVGVideoElement* element = (wxSVGVideoElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN || element->GetOpacity() == 0)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
#ifdef USE_LIBAV
		DrawVideo(element, &matrix, &style);
#else
		wxSVGGElement* gElem = new wxSVGGElement();
		gElem->SetOwnerSVGElement(ownerSVGElement);
		gElem->SetViewportElement(viewportElement);
		gElem->SetStyle(element->GetStyle());
		wxSVGRectElement* rectElem = new wxSVGRectElement();
		rectElem->SetX(element->GetX().GetAnimVal());
		rectElem->SetY(element->GetY().GetAnimVal());
		rectElem->SetWidth(element->GetWidth().GetAnimVal());
		rectElem->SetHeight(element->GetHeight().GetAnimVal());
		rectElem->SetFill(wxSVGPaint(0,0,0));
		gElem->AppendChild(rectElem);
		wxSVGTextElement* textElem = new wxSVGTextElement;
		textElem->SetX((double)element->GetX().GetAnimVal());
		textElem->SetY(element->GetY().GetAnimVal()+(double)element->GetHeight().GetAnimVal()/10);
		textElem->SetFontSize((double)element->GetHeight().GetAnimVal()/15);
		textElem->SetFill(wxSVGPaint(255,255,255));
		textElem->SetStroke(wxSVGPaint(255,255,255));
		textElem->AddChild(new wxSvgXmlNode(wxSVGXML_TEXT_NODE, wxT(""), wxT(" [") + element->GetHref() + wxT("]")));
		gElem->AppendChild(textElem);

		// render
		RenderElement(gElem, rect, &matrix, &style, ownerSVGElement, viewportElement, progressDlg);
		// delete shadow tree
		delete gElem;
#endif
		break;
	}
	case wxSVG_USE_ELEMENT: {
		wxSVGUseElement* element = (wxSVGUseElement*) elem;
		if (element->GetVisibility() == wxCSS_VALUE_HIDDEN)
			break;
		element->UpdateMatrix(matrix);
		style.Add(element->GetStyle());
		style.Add(element->GetAnimStyle());
		// test if visible
		if (element->GetWidth().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN
				&& element->GetHeight().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN) {
			if (rect && !ownerSVGElement->CheckIntersection(*elem, *rect))
				break;
			wxSVGPoint point(element->GetX().GetAnimVal() + element->GetWidth().GetAnimVal(),
					element->GetY().GetAnimVal() + element->GetHeight().GetAnimVal());
			point = point.MatrixTransform(matrix);
			if (point.GetX() < 0 || point.GetY() < 0)
				break;
		}
		// get ref element
		wxString href = element->GetHref();
		if (href.length() == 0 || href.GetChar(0) != wxT('#'))
			break;
		href.Remove(0, 1);
		wxSVGElement* refElem = (wxSVGElement*) ownerSVGElement->GetElementById(href);
		if (!refElem)
			break;

		// create shadow tree
		wxSVGGElement* gElem = new wxSVGGElement();
		gElem->SetOwnerDocument(elem->GetOwnerDocument());
		gElem->SetOwnerSVGElement(ownerSVGElement);
		gElem->SetViewportElement(viewportElement);
		gElem->SetStyle(element->GetStyle());
		if (element->GetX().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN)
			gElem->Translate(element->GetX().GetAnimVal(), element->GetY().GetAnimVal());
		if (refElem->GetDtd() == wxSVG_SYMBOL_ELEMENT || refElem->GetDtd() == wxSVG_SVG_ELEMENT) {
			wxSVGSVGElement* svgElem;
			if (refElem->GetDtd() == wxSVG_SVG_ELEMENT)
				svgElem = (wxSVGSVGElement*) refElem->CloneNode();
			else {
				svgElem = new wxSVGSVGElement();
				wxSvgXmlElement* child = refElem->GetChildren();
				while (child) {
					svgElem->AddChild(child->CloneNode());
					child = child->GetNext();
				}
				svgElem->SetViewBox(((wxSVGSymbolElement*) refElem)->GetViewBox());
				svgElem->SetPreserveAspectRatio(((wxSVGSymbolElement*) refElem)->GetPreserveAspectRatio());
			}
			if (element->GetWidth().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN)
				svgElem->SetWidth(element->GetWidth().GetAnimVal());
			if (element->GetHeight().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN)
				svgElem->SetHeight(element->GetHeight().GetAnimVal());
			gElem->AddChild(svgElem);
			LoadImages(refElem, svgElem, progressDlg);
		} else
			gElem->AddChild(refElem->CloneNode());
		// render
		RenderElement(gElem, rect, &matrix, &style, ownerSVGElement, viewportElement, progressDlg);
		// delete shadow tree
		delete gElem;
		break;
	}
	default:
	  break;
  }
}