private void load(ByteBuffer pixels) { int target = GL11.GL_TEXTURE_2D; int type = TYPE_MAP[getComponentType().ordinal()]; int internalFormat = INTERNAL_FORMAT_MAP[getComponentType().ordinal()][getComponentFormat().ordinal()]; int format = FORMAT_MAP[getComponentFormat().ordinal()]; switch (getComponentFormat()) { case G: GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_R, GL11.GL_RED); GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_G, GL11.GL_RED); GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_B, GL11.GL_RED); break; case GA: GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_R, GL11.GL_RED); GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_G, GL11.GL_RED); GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_B, GL11.GL_RED); GL11.glTexParameteri(target, GL33.GL_TEXTURE_SWIZZLE_A, GL11.GL_GREEN); break; default: } GL11.glTexImage2D(target, 0, internalFormat, getWidth(), getHeight(), 0, format, type, pixels); }
/** * Bind this attrib, automatically binds multiple attribs for more than 4 compnent objects * @param attrib The starting attrib * @return The ending attrib */ public int bind(int attrib) { int sizeNeeded = size; vbo.bind(); for (int i = 0; i < requiredAttribs(); i++) { GL20.glEnableVertexAttribArray(attrib); GL20.glVertexAttribPointer(attrib, Math.min(sizeNeeded, 4), type, normalized, stride, offset + extraOffset * i); if (instanced) GL33.glVertexAttribDivisor(attrib, 1); attrib++; sizeNeeded -= 4; } vbo.unbind(); return attrib; }
private static void buildMapping() { if (mapping != null) return; Multimap<Integer, String> map = HashMultimap.create(); List<Class<?>> classes = ImmutableList.of( GL11.class, GL12.class, GL13.class, GL14.class, GL15.class, GL20.class, GL21.class, GL30.class, GL31.class, GL32.class, GL33.class, GL40.class, GL41.class, GL42.class, GL43.class, GL44.class, GL45.class, GLFW.class ); for (Class<?> clazz : classes) { for (Field f : clazz.getDeclaredFields()) { if (f.getName().toUpperCase(Locale.ROOT).equals(f.getName()) && f.getType() == int.class && Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) { List<String> li = Splitter.on('_').splitToList(f.getName()); li = li.subList(1, li.size()); String clean = Joiner.on(' ').join( li.stream() .map(Errors::toTitleCase) .iterator()); try { map.put(f.getInt(null), clean); } catch (Throwable t) { t.printStackTrace(); } } } } mapping = map; }
public void addInstancedAttribute(int vao, int vbo, int attribute, int dataSize, int instancedDataLength, int offset) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL30.glBindVertexArray(vao); GL20.glVertexAttribPointer(attribute, dataSize, GL11.GL_FLOAT, false, instancedDataLength * 4, offset * 4); GL33.glVertexAttribDivisor(attribute, 1); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
public static void glVertexAttribDivisor(int index, int divisor) { if(GL_VERSION >= 33) { GL33.glVertexAttribDivisor(index, divisor); } else if(GLContext.getCapabilities().GL_ARB_instanced_arrays) { ARBInstancedArrays.glVertexAttribDivisorARB(index, divisor); } else { throw new UnsupportedOperationException("GL_ARB_instanced_arrays not supported on this system."); } }
public static int glGenSampler() throws GLException { int ret = GL33.glGenSamplers(); RenderHelper.checkForGLError(); return ret; }
public static int glGetFragDataIndex(int program, String name) throws GLException { int ret = GL33.glGetFragDataIndex(program, name); RenderHelper.checkForGLError(); return ret; }
public static long glGetQueryObjecti64(int id, int pname) throws GLException { long ret = GL33.glGetQueryObjecti64(id, pname); RenderHelper.checkForGLError(); return ret; }
public static long glGetQueryObjectui64(int id, int pname) throws GLException { long ret = GL33.glGetQueryObjectui64(id, pname); RenderHelper.checkForGLError(); return ret; }
public static float glGetSamplerParameterf(int sampler, int pname) throws GLException { float ret = GL33.glGetSamplerParameterf(sampler, pname); RenderHelper.checkForGLError(); return ret; }
public static int glGetSamplerParameteri(int sampler, int pname) throws GLException { int ret = GL33.glGetSamplerParameteri(sampler, pname); RenderHelper.checkForGLError(); return ret; }
public static int glGetSamplerParameterIi(int sampler, int pname) throws GLException { int ret = GL33.glGetSamplerParameterIi(sampler, pname); RenderHelper.checkForGLError(); return ret; }
public static int glGetSamplerParameterIui(int sampler, int pname) throws GLException { int ret = GL33.glGetSamplerParameterIui(sampler, pname); RenderHelper.checkForGLError(); return ret; }
@Override public void glGenSamplers (int count, int[] samplers, int offset) { for(int i = offset; i < offset + count; i++) { samplers[i] = GL33.glGenSamplers(); } }
@Override public void glGenSamplers (int count, IntBuffer samplers) { GL33.glGenSamplers(samplers); }
@Override public void glDeleteSamplers (int count, int[] samplers, int offset) { for(int i = offset; i < offset + count; i++) { GL33.glDeleteSamplers(samplers[i]); } }
@Override public void glDeleteSamplers (int count, IntBuffer samplers) { GL33.glDeleteSamplers(samplers); }
@Override public boolean glIsSampler (int sampler) { return GL33.glIsSampler(sampler); }
@Override public void glBindSampler (int unit, int sampler) { GL33.glBindSampler(unit, sampler); }
@Override public void glSamplerParameteri (int sampler, int pname, int param) { GL33.glSamplerParameteri(sampler, pname, param); }
@Override public void glSamplerParameteriv (int sampler, int pname, IntBuffer param) { GL33.glSamplerParameteriv(sampler, pname, param); }
@Override public void glSamplerParameterf (int sampler, int pname, float param) { GL33.glSamplerParameterf(sampler, pname, param); }
@Override public void glSamplerParameterfv (int sampler, int pname, FloatBuffer param) { GL33.glSamplerParameterfv(sampler, pname, param); }
@Override public void glGetSamplerParameteriv (int sampler, int pname, IntBuffer params) { GL33.glGetSamplerParameteriv(sampler, pname, params); }
@Override public void glGetSamplerParameterfv (int sampler, int pname, FloatBuffer params) { GL33.glGetSamplerParameterfv(sampler, pname, params); }
@Override public void glVertexAttribDivisor (int index, int divisor) { GL33.glVertexAttribDivisor(index, divisor); }
/** Set the bound vbo as an instanced attribute to the vertex array */ public void setAttributeInstanced(int attributeID, int length, int type, boolean normalized, int stride, int offset) { this.setAttribute(attributeID, length, type, normalized, stride, offset); GL33.glVertexAttribDivisor(attributeID, 1); }
@Override public void glSamplerParameteriv (int sampler, int pname, IntBuffer param) { GL33.glSamplerParameter(sampler, pname, param); }
@Override public void glSamplerParameterfv (int sampler, int pname, FloatBuffer param) { GL33.glSamplerParameter(sampler, pname, param); }
@Override public void glGetSamplerParameteriv (int sampler, int pname, IntBuffer params) { GL33.glGetSamplerParameterI(sampler, pname, params); }
@Override public void glGetSamplerParameterfv (int sampler, int pname, FloatBuffer params) { GL33.glGetSamplerParameter(sampler, pname, params); }