Skip to content

Commit

Permalink
Fixed cubmap texture init
Browse files Browse the repository at this point in the history
  • Loading branch information
thothbot committed Feb 14, 2016
1 parent ca1b940 commit 973cfc8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2916,8 +2916,7 @@ public void setTexture( Texture texture, int slot )
boolean isImagePowerOfTwo = Mathematics.isPowerOfTwo( image.getWidth() )
&& Mathematics.isPowerOfTwo( image.getHeight() );

texture.setTextureParameters( this.gl, getMaxAnisotropy(),
TextureTarget.TEXTURE_2D.getValue(), isImagePowerOfTwo );
texture.setTextureParameters( this.gl, getMaxAnisotropy(), TextureTarget.TEXTURE_2D, isImagePowerOfTwo );

if ( texture instanceof CompressedTexture )
{
Expand Down Expand Up @@ -3022,9 +3021,10 @@ private void setCubeTexture ( CubeTexture texture, int slot )
{
if ( this.autoScaleCubemaps )
{
TextureData clamped = clampToMaxSize(texture.getImage(i),
this._maxCubemapSize);
cubeImage.add(clamped);
Log.warn("Need to fix autoscale of cubemaps");
// TextureData clamped = clampToMaxSize(texture.getImage(i),
// this._maxCubemapSize);
cubeImage.add(texture.getImage(i));

}
else
Expand All @@ -3037,7 +3037,7 @@ private void setCubeTexture ( CubeTexture texture, int slot )
boolean isImagePowerOfTwo = Mathematics.isPowerOfTwo( image.getWidth() )
&& Mathematics.isPowerOfTwo( image.getHeight() );

texture.setTextureParameters( this.gl, getMaxAnisotropy(), TextureTarget.TEXTURE_CUBE_MAP.getValue(),
texture.setTextureParameters( this.gl, getMaxAnisotropy(), TextureTarget.TEXTURE_CUBE_MAP,
true /*power of two*/ );

for ( int i = 0; i < 6; i ++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void setRenderTarget(GL20 gl)

gl.glBindTexture(TextureTarget.TEXTURE_CUBE_MAP.getValue(), this.getWebGlTexture() );

setTextureParameters( gl, TextureTarget.TEXTURE_CUBE_MAP.getValue(), isTargetPowerOfTwo );
setTextureParameters( gl, TextureTarget.TEXTURE_CUBE_MAP, isTargetPowerOfTwo );

for ( int i = 0; i < 6; i ++ )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void setRenderTarget(GL20 gl)
}

gl.glBindTexture(TextureTarget.TEXTURE_2D.getValue(), this.getWebGlTexture());
setTextureParameters(gl, TextureTarget.TEXTURE_2D.getValue(), isTargetPowerOfTwo);
setTextureParameters(gl, TextureTarget.TEXTURE_2D, isTargetPowerOfTwo);

gl.glTexImage2D(TextureTarget.TEXTURE_2D.getValue(), 0, getFormat().getValue(), this.width, this.height, 0, getFormat().getValue(), getType().getValue(), null);

Expand Down
28 changes: 16 additions & 12 deletions parallax/src/org/parallax3d/parallax/graphics/textures/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.parallax3d.parallax.graphics.textures;

import org.parallax3d.parallax.Log;
import org.parallax3d.parallax.Parallax;
import org.parallax3d.parallax.files.FileHandle;
import org.parallax3d.parallax.system.ThreejsObject;
Expand Down Expand Up @@ -102,7 +103,9 @@ public enum MAPPING_MODE

private int cache_oldAnisotropy;

protected Texture(){}
protected Texture(){
this((TextureData)null);
}

public Texture (String internalPath) {
this( Parallax.asset(internalPath), null );
Expand Down Expand Up @@ -453,36 +456,37 @@ public Texture setWebGlTexture(int webglTexture) {
return this;
}

public Texture setTextureParameters ( GL20 gl, Integer /*TextureTarget*/ textureType, boolean isImagePowerOfTwo )
public Texture setTextureParameters ( GL20 gl, TextureTarget textureType, boolean isImagePowerOfTwo )
{
return setTextureParameters( gl, 0, textureType, isImagePowerOfTwo);
}

public Texture setTextureParameters ( GL20 gl, int maxAnisotropy, Integer /*TextureTarget*/ textureType, boolean isImagePowerOfTwo )
public Texture setTextureParameters ( GL20 gl, int maxAnisotropy, TextureTarget textureType, boolean isImagePowerOfTwo )
{
if ( isImagePowerOfTwo )
{
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_WRAP_S.getValue(), this.wrapS.getValue());
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_WRAP_T.getValue(), this.wrapT.getValue());
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_MAG_FILTER.getValue(), this.magFilter.getValue() );
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_MIN_FILTER.getValue(), this.minFilter.getValue());
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_WRAP_S.getValue(), this.wrapS.getValue());
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_WRAP_T.getValue(), this.wrapT.getValue());
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_MAG_FILTER.getValue(), this.magFilter.getValue() );
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_MIN_FILTER.getValue(), this.minFilter.getValue());
}
else
{
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_WRAP_S.getValue(), GL20.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_WRAP_T.getValue(), GL20.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_MAG_FILTER.getValue(), filterFallback(this.magFilter.getValue()));
gl.glTexParameteri(textureType, TextureParameterName.TEXTURE_MIN_FILTER.getValue(), filterFallback(this.minFilter.getValue()));
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_WRAP_S.getValue(), GL20.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_WRAP_T.getValue(), GL20.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_MAG_FILTER.getValue(), filterFallback(this.magFilter.getValue()));
gl.glTexParameteri(textureType.getValue(), TextureParameterName.TEXTURE_MIN_FILTER.getValue(), filterFallback(this.minFilter.getValue()));
}

if ( maxAnisotropy > 0 )
{
if ( this.anisotropy > 1 || this.cache_oldAnisotropy > 1 )
{
gl.glTexParameterf(textureType, TextureParameterName.TEXTURE_MAX_ANISOTROPY_EXT.getValue(), Math.min(this.anisotropy, maxAnisotropy));
gl.glTexParameterf(textureType.getValue(), TextureParameterName.TEXTURE_MAX_ANISOTROPY_EXT.getValue(), Math.min(this.anisotropy, maxAnisotropy));
this.cache_oldAnisotropy = this.anisotropy;
}
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,34 @@
import org.parallax3d.parallax.graphics.renderers.shaders.CubeShader;
import org.parallax3d.parallax.graphics.scenes.Scene;
import org.parallax3d.parallax.graphics.textures.CubeTexture;
import org.parallax3d.parallax.input.TouchMoveHandler;
import org.parallax3d.parallax.math.Color;
import org.parallax3d.parallax.tests.ParallaxTest;
import org.parallax3d.parallax.tests.ThreejsExample;

@ThreejsExample("webgl_materials_cubemap_balls_reflection")
public final class MaterialsCubemapBallsReflection extends ParallaxTest
public final class MaterialsCubemapBallsReflection extends ParallaxTest implements TouchMoveHandler
{

static final String textures = "textures/cube/pisa/*.png";

Scene scene;
PerspectiveCamera camera;

public int mouseX = 0;
public int mouseY = 0;

int width = 0, height = 0;
int mouseX = 0;
int mouseY = 0;

private List<Mesh> sphere;

private Scene sceneCube;
private PerspectiveCamera cameraCube;

@Override
public void onResize(RenderingContext context) {
width = context.getWidth();
height = context.getHeight();
}

@Override
public void onStart(RenderingContext context)
{
Expand Down Expand Up @@ -135,6 +142,12 @@ public void onUpdate(RenderingContext context)
context.getRenderer().render(scene, camera);
}

@Override
public void onTouchMove(int screenX, int screenY, int pointer) {
mouseX = (screenX - width / 2 ) * 10;
mouseY = (screenY - height / 2) * 10;
}

@Override
public String getName() {
return "Cube map reflection";
Expand All @@ -149,21 +162,4 @@ public String getDescription() {
public String getAuthor() {
return "<a href=\"http://threejs.org\">threejs</a>";
}

// @Override
// public void onAnimationReady(AnimationReadyEvent event)
// {
// super.onAnimationReady(event);
//
// this.renderingPanel.getCanvas().addMouseMoveHandler(new MouseMoveHandler() {
// @Override
// public void onMouseMove(MouseMoveEvent event)
// {
// DemoScene rs = (DemoScene) renderingPanel.getAnimatedScene();
//
// rs.mouseX = (event.getX() - renderingPanel.context.getRenderer().getAbsoluteWidth() / 2 ) * 10;
// rs.mouseY = (event.getY() - renderingPanel.context.getRenderer().getAbsoluteHeight() / 2) * 10;
// }
// });
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void onStart(RenderingContext context)
// materialPainting.setColor(new Color(0xffffff));
// materialPainting.setMap(texturePainting);

texturePainting2 = new Texture();
texturePainting2 = new Texture("");
materialPainting2 = new MeshBasicMaterial()
.setColor(0xffccaa)
.setMap(texturePainting2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,30 @@
import org.parallax3d.parallax.graphics.scenes.Scene;
import org.parallax3d.parallax.graphics.textures.CubeTexture;
import org.parallax3d.parallax.graphics.textures.Texture;
import org.parallax3d.parallax.input.TouchMoveHandler;
import org.parallax3d.parallax.math.Color;
import org.parallax3d.parallax.system.gl.enums.PixelFormat;
import org.parallax3d.parallax.tests.ParallaxTest;
import org.parallax3d.parallax.tests.ThreejsExample;

@ThreejsExample("webgl_performance_doublesided")
public final class PerformanceDoubleSided extends ParallaxTest
public final class PerformanceDoubleSided extends ParallaxTest implements TouchMoveHandler
{

private static final String textures = "textures/cube/swedishRoyalCastle/*.jpg";

Scene scene;
PerspectiveCamera camera;

public int mouseX;
public int mouseY;

int width = 0, height = 0;
int mouseX;
int mouseY;

@Override
public void onResize(RenderingContext context) {
width = context.getWidth();
height = context.getHeight();
}

@Override
public void onStart(RenderingContext context)
Expand Down Expand Up @@ -122,6 +130,12 @@ public void onUpdate(RenderingContext context)
context.getRenderer().render(scene, camera);
}

@Override
public void onTouchMove(int screenX, int screenY, int pointer) {
mouseX = (screenX - width / 2 ) * 10;
mouseY = (screenY - height / 2) * 10;
}

@Override
public String getName() {
return "Performance: Double sided";
Expand All @@ -137,20 +151,4 @@ public String getAuthor() {
return "<a href=\"http://threejs.org\">threejs</a>";
}

// @Override
// public void onAnimationReady(AnimationReadyEvent event)
// {
// super.onAnimationReady(event);
//
// this.renderingPanel.getCanvas().addMouseMoveHandler(new MouseMoveHandler() {
// @Override
// public void onMouseMove(MouseMoveEvent event)
// {
// DemoScene rs = (DemoScene) renderingPanel.getAnimatedScene();
// rs.mouseX = (event.getX() - renderingPanel.context.getRenderer().getAbsoluteWidth() / 2 ) * 10;
// rs.mouseY = (event.getY() - renderingPanel.context.getRenderer().getAbsoluteHeight() / 2) * 10;
// }
// });
// }

}

0 comments on commit 973cfc8

Please sign in to comment.