@Test public final void testProgramLinkValidAttributesMatrices1() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex( "attributes2", this.getShaderLines("attributes2.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("attributes2", v, Optional.empty(), f); Assert.assertEquals("attributes2", p.getName()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.getGLName() > 0); final Map<String, JCGLProgramAttributeType> a = p.getAttributes(); Assert.assertEquals(3L, (long) a.size()); final Set<Integer> locations = new HashSet<>(a.values().size()); for (final JCGLProgramAttributeType attr : a.values()) { final Integer id = Integer.valueOf(attr.getGLName()); Assert.assertTrue(id.intValue() >= 0); Assert.assertFalse(locations.contains(id)); locations.add(id); } JCGLShadersContract.checkAttribute( p, a, "m4", JCGLType.TYPE_FLOAT_MATRIX_4); JCGLShadersContract.checkAttribute( p, a, "m3", JCGLType.TYPE_FLOAT_MATRIX_4x3); JCGLShadersContract.checkAttribute( p, a, "m2", JCGLType.TYPE_FLOAT_MATRIX_4x2); }
@Test public final void testProgramLinkValidAttributesMatrices3() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex( "attributes3", this.getShaderLines("attributes3.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("attributes3", v, Optional.empty(), f); Assert.assertEquals("attributes3", p.name()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.glName() > 0); final Map<String, JCGLProgramAttributeType> a = p.attributes(); Assert.assertEquals(3L, (long) a.size()); final Set<Integer> locations = new HashSet<>(a.values().size()); for (final JCGLProgramAttributeType attr : a.values()) { final Integer id = Integer.valueOf(attr.glName()); Assert.assertTrue(id.intValue() >= 0); Assert.assertFalse(locations.contains(id)); locations.add(id); } checkAttribute( p, a, "m4", JCGLType.TYPE_FLOAT_MATRIX_3x4); checkAttribute( p, a, "m3", JCGLType.TYPE_FLOAT_MATRIX_3); checkAttribute( p, a, "m2", JCGLType.TYPE_FLOAT_MATRIX_3x2); }
@Test public final void testProgramLinkValidUniforms3() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("valid0", this.getShaderLines("valid0.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment( "validarray0", this.getShaderLines("validarray0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("validarray0", v, Optional.empty(), f); Assert.assertEquals("validarray0", p.getName()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.getGLName() > 0); final Map<String, JCGLProgramUniformType> u = p.getUniforms(); Assert.assertEquals(1L, (long) u.size()); final Set<Integer> locations = new HashSet<>(u.values().size()); for (final JCGLProgramUniformType uni : u.values()) { final Integer id = Integer.valueOf(uni.getGLName()); Assert.assertTrue(id.intValue() >= 0); Assert.assertFalse(locations.contains(id)); locations.add(id); } JCGLShadersContract.checkUniform( p, u, "big_array[0]", JCGLType.TYPE_FLOAT_VECTOR_4, 16); }
@Override public void shaderDeleteProgram(final JCGLProgramShaderType p) throws JCGLException, JCGLExceptionDeleted { NullCheck.notNull(p, "Shader"); LWJGL3ProgramShader.checkProgramShader(this.context, p); JCGLResources.checkNotDeleted(p); if (LOG.isDebugEnabled()) { LOG.debug("delete program shader {}", p.name()); } GL20.glDeleteProgram(p.glName()); ((LWJGL3ObjectDeletable) p).setDeleted(); if (Objects.equals(p, this.current)) { this.current = null; } }
@Override public void shaderDeleteProgram(final JCGLProgramShaderType p) throws JCGLException, JCGLExceptionDeleted { NullCheck.notNull(p); LWJGL3ProgramShader.checkProgramShader(this.context, p); JCGLResources.checkNotDeleted(p); if (LWJGL3Shaders.LOG.isDebugEnabled()) { LWJGL3Shaders.LOG.debug("delete program shader {}", p.getName()); } GL20.glDeleteProgram(p.getGLName()); ((LWJGL3ObjectDeletable) p).setDeleted(); if (p.equals(this.current)) { this.current = null; } }
@Test public final void testProgramLinkValidUniforms3() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("valid0", this.getShaderLines("valid0.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment( "validarray0", this.getShaderLines("validarray0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("validarray0", v, Optional.empty(), f); Assert.assertEquals("validarray0", p.name()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.glName() > 0); final Map<String, JCGLProgramUniformType> u = p.uniforms(); Assert.assertEquals(1L, (long) u.size()); final Set<Integer> locations = new HashSet<>(u.values().size()); for (final JCGLProgramUniformType uni : u.values()) { final Integer id = Integer.valueOf(uni.glName()); Assert.assertTrue(id.intValue() >= 0); Assert.assertFalse(locations.contains(id)); locations.add(id); } checkUniform( p, u, "big_array[0]", JCGLType.TYPE_FLOAT_VECTOR_4, 16); }
s.shaderLinkProgram("valid0", v, Optional.of(g), f); Assert.assertEquals("valid0", p.getName()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.getGLName() > 0); final Set<JCGLReferableType> p_refs = p.getReferences(); Assert.assertEquals(3L, (long) p_refs.size()); Assert.assertTrue(p_refs.contains(f)); Assert.assertTrue(f_refs.contains(p)); final Map<String, JCGLProgramAttributeType> a = p.getAttributes(); Assert.assertEquals(1L, (long) a.size()); final Map<String, JCGLProgramUniformType> u = p.getUniforms(); Assert.assertEquals(0L, (long) u.size());
s.shaderLinkProgram("valid0", v, Optional.of(g), f); Assert.assertEquals("valid0", p.name()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.glName() > 0); final Set<JCGLReferableType> p_refs = p.references(); Assert.assertEquals(3L, (long) p_refs.size()); Assert.assertTrue(p_refs.contains(f)); Assert.assertTrue(f_refs.contains(p)); final Map<String, JCGLProgramAttributeType> a = p.attributes(); Assert.assertEquals(1L, (long) a.size()); final Map<String, JCGLProgramUniformType> u = p.uniforms(); Assert.assertEquals(0L, (long) u.size());
@Test public final void testProgramUniformPutVectorfWrongType() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("uniforms0", this.getShaderLines("uniforms0.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("uniforms0", v, Optional.empty(), f); final FloatBuffer buf = ByteBuffer.allocateDirect(4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); s.shaderActivateProgram(p); final JCGLProgramUniformType u = p.getUniforms().get("u"); this.expected.expect(JCGLExceptionProgramTypeError.class); s.shaderUniformPutVectorf(u, buf); }
@Test public final void testProgramUniformPutVectorfTooFew() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("uniforms0", this.getShaderLines("uniforms0.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("uniforms0", v, Optional.empty(), f); final FloatBuffer buf = ByteBuffer.allocateDirect(4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); s.shaderActivateProgram(p); final JCGLProgramUniformType u = p.uniforms().get("fv4"); this.expected.expect(JCGLExceptionProgramTypeError.class); s.shaderUniformPutVectorf(u, buf); }
@Override public void shaderDeleteProgram(final JCGLProgramShaderType p) throws JCGLException, JCGLExceptionDeleted { NullCheck.notNull(p); FakeCompatibilityChecks.checkProgramShader(this.context, p); JCGLResources.checkNotDeleted(p); FakeShaders.LOG.debug("delete program shader {}", p.getName()); ((FakeObjectDeletable) p).setDeleted(); if (p.equals(this.current)) { this.current = null; } }
@Override public void shaderDeleteProgram(final JCGLProgramShaderType p) throws JCGLException, JCGLExceptionDeleted { NullCheck.notNull(p, "Shader"); FakeCompatibilityChecks.checkProgramShader(this.context, p); JCGLResources.checkNotDeleted(p); LOG.debug("delete program shader {}", p.name()); ((FakeObjectDeletable) p).setDeleted(); if (Objects.equals(p, this.current)) { this.current = null; } }
@Test public final void testProgramDeleteSharedContext() { final JCGLSharedContextPair<JCGLShadersType> cp = this.getShadersSharedWith("main", "alt"); final JCGLContextType c0 = cp.getMasterContext(); final JCGLShadersType s0 = cp.getMasterValue(); final JCGLContextType c1 = cp.getSlaveContext(); final JCGLShadersType s1 = cp.getSlaveValue(); Assert.assertTrue(c0.contextIsCurrent()); Assert.assertFalse(c1.contextIsCurrent()); final JCGLGeometryShaderType g = s0.shaderCompileGeometry("valid0", this.getShaderLines("valid0.geom")); final JCGLVertexShaderType v = s0.shaderCompileVertex("valid0", this.getShaderLines("valid0.vert")); final JCGLFragmentShaderType f = s0.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s0.shaderLinkProgram("valid0", v, Optional.of(g), f); c0.contextReleaseCurrent(); c1.contextMakeCurrent(); s1.shaderDeleteProgram(p); Assert.assertTrue(p.isDeleted()); }
@Test public final void testProgramLinkSharedContext() { final JCGLSharedContextPair<JCGLShadersType> cp = this.getShadersSharedWith("main", "alt"); final JCGLContextType c0 = cp.getMasterContext(); final JCGLShadersType s0 = cp.getMasterValue(); final JCGLContextType c1 = cp.getSlaveContext(); final JCGLShadersType s1 = cp.getSlaveValue(); Assert.assertTrue(c0.contextIsCurrent()); Assert.assertFalse(c1.contextIsCurrent()); final JCGLGeometryShaderType g = s0.shaderCompileGeometry("valid0", this.getShaderLines("valid0.geom")); final JCGLVertexShaderType v = s0.shaderCompileVertex("valid0", this.getShaderLines("valid0.vert")); final JCGLFragmentShaderType f = s0.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); c0.contextReleaseCurrent(); c1.contextMakeCurrent(); final JCGLProgramShaderType p = s1.shaderLinkProgram("valid0", v, Optional.of(g), f); Assert.assertTrue(p.getGLName() > 0); }
@Test public final void testProgramLinkSharedContext() { final JCGLSharedContextPair<JCGLShadersType> cp = this.getShadersSharedWith("main", "alt"); final JCGLContextType c0 = cp.getMasterContext(); final JCGLShadersType s0 = cp.getMasterValue(); final JCGLContextType c1 = cp.getSlaveContext(); final JCGLShadersType s1 = cp.getSlaveValue(); Assert.assertTrue(c0.contextIsCurrent()); Assert.assertFalse(c1.contextIsCurrent()); final JCGLGeometryShaderType g = s0.shaderCompileGeometry("valid0", this.getShaderLines("valid0.geom")); final JCGLVertexShaderType v = s0.shaderCompileVertex("valid0", this.getShaderLines("valid0.vert")); final JCGLFragmentShaderType f = s0.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); c0.contextReleaseCurrent(); c1.contextMakeCurrent(); final JCGLProgramShaderType p = s1.shaderLinkProgram("valid0", v, Optional.of(g), f); Assert.assertTrue(p.glName() > 0); }
@Test public final void testProgramLinkValidUniforms2() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("uniforms2", this.getShaderLines("uniforms2.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("uniforms2", v, Optional.empty(), f); Assert.assertEquals("uniforms2", p.name()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.glName() > 0); final Map<String, JCGLProgramUniformType> u = p.uniforms(); Assert.assertEquals(3L, (long) u.size()); final Set<Integer> locations = new HashSet<>(u.values().size()); for (final JCGLProgramUniformType uni : u.values()) { final Integer id = Integer.valueOf(uni.glName()); Assert.assertTrue(id.intValue() >= 0); Assert.assertFalse(locations.contains(id)); locations.add(id); } checkUniform( p, u, "s2", JCGLType.TYPE_SAMPLER_2D, 1); checkUniform( p, u, "s3", JCGLType.TYPE_SAMPLER_3D, 1); checkUniform( p, u, "sc", JCGLType.TYPE_SAMPLER_CUBE, 1); }
@Test public final void testProgramUniformPutVectorfTooFew() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("uniforms0", this.getShaderLines("uniforms0.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("uniforms0", v, Optional.empty(), f); final FloatBuffer buf = ByteBuffer.allocateDirect(4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); s.shaderActivateProgram(p); final JCGLProgramUniformType u = p.getUniforms().get("fv4"); this.expected.expect(JCGLExceptionProgramTypeError.class); s.shaderUniformPutVectorf(u, buf); }
@Test public final void testProgramUniformUnsignedIntegerCorrect() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex("uniforms0", this.getShaderLines("uniforms0.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("uniforms0", v, Optional.empty(), f); final Map<String, JCGLProgramUniformType> us = p.uniforms(); Assert.assertTrue(us.containsKey("u")); final JCGLProgramUniformType u = us.get("u"); Assert.assertEquals(JCGLType.TYPE_UNSIGNED_INTEGER, u.type()); s.shaderActivateProgram(p); s.shaderUniformPutUnsignedInteger(u, 1); }
@Test public final void testProgramDeleteSharedContext() { final JCGLSharedContextPair<JCGLShadersType> cp = this.getShadersSharedWith("main", "alt"); final JCGLContextType c0 = cp.getMasterContext(); final JCGLShadersType s0 = cp.getMasterValue(); final JCGLContextType c1 = cp.getSlaveContext(); final JCGLShadersType s1 = cp.getSlaveValue(); Assert.assertTrue(c0.contextIsCurrent()); Assert.assertFalse(c1.contextIsCurrent()); final JCGLGeometryShaderType g = s0.shaderCompileGeometry("valid0", this.getShaderLines("valid0.geom")); final JCGLVertexShaderType v = s0.shaderCompileVertex("valid0", this.getShaderLines("valid0.vert")); final JCGLFragmentShaderType f = s0.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s0.shaderLinkProgram("valid0", v, Optional.of(g), f); c0.contextReleaseCurrent(); c1.contextMakeCurrent(); s1.shaderDeleteProgram(p); Assert.assertTrue(p.isDeleted()); }
@Test public final void testProgramLinkValidAttributesMatrices4() { final JCGLShadersType s = this.getShaders("main"); final JCGLVertexShaderType v = s.shaderCompileVertex( "attributes4", this.getShaderLines("attributes4.vert")); final JCGLFragmentShaderType f = s.shaderCompileFragment("valid0", this.getShaderLines("valid0.frag")); final JCGLProgramShaderType p = s.shaderLinkProgram("attributes4", v, Optional.empty(), f); Assert.assertEquals("attributes4", p.name()); Assert.assertFalse(p.isDeleted()); Assert.assertTrue(p.glName() > 0); final Map<String, JCGLProgramAttributeType> a = p.attributes(); Assert.assertEquals(3L, (long) a.size()); final Set<Integer> locations = new HashSet<>(a.values().size()); for (final JCGLProgramAttributeType attr : a.values()) { final Integer id = Integer.valueOf(attr.glName()); Assert.assertTrue(id.intValue() >= 0); Assert.assertFalse(locations.contains(id)); locations.add(id); } checkAttribute( p, a, "m4", JCGLType.TYPE_FLOAT_MATRIX_2x4); checkAttribute( p, a, "m3", JCGLType.TYPE_FLOAT_MATRIX_2x3); checkAttribute( p, a, "m2", JCGLType.TYPE_FLOAT_MATRIX_2); }