Пример #1
0
 private void invalidateRTT() {
   if (rtt != null) {
     // TODO as possibile optimization by keeping old rtt if SubScene
     // becomes smaller
     rtt.dispose();
     rtt = null;
   }
 }
Пример #2
0
 private void applyBackgroundFillPaint(Graphics g) {
   isOpaque = true;
   if (fillPaint != null) {
     if (fillPaint instanceof Color) {
       Color fillColor = (Color) fillPaint;
       isOpaque = (fillColor.getAlpha() >= 1.0);
       g.clear(fillColor);
     } else {
       if (!fillPaint.isOpaque()) {
         g.clear();
         isOpaque = false;
       }
       g.setPaint(fillPaint);
       g.fillRect(0, 0, rtt.getContentWidth(), rtt.getContentHeight());
     }
   } else {
     isOpaque = false;
     // Default is transparent
     g.clear();
   }
 }
Пример #3
0
  @Override
  protected void renderContent(Graphics g) {
    if (rtWidth <= 0.0 || rtHeight <= 0.0) {
      return;
    }
    if (rtt != null) {
      rtt.lock();
      if (rtt.isSurfaceLost()) {
        renderSG = true;
        rtt = null;
      }
    }

    if (renderSG || !root.isClean()) {
      if (rtt == null) {
        ResourceFactory factory = g.getResourceFactory();
        rtt =
            factory.createRTTexture(
                rtWidth, rtHeight, Texture.WrapMode.CLAMP_NOT_NEEDED, antiAliasing);
      }
      Graphics rttGraphics = rtt.createGraphics();
      rttGraphics.setLights(lights);

      rttGraphics.setDepthBuffer(depthBuffer);
      if (camera != null) {
        rttGraphics.setCamera(camera);
      }
      applyBackgroundFillPaint(rttGraphics);
      rttGraphics.setTransform(BaseTransform.IDENTITY_TRANSFORM);

      root.render(rttGraphics);
      root.clearDirtyTree();
      renderSG = false;
    }
    if (antiAliasing) {
      int x0 = rtt.getContentX();
      int y0 = rtt.getContentY();
      int x1 = x0 + rtt.getContentWidth();
      int y1 = y0 + rtt.getContentHeight();
      if ((isOpaque || g.getCompositeMode() == CompositeMode.SRC)
          && g.getTransformNoClone().isTranslateOrIdentity()
          && !g.isDepthTest()) {
        // Round translation to closest pixel
        int tx = (int) (g.getTransformNoClone().getMxt() + 0.5);
        int ty = (int) (g.getTransformNoClone().getMyt() + 0.5);
        // Blit SubScene directly to scene surface

        // Intersect src and dst boundaries.
        // On D3D if blit is called outside boundary it will draw
        // nothing. Using intersect prevents that from occurring.
        int dstX0 = x0 + tx;
        int dstY0 = y0 + ty;
        int dstX1 = x1 + tx;
        int dstY1 = y1 + ty;
        int dstW = g.getRenderTarget().getContentWidth();
        int dstH = g.getRenderTarget().getContentHeight();
        int dX = dstX1 > dstW ? dstW - dstX1 : 0;
        int dY = dstY1 > dstH ? dstH - dstY1 : 0;
        g.blit(rtt, null, x0, y0, x1 + dX, y1 + dY, dstX0, dstY0, dstX1 + dX, dstY1 + dY);
      } else {
        if (resolveRTT != null
            && (resolveRTT.getContentWidth() < rtt.getContentWidth()
                || (resolveRTT.getContentHeight() < rtt.getContentHeight()))) {
          // If msaa rtt is larger than resolve buffer, then dispose
          resolveRTT.dispose();
          resolveRTT = null;
        }
        if (resolveRTT == null || resolveRTT.isSurfaceLost()) {
          resolveRTT =
              g.getResourceFactory()
                  .createRTTexture(rtWidth, rtHeight, Texture.WrapMode.CLAMP_NOT_NEEDED, false);
        } else {
          resolveRTT.lock();
        }
        g.blit(rtt, resolveRTT, x0, y0, x1, y1, x0, y0, x1, y1);
        g.drawTexture(
            resolveRTT,
            rtt.getContentX(),
            rtt.getContentY(),
            rtt.getContentWidth(),
            rtt.getContentHeight());
        resolveRTT.unlock();
      }
    } else {
      g.drawTexture(
          rtt, rtt.getContentX(), rtt.getContentY(), rtt.getContentWidth(), rtt.getContentHeight());
    }
    rtt.unlock();
  }