Skip to content

Commit

Permalink
add PowerPreference option
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Jul 21, 2024
1 parent 394e9d8 commit 66c9690
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class TeaApplicationConfiguration {
* return value of {@link TeaApplication#isMobileDevice()} . */
public boolean usePhysicalPixels = true;

/**
* default, low-power or high-performance
*/
public String powerPreference = "high-performance";

public boolean isFixedSizeApplication() {
return width != 0 && height != 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.github.xpenatan.gdx.backends.teavm.dom.StyleWrapper;
import com.github.xpenatan.gdx.backends.teavm.dom.impl.TeaWindow;
import com.github.xpenatan.gdx.backends.teavm.gl.WebGL2RenderingContextWrapper;
import com.github.xpenatan.gdx.backends.teavm.gl.WebGLContextAttributesWrapper;
import com.github.xpenatan.gdx.backends.teavm.gl.WebGLRenderingContextWrapper;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSFunctor;
Expand Down Expand Up @@ -50,12 +51,13 @@ public TeaGraphics(TeaApplicationConfiguration config) {
HTMLElementWrapper elementID = document.getElementById(config.canvasID);
this.canvas = (HTMLCanvasElementWrapper)elementID;

WebGLContextAttributes attr = WebGLContextAttributes.create();
WebGLContextAttributesWrapper attr = WebGLContextAttributesWrapper.create();
attr.setAlpha(config.alpha);
attr.setAntialias(config.antialiasing);
attr.setStencil(config.stencil);
attr.setPremultipliedAlpha(config.premultipliedAlpha);
attr.setPreserveDrawingBuffer(config.preserveDrawingBuffer);
attr.setPowerPreference(config.powerPreference);
HTMLCanvasElement canvas1 = (HTMLCanvasElement)canvas;

if (config.useGL30) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
package com.github.xpenatan.gdx.backends.teavm.gl;

import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;

/**
* @author xpenatan
*/
public interface WebGLContextAttributesWrapper extends JSObject {
// WebGLContextAttributes
boolean getAlpha();
public abstract class WebGLContextAttributesWrapper implements JSObject {
@JSProperty
public abstract boolean isAlpha();

void setAlpha(boolean alpha);
@JSProperty
public abstract void setAlpha(boolean alpha);

boolean getDepth();
@JSProperty
public abstract boolean isDepth();

void setDepth(boolean depth);
@JSProperty
public abstract void setDepth(boolean depth);

boolean getStencil();
@JSProperty
public abstract boolean isScencil();

void setStencil(boolean stencil);
@JSProperty
public abstract void setStencil(boolean stencil);

boolean getAntialias();
@JSProperty
public abstract boolean isAntialias();

void setAntialias(boolean antialias);
@JSProperty
public abstract void setAntialias(boolean antialias);

boolean getPremultipliedAlpha();
@JSProperty
public abstract boolean isPremultipliedAlpha();

void setPremultipliedAlpha(boolean premultipliedAlpha);
@JSProperty
public abstract void setPremultipliedAlpha(boolean premultipliedAlpha);

boolean getPreserveDrawingBuffer();
@JSProperty
public abstract boolean isPreserveDrawingBuffer();

void setPreserveDrawingBuffer(boolean preserveDrawingBuffer);
@JSProperty
public abstract void setPreserveDrawingBuffer(boolean preserveDrawingBuffer);

@JSProperty
public abstract void setPowerPreference(String powerPreference);

@JSBody(script = "return {};")
public static native WebGLContextAttributesWrapper create();
}

0 comments on commit 66c9690

Please sign in to comment.