textureCube deprecated error

hello,

I try to use textureCube in a shader node

here is how I set the texture (inspired from generateSkyTexture - CombinedTexture.java)

actualy this code does not make much sens since it copy 6 times the same texture, but I cant find any doc about how cubemap should be organized

        Texture skybox_cubemap = assetManager.loadTexture(fileName);
        Image image = skybox_cubemap.getImage();
        ByteBuffer sourceData = image.getData(0);
        ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(6);
        for (int i = 0; i < 6; ++i) {
                data.add(BufferUtils.clone(sourceData));
        }
        TextureCubeMap texture = new TextureCubeMap(new Image(image.getFormat(), image.getWidth(), image.getHeight(), 6, data));                
        material.setTexture("RefractionMap", texture);

and the shader

    float refractiveIndex = 1.5;
    vec3 refractedDirection = refract(normalize(eyeVec), normalize(normal), 1.0 / refractiveIndex);
    outColor = texture(refractionMap, refractedDirection);//textureCube deprecated

the image I try to use : http://www.keithlantz.net/wp-content/uploads/2011/10/skybox_texture.jpg

[edit: ok I just found out http://javadoc.jmonkeyengine.org/com/jme3/texture/TextureCubeMap.html#TextureCubeMap(com.jme3.texture.Image)

0 => Positive X (+x)
1 => Negative X (-x)
2 => Positive Y (+y)
3 => Negative Y (-y)
4 => Positive Z (+z)
5 => Negative Z (-z)

now I need to copy subregions of the main image
now why does generateSkyTexture not do that… ? mistery

thanks

ok, here is how I do it (if anyone is interested or has a better solution)

 public static void SetCubeMap(Material material, String fileName) 
    {
        Texture skybox_cubemap = assetManager.loadTexture(fileName);
        
        Image image = skybox_cubemap.getImage();
        int dx=image.getWidth()/4;
        int dy=image.getHeight()/3;
        
        ByteBuffer sourceData = image.getData(0);
        int pixelSize=sourceData.capacity()/(image.getWidth()*image.getHeight());
        
        ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(6);
        for (int i = 0; i < 6; ++i)
        {
            ByteBuffer newData = BufferUtils.createByteBuffer(pixelSize*dx*dy);
            int offsetX=0,offsetY=0;
            switch(i)
            {
                case 0: offsetX=0;offsetY=1;//Positive X (+x)
                    break;
                case 1: offsetX=2;offsetY=1;//Negative X (-x)
                    break;
                case 2: offsetX=1;offsetY=0;//Positive Y (+y)
                    break;
                case 3: offsetX=1;offsetY=2;//Negative Y (-y)
                    break;
                case 4: offsetX=1;offsetY=1;//Positive Z (+z)
                    break;
                case 5: offsetX=3;offsetY=1;//Negative Z (-z)
                    break;
            }
            Tools.CopyImageSubRegion(image,offsetX*dx,offsetY*dy,newData,dx,dy);
            data.add(newData);
        }
        TextureCubeMap texture = new TextureCubeMap(new Image(image.getFormat(), dx, dy, 6, data));                
        material.setTexture("RefractionMap", texture);
    }
public static void CopyImageSubRegion(Image image,int offsetX,int offsetY, ByteBuffer dstImageData,int dstImageWidth,int dstImageHeight) 
    {
        ByteBuffer srcImageData=image.getData(0);
        
        if(image.getFormat()==Image.Format.ABGR8)
        {
            for(int y=0;y<dstImageHeight;y++)
                for(int x=0;x<dstImageWidth;x++)
                {
                    int src=(((y+offsetY)*image.getWidth())+(x+offsetX))*4;
                    int dst=((y*dstImageWidth)+x)*4;
                    byte a=srcImageData.get(src+0);
                    byte b=srcImageData.get(src+1);
                    byte g=srcImageData.get(src+2);
                    byte r=srcImageData.get(src+3);
                    dstImageData.put(dst+0,a);
                    dstImageData.put(dst+1,b);
                    dstImageData.put(dst+2,g);
                    dstImageData.put(dst+3,r);
                }
        }
        else if(image.getFormat()==Image.Format.BGR8)
        {
            for(int y=0;y<dstImageHeight;y++)
                for(int x=0;x<dstImageWidth;x++)
                {
                    int src=(((y+offsetY)*image.getWidth())+(x+offsetX))*3;
                    int dst=((y*dstImageWidth)+x)*3;
                    byte b=srcImageData.get(src+0);
                    byte g=srcImageData.get(src+1);
                    byte r=srcImageData.get(src+2);
                    dstImageData.put(dst+0,b);
                    dstImageData.put(dst+1,g);
                    dstImageData.put(dst+2,r);
                }
        }
        else
            System.out.println("Error, CopyImageSubRegion : Unsuported format for copy");
    }

The sky shader doesn’t do that because it’s specified as a glsl 1.0 shader (and texture cube is not deprecated). So the version is enforced to it.
ShaderNodes works differently, the generator will always generate the max supported shader version your hardware can support.

So for example, if your hardware supports glsl 1.5 the version injected in your shader will be 1.5. And if you use the textureCube function you’ll have this error. In that case you have to use the texture function as you did.

Here are your options
1.There is a way to specify a node code for whatever version you want in the shadernode definition :
When you specify the shader source, you can specify the glsl version , you just have to specify a shader with 100 and use textureCube in the shader node source, then have another shader define with 130 and use your current shader code.
2. you can check for the version in a preprocessor directive and use only one shader.

#if __VERSION__ >= 130
//use texture()
#else
//use textureCube()
#endif

ok, but I meant the sky thingy does not copy subregions of the texture but copy 6 times the same texture

 for (int i = 0; i < 6; ++i) {
                data.add(BufferUtils.clone(sourceData));
        }

ok…my bad I didn’t read thoroughly your post and just relied on the title.
IMO that’s a bug in the first code you posted. Or it’s not meant to do what you think it does…

A cube map is composed of 6 buffers. I’m surprised what you do here actually works. However the order you figured is the right one.

I create 6 buffers and copy subregions of my texture to each of these

oh ok ! Makes sense then :wink: