@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()); }
@Override protected JCGLUnsharedContextPair<JCGLIndexBuffersType> getIndexBuffersUnshared( final String main, final String alt) { final JCGLContextType c0 = LWJGL3TestContexts.newGL33Context(main, 24, 8); final JCGLContextType c1 = LWJGL3TestContexts.newGL33Context(alt, 24, 8); return new JCGLUnsharedContextPair<>( c0.contextGetGL33().getIndexBuffers(), c0, c1.contextGetGL33().getIndexBuffers(), c1); }
@Override protected Interfaces getIndexBuffers(final String name) { final JCGLContextType c = LWJGL3TestContexts.newGL33Context(name, 24, 8); final JCGLInterfaceGL33Type cg = c.contextGetGL33(); final JCGLArrayBuffersType ga = cg.getArrayBuffers(); final JCGLIndexBuffersType gi = cg.getIndexBuffers(); final JCGLArrayObjectsType go = cg.getArrayObjects(); return new Interfaces(c, ga, gi, go); }
@Override protected JCGLSharedContextPair<JCGLIndexBuffersType> getIndexBuffersSharedWith( final String name, final String shared) { final JCGLSharedContextPair<JCGLContextType> p = LWJGL3TestContexts.newGL33ContextSharedWith(name, shared); final JCGLContextType mc = p.getMasterContext(); final JCGLContextType sc = p.getSlaveContext(); return new JCGLSharedContextPair<>( mc.contextGetGL33().getIndexBuffers(), mc, sc.contextGetGL33().getIndexBuffers(), sc); }
/** * Main program. * * @param args Command line arguments * @throws Exception On errors */ public static void main(final String[] args) throws Exception { if (args.length != 3 && args.length != 4) { Main.LOG.info("usage: root file.vert [file.geom] file.frag"); System.exit(1); } final File root = new File(args[0]); final R2ShaderPreprocessorType p = R2ShaderPreprocessor.newPreprocessor(root); List<String> vs = null; Optional<List<String>> gs = null; List<String> fs = null; try { if (args.length == 4) { vs = p.preprocessFile(args[1]); gs = Optional.of(p.preprocessFile(args[2])); fs = p.preprocessFile(args[3]); } else { vs = p.preprocessFile(args[1]); gs = Optional.empty(); fs = p.preprocessFile(args[2]); } } catch (final Exception e) { Main.LOG.error("Preprocessing failure: ", e); System.exit(1); } final GLProfile pro = GLProfile.get(GLProfile.GL3); final GLCapabilities caps = new GLCapabilities(pro); final GLDrawableFactory f = GLDrawableFactory.getFactory(pro); final GLOffscreenAutoDrawable drawable = f.createOffscreenAutoDrawable(null, caps, null, 32, 32); drawable.display(); final GLContext ctx = drawable.getContext(); ctx.makeCurrent(); try { final JCGLImplementationJOGLType i = JCGLImplementationJOGL.getInstance(); final JCGLContextType jc = i.newContextFrom(ctx, "offscreen"); final JCGLInterfaceGL33Type gi = jc.contextGetGL33(); final R2ShaderCheckerType ch = R2ShaderChecker.newChecker(gi.getShaders()); ch.check(vs, gs, fs); } finally { ctx.release(); drawable.destroy(); } }
@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()); } }
@Test public final void testIdentities() { final JCGLContextType c = this.newGL33Context("main", 24, 8); final JCGLInterfaceGL33Type g = c.contextGetGL33(); final JCGLTextureUnitAllocatorType ta = JCGLTextureUnitAllocator.newAllocatorWithStack(8, g.getTextures().textureGetUnits()); final JCGLTextureUnitContextParentType tc = ta.getRootContext(); final R2TextureDefaultsType td = R2TextureDefaults.newDefaults(g.getTextures(), tc); final R2UnitQuadType quad = R2UnitQuad.newUnitQuad(g); final R2ShaderSourcesType ss = R2ShaderSourcesResources.newSources(R2Shaders.class); final R2IDPoolType id_pool = R2IDPool.newPool(); final R2LightRendererType r = this.getRenderer(g, td, ss, id_pool, quad); Assert.assertFalse(r.isDeleted()); r.delete(g); Assert.assertTrue(r.isDeleted()); }
@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())); }