Skip to content

Commit

Permalink
Code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
thothbot committed Jul 27, 2012
1 parent 39b01c6 commit 0fcd3e3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/thothbot/parallax/core/client/AnimatedScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected void onResize()
if(getCamera() != null && getCamera().getClass() == PerspectiveCamera.class )
{
((PerspectiveCamera)getCamera()).setAspectRatio(
getRenderer().getCanvas().getAspectRation());
getRenderer().getCanvas().getAspectRation());
}
}
}
5 changes: 0 additions & 5 deletions src/thothbot/parallax/core/client/RenderingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ public RenderingPanel()
this.ensureDebugId("renderingPanel");
this.getElement().getStyle().setPosition(Position.RELATIVE);
this.canvas3dAttributes = new Canvas3dAttributes();
// this.canvas3dAttributes.setAlphaEnable(true);
// this.canvas3dAttributes.setDepthEnable(true);
this.canvas3dAttributes.setStencilEnable(true);
// this.canvas3dAttributes.setAntialiasEnable(true);
// this.canvas3dAttributes.setPremultipliedAlphaEnable(true);
// this.canvas3dAttributes.setPreserveDrawingBufferEnable(false);

updateBackground();

Expand Down
20 changes: 8 additions & 12 deletions src/thothbot/parallax/core/client/renderers/WebGLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,8 @@ public void initWebGLObjects(Scene scene )
}

Log.debug("initWebGLObjects() objectsAdded=" + scene.getObjectsAdded().size()
+ ", objectsRemoved=" + scene.getObjectsRemoved().size());
+ ", objectsRemoved=" + scene.getObjectsRemoved().size()
+ ", update=" + scene.__webglObjects.size());

while ( scene.getObjectsAdded().size() > 0 )
{
Expand Down Expand Up @@ -1824,13 +1825,12 @@ private void initMaterial ( Material material, List<Light> lights, Fog fog, Geom

if ( material instanceof HasSkinning && ((HasSkinning)material).isSkinning() &&
attributes.get("skinVertexA") >=0 && attributes.get("skinVertexB") >= 0 &&
attributes.get("skinIndex") >= 0 && attributes.get("skinWeight") >= 0 ) {

attributes.get("skinIndex") >= 0 && attributes.get("skinWeight") >= 0
) {
getGL().enableVertexAttribArray( attributes.get("skinVertexA") );
getGL().enableVertexAttribArray( attributes.get("skinVertexB") );
getGL().enableVertexAttribArray( attributes.get("skinIndex") );
getGL().enableVertexAttribArray( attributes.get("skinWeight") );

}

if ( material.getAttributes() != null )
Expand Down Expand Up @@ -2812,9 +2812,6 @@ private void setTexture( Texture texture, int slot )
getGL().generateMipmap( GLenum.TEXTURE_2D.getValue() );

texture.setNeedsUpdate(false);

// if ( texture.onUpdate )
// texture.onUpdate();
}
else
{
Expand All @@ -2836,6 +2833,7 @@ private Element clampToMaxSize ( Element image, int maxSize )
{
int imgWidth = image.getOffsetWidth();
int imgHeight = image.getOffsetHeight();

if ( imgWidth <= maxSize && imgHeight <= maxSize )
return image;

Expand Down Expand Up @@ -2878,7 +2876,6 @@ private void setCubeTexture ( CubeTexture texture, int slot )

else
cubeImage.add(texture.getImage( i ));

}

Element image = cubeImage.get( 0 );
Expand All @@ -2887,17 +2884,16 @@ private void setCubeTexture ( CubeTexture texture, int slot )

texture.setTextureParameters( getGL(), GLenum.TEXTURE_CUBE_MAP.getValue(), isImagePowerOfTwo );

for ( int i = 0; i < 6; i ++ )
for ( int i = 0; i < 6; i ++ )
{
getGL().texImage2D( GLenum.TEXTURE_CUBE_MAP_POSITIVE_X.getValue() + i, 0,
texture.getFormat().getValue(), texture.getFormat().getValue(), texture.getType().getValue(), cubeImage.get( i ) );
}

if ( texture.isGenerateMipmaps() && isImagePowerOfTwo )
getGL().generateMipmap( GLenum.TEXTURE_CUBE_MAP.getValue() );

texture.setNeedsUpdate(false);

// if ( texture.onUpdate )
// texture.onUpdate();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CubeTexture(List<Element> images, Texture.MAPPING_MODE mapping)
*/
public boolean isValid()
{
return (images.size() == 6);
return (images != null && images.size() == 6);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/thothbot/parallax/core/shared/cameras/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package thothbot.parallax.core.shared.cameras;

import thothbot.parallax.core.client.gl2.arrays.Float32Array;
import thothbot.parallax.core.shared.Log;
import thothbot.parallax.core.shared.core.Matrix4f;
import thothbot.parallax.core.shared.core.Vector3f;
import thothbot.parallax.core.shared.objects.Object3D;
Expand Down
2 changes: 1 addition & 1 deletion src/thothbot/parallax/core/shared/core/Matrix4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package thothbot.parallax.core.shared.core;

import thothbot.parallax.core.client.gl2.arrays.Float32Array;
import thothbot.parallax.core.shared.Log;

/**
* This class implements three-dimensional matrix. NxN, where N=4.
Expand Down Expand Up @@ -1341,7 +1342,6 @@ public Matrix4f makeFrustum(float left, float right, float bottom, float top, fl
*/
public Matrix4f makePerspective(float fov, float aspect, float near, float far)
{

float ymax = (float) (near * Math.tan( fov * Math.PI / 360.0 ));
float ymin = - ymax;
float xmin = ymin * aspect;
Expand Down
50 changes: 38 additions & 12 deletions src/thothbot/parallax/core/shared/utils/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public static interface Callback
void run(Texture texture);
}

private static int loadedCount;
private static interface Loader
{
void onLoad();
}

public static Texture loadTexture(ImageResource imageResource)
{
return ImageUtils.loadTexture(imageResource.getSafeUri().asString());
Expand Down Expand Up @@ -102,11 +108,20 @@ public static Texture loadTexture(String url, Texture.MAPPING_MODE mapping, Call
*
* @return the new instance of {@link thothbot.parallax.core.client.textures.Texture}
*/
public static Texture loadTexture(Image image, Texture.MAPPING_MODE mapping, Callback callback)
public static Texture loadTexture(Image image, Texture.MAPPING_MODE mapping, final Callback callback)
{
Texture texture = new Texture(image.getElement(), mapping);
final Texture texture = new Texture(image.getElement(), mapping);

loadImage(image, texture, callback);
loadImage(image, texture, new Loader() {

@Override
public void onLoad() {

texture.setNeedsUpdate(true);
if (callback != null)
callback.run(texture);
}
});

return texture;
}
Expand Down Expand Up @@ -138,22 +153,34 @@ public static CubeTexture loadTextureCube(String url, Texture.MAPPING_MODE mappi

return ImageUtils.loadTextureCube(images, mapping, callback);
}
public static CubeTexture loadTextureCube(List<Image> images, Texture.MAPPING_MODE mapping, Callback callback)

public static CubeTexture loadTextureCube(List<Image> images, Texture.MAPPING_MODE mapping, final Callback callback)
{
List<Element> elements = new ArrayList<Element>();
CubeTexture texture = new CubeTexture(elements, mapping);

final CubeTexture texture = new CubeTexture(elements, mapping);

loadedCount = 0;
for(Image image: images)
{
loadImage(image, texture, callback);
loadImage(image, texture, new Loader() {

@Override
public void onLoad() {
if(++loadedCount == 6)
{
texture.setNeedsUpdate(true);
if (callback != null)
callback.run(texture);
}
}
});
elements.add(image.getElement());
}

return texture;
}

private static void loadImage(final Image image, final Texture texture, final Callback callback)
private static void loadImage(final Image image, final Texture texture, final Loader loader)
{
loadingArea.add(image);

Expand All @@ -169,12 +196,11 @@ public void onError(ErrorEvent event)
});

image.addLoadHandler(new LoadHandler() {

@Override
public void onLoad(LoadEvent event)
{
texture.setNeedsUpdate(true);
if (callback != null)
callback.run(texture);
loader.onLoad();
}
});
}
Expand Down

0 comments on commit 0fcd3e3

Please sign in to comment.