/** Sets the sides of this cubemap to the specified {@link CubemapData}. */ public void load (CubemapData data) { if (!data.isPrepared()) data.prepare(); bind(); unsafeSetFilter(minFilter, magFilter, true); unsafeSetWrap(uWrap, vWrap, true); data.consumeCubemapData(); Gdx.gl.glBindTexture(glTarget, 0); }
@Override public int hashCode () { long result = (texture == null ? 0 : texture.glTarget); result = 811 * result + (texture == null ? 0 : texture.getTextureObjectHandle()); result = 811 * result + (minFilter == null ? 0 : minFilter.getGLEnum()); result = 811 * result + (magFilter == null ? 0 : magFilter.getGLEnum()); result = 811 * result + (uWrap == null ? 0 : uWrap.getGLEnum()); result = 811 * result + (vWrap == null ? 0 : vWrap.getGLEnum()); return (int)(result ^ (result >> 32)); }
@Override protected void attachFrameBufferColorTexture (Cubemap texture) { GL20 gl = Gdx.gl20; int glHandle = texture.getTextureObjectHandle(); Cubemap.CubemapSide[] sides = Cubemap.CubemapSide.values(); for (Cubemap.CubemapSide side : sides) { gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, glHandle, 0); } }
/** Draws the given {@link Pixmap} to the texture at position x, y. No clipping is performed so you have to make sure that you * draw only inside the texture region. Note that this will only draw to mipmap level 0! * * @param pixmap The Pixmap * @param x The x coordinate in pixels * @param y The y coordinate in pixels */ public void draw (Pixmap pixmap, int x, int y) { if (data.isManaged()) throw new GdxRuntimeException("can't draw to a managed texture"); bind(); Gdx.gl.glTexSubImage2D(glTarget, 0, x, y, pixmap.getWidth(), pixmap.getHeight(), pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); }
private static void generateMipMapGLES20 (int target, Pixmap pixmap) { Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); Gdx.gl20.glGenerateMipmap(target); }
private int addVertex (int i, int j, float[] vertsOut, Pixmap heightmap, int idx) { int pixel = heightmap.getPixel((int) (i/100f * heightmap.getWidth()), (int)(j/100f * heightmap.getHeight())); tmpColor.set(pixel); vertsOut[idx++] = i/5f; vertsOut[idx++] = tmpColor.r * 25f/5f; vertsOut[idx++] = j/ 5f; vertsOut[idx++] = i/20f; vertsOut[idx++] = j/20f; vertsOut[idx++] = (tmpColor.r * 3f) - 0.5f; return idx; }
private void createQuad () { if (quad != null) return; quad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); quad.setVertices(new float[] {-1, -1, 0, 1, 1, 1, 1, 0, 1, 1, -1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 0, 0}); quad.setIndices(new short[] {0, 1, 2, 2, 3, 0}); }
private void load (TextureArrayData data) { if (this.data != null && data.isManaged() != this.data.isManaged()) throw new GdxRuntimeException("New data must have the same managed status as the old data"); this.data = data; bind(); Gdx.gl30.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, data.getInternalFormat(), data.getWidth(), data.getHeight(), data.getDepth(), 0, data.getInternalFormat(), data.getGLType(), null); if (!data.isPrepared()) data.prepare(); data.consumeTextureArrayData(); setFilter(minFilter, magFilter); setWrap(uWrap, vWrap); Gdx.gl.glBindTexture(glTarget, 0); }
/** Create a ShapeCache with default values */ public ShapeCache () { this(5000, 5000, new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute( Usage.ColorPacked, 4, "a_color")), GL20.GL_LINES); }
/** Sets the {@link TextureFilter} for this texture for minification and magnification. This will bind this texture! * @param minFilter the minification filter * @param magFilter the magnification filter */ public void setFilter (TextureFilter minFilter, TextureFilter magFilter) { this.minFilter = minFilter; this.magFilter = magFilter; bind(); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_MIN_FILTER, minFilter.getGLEnum()); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_MAG_FILTER, magFilter.getGLEnum()); }
/** Sets the {@link TextureWrap} for this texture on the u and v axis. This will bind this texture! * @param u the u wrap * @param v the v wrap */ public void setWrap (TextureWrap u, TextureWrap v) { this.uWrap = u; this.vWrap = v; bind(); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_WRAP_S, u.getGLEnum()); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_WRAP_T, v.getGLEnum()); }
protected Texture (int glTarget, int glHandle, TextureData data) { super(glTarget, glHandle); load(data); if (data.isManaged()) addManagedTexture(Gdx.app, this); }
/** Sets the sides of this cubemap to the specified {@link CubemapData}. */ public void load (CubemapData data) { if (!data.isPrepared()) data.prepare(); bind(); unsafeSetFilter(minFilter, magFilter, true); unsafeSetWrap(uWrap, vWrap, true); data.consumeCubemapData(); Gdx.gl.glBindTexture(glTarget, 0); }
/** Sets the {@link TextureFilter} for this texture for minification and magnification. This will bind this texture! * @param minFilter the minification filter * @param magFilter the magnification filter */ public void setFilter (TextureFilter minFilter, TextureFilter magFilter) { this.minFilter = minFilter; this.magFilter = magFilter; bind(); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_MIN_FILTER, minFilter.getGLEnum()); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_MAG_FILTER, magFilter.getGLEnum()); }
/** Sets the {@link TextureWrap} for this texture on the u and v axis. This will bind this texture! * @param u the u wrap * @param v the v wrap */ public void setWrap (TextureWrap u, TextureWrap v) { this.uWrap = u; this.vWrap = v; bind(); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_WRAP_S, u.getGLEnum()); Gdx.gl.glTexParameteri(glTarget, GL20.GL_TEXTURE_WRAP_T, v.getGLEnum()); }
@Override public int hashCode () { long result = (texture == null ? 0 : texture.glTarget); result = 811 * result + (texture == null ? 0 : texture.getTextureObjectHandle()); result = 811 * result + (minFilter == null ? 0 : minFilter.getGLEnum()); result = 811 * result + (magFilter == null ? 0 : magFilter.getGLEnum()); result = 811 * result + (uWrap == null ? 0 : uWrap.getGLEnum()); result = 811 * result + (vWrap == null ? 0 : vWrap.getGLEnum()); return (int)(result ^ (result >> 32)); }
@Override protected void attachFrameBufferColorTexture (Cubemap texture) { GL20 gl = Gdx.gl20; int glHandle = texture.getTextureObjectHandle(); Cubemap.CubemapSide[] sides = Cubemap.CubemapSide.values(); for (Cubemap.CubemapSide side : sides) { gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, glHandle, 0); } }