Exemple #1
0
  @Test
  public final void testIdentities() {
    final JCGLContextType c = this.newGL33Context("main", 24, 8);
    final JCGLInterfaceGL33Type g = c.contextGetGL33();
    final JCGLTextureUnitAllocatorType a =
        JCGLTextureUnitAllocator.newAllocatorWithStack(4, g.getTextures().textureGetUnits());

    final AreaInclusiveUnsignedL area =
        AreaInclusiveUnsignedL.of(
            new UnsignedRangeInclusiveL(0L, 639L), new UnsignedRangeInclusiveL(0L, 479L));
    final R2ImageBufferDescription desc = R2ImageBufferDescription.of(area, Optional.empty());

    final R2ImageBufferType gb =
        R2ImageBuffer.newImageBuffer(
            g.getFramebuffers(), g.getTextures(), a.getRootContext(), desc);

    Assert.assertEquals(640L * 480L * 4L, gb.getRange().getInterval());
    Assert.assertFalse(gb.isDeleted());

    final R2Texture2DUsableType t_rgba = gb.getRGBATexture();
    final JCGLFramebufferUsableType fb = gb.getPrimaryFramebuffer();

    Assert.assertEquals(desc, gb.getDescription());
    Assert.assertEquals(area, gb.getArea());

    Assert.assertEquals(
        JCGLTextureFormat.TEXTURE_FORMAT_RGBA_8_4BPP, t_rgba.get().textureGetFormat());

    gb.delete(g);
    Assert.assertTrue(fb.isDeleted());
    Assert.assertTrue(gb.isDeleted());
  }
Exemple #2
0
  @Test
  public final void testIdentitiesWithDepth() {
    final JCGLContextType c = this.newGL33Context("main", 24, 8);
    final JCGLInterfaceGL33Type g = c.contextGetGL33();
    final JCGLTextureUnitAllocatorType a =
        JCGLTextureUnitAllocator.newAllocatorWithStack(4, g.getTextures().textureGetUnits());

    for (final R2DepthPrecision dp : R2DepthPrecision.values()) {
      final AreaInclusiveUnsignedL area =
          AreaInclusiveUnsignedL.of(
              new UnsignedRangeInclusiveL(0L, 639L), new UnsignedRangeInclusiveL(0L, 479L));
      final R2ImageBufferDescription desc = R2ImageBufferDescription.of(area, Optional.of(dp));

      final R2ImageBufferType gb =
          R2ImageBuffer.newImageBuffer(
              g.getFramebuffers(), g.getTextures(), a.getRootContext(), desc);

      long pixel_size = 4L;
      switch (dp) {
        case R2_DEPTH_PRECISION_16:
          pixel_size += 2L;
          break;
        case R2_DEPTH_PRECISION_24:
          pixel_size += 4L;
          break;
        case R2_DEPTH_PRECISION_32F:
          pixel_size += 4L;
          break;
      }

      Assert.assertEquals(640L * 480L * pixel_size, gb.getRange().getInterval());
      Assert.assertFalse(gb.isDeleted());

      final R2Texture2DUsableType t_rgba = gb.getRGBATexture();
      final JCGLFramebufferUsableType fb = gb.getPrimaryFramebuffer();

      Assert.assertEquals(desc, gb.getDescription());
      Assert.assertEquals(area, gb.getArea());

      Assert.assertEquals(
          JCGLTextureFormat.TEXTURE_FORMAT_RGBA_8_4BPP, t_rgba.get().textureGetFormat());

      gb.delete(g);
      Assert.assertTrue(fb.isDeleted());
      Assert.assertTrue(gb.isDeleted());
    }
  }
Exemple #3
0
  @Test
  public final void testFramebufferBindingNonDefaultNotProvided() {
    final JCGLContextType c = this.newGL33Context("main", 24, 8);
    final JCGLInterfaceGL33Type g = c.contextGetGL33();

    final JCGLFramebuffersType g_fb = g.getFramebuffers();

    final AreaInclusiveUnsignedL area =
        AreaInclusiveUnsignedL.of(
            new UnsignedRangeInclusiveL(0L, 639L), new UnsignedRangeInclusiveL(0L, 479L));

    final JCGLTextureUnitAllocatorType ta =
        JCGLTextureUnitAllocator.newAllocatorWithStack(8, g.getTextures().textureGetUnits());
    final JCGLTextureUnitContextParentType tc = ta.getRootContext();
    final R2TextureDefaultsType td = R2TextureDefaults.newDefaults(g.getTextures(), tc);

    final R2UnitSphereType sphere = R2UnitSphere.newUnitSphere8(g);
    final R2UnitQuadType quad = R2UnitQuad.newUnitQuad(g);
    final R2IDPoolType id_pool = R2IDPool.newPool();

    final JCGLProfilingType pro = JCGLProfiling.newProfiling(g.getTimers());
    final JCGLProfilingFrameType pro_frame = pro.startFrame();
    final JCGLProfilingContextType pro_root = pro_frame.getChildContext("main");

    final R2SceneLightsType s = R2LightRendererContract.newScene(g, sphere, id_pool);

    final R2ShadowMapContextUsableType shadows =
        ls -> {
          throw new UnreachableCodeException();
        };

    final R2ProjectionOrthographic proj =
        R2ProjectionOrthographic.newFrustum(JCGLProjectionMatrices.newMatrices());

    final R2ShaderSourcesType ss = R2ShaderSourcesResources.newSources(R2Shaders.class);
    final R2LightRendererType r = this.getRenderer(g, td, ss, id_pool, quad);

    final R2GeometryBufferType gbuffer =
        R2GeometryBuffer.newGeometryBuffer(
            g_fb,
            g.getTextures(),
            tc,
            R2GeometryBufferDescription.of(
                area, R2GeometryBufferComponents.R2_GEOMETRY_BUFFER_FULL));

    final R2LightBufferType lbuffer =
        R2LightBuffers.newLightBuffer(
            g_fb,
            g.getTextures(),
            tc,
            R2LightBufferDescription.of(
                area, R2LightBufferComponents.R2_LIGHT_BUFFER_DIFFUSE_AND_SPECULAR));

    g_fb.framebufferReadUnbind();
    Assert.assertTrue(g_fb.framebufferDrawIsBound(lbuffer.getPrimaryFramebuffer()));

    final R2MatricesType m = R2Matrices.newMatrices();
    m.withObserver(
        PMatrixI4x4F.identity(),
        proj,
        Unit.unit(),
        (x, y) -> {
          r.renderLights(gbuffer, area, Optional.empty(), pro_root, tc, shadows, x, s);
          return Unit.unit();
        });

    Assert.assertFalse(g_fb.framebufferReadAnyIsBound());
    Assert.assertTrue(g_fb.framebufferDrawIsBound(lbuffer.getPrimaryFramebuffer()));
  }