public void modifyTexture(Texture tex, Image pixels, int x, int y) { setTexture(0, tex); TextureUtil.uploadSubTexture(pixels, convertTextureType(tex.getType()), 0, x, y); }
public void updateTexImageData(Image img, Texture.Type type, int unit) { int texId = img.getId(); if (texId == -1) { // create texture glGenTextures(ib1); texId = ib1.get(0); img.setId(texId); objManager.registerObject(img); statistics.onNewTexture(); } // bind texture int target = convertTextureType(type); // if (context.boundTextureUnit != unit) { // glActiveTexture(GL_TEXTURE0 + unit); // context.boundTextureUnit = unit; // } if (context.boundTextures[unit] != img) { glEnable(target); glBindTexture(target, texId); context.boundTextures[unit] = img; statistics.onTextureUse(img, true); } // Check sizes if graphics card doesn't support NPOT if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) { if (img.getWidth() != 0 && img.getHeight() != 0) { if (!FastMath.isPowerOfTwo(img.getWidth()) || !FastMath.isPowerOfTwo(img.getHeight())) { // Resize texture to Power-of-2 size MipMapGenerator.resizeToPowerOf2(img); } } } if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { // No pregenerated mips available, // generate from base level if required // Check if hardware mips are supported if (GLContext.getCapabilities().OpenGL14) { glTexParameteri(target, GL14.GL_GENERATE_MIPMAP, GL_TRUE); } else { MipMapGenerator.generateMipMaps(img); } img.setMipmapsGenerated(true); } else { } if (img.getWidth() > maxTexSize || img.getHeight() > maxTexSize) { throw new RendererException( "Cannot upload texture " + img + ". The maximum supported texture resolution is " + maxTexSize); } /* if (target == GL_TEXTURE_CUBE_MAP) { List<ByteBuffer> data = img.getData(); if (data.size() != 6) { logger.log(Level.WARNING, "Invalid texture: {0}\n" + "Cubemap textures must contain 6 data units.", img); return; } for (int i = 0; i < 6; i++) { TextureUtil.uploadTexture(img, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc); } } else if (target == EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT) { List<ByteBuffer> data = img.getData(); // -1 index specifies prepare data for 2D Array TextureUtil.uploadTexture(img, target, -1, 0, tdc); for (int i = 0; i < data.size(); i++) { // upload each slice of 2D array in turn // this time with the appropriate index TextureUtil.uploadTexture(img, target, i, 0, tdc); } } else {*/ TextureUtil.uploadTexture(img, target, 0, 0); // } img.clearUpdateNeeded(); }