Skip to content

Commit

Permalink
Add toggleable fb mipmaps generation
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl authored and stephengold committed Apr 18, 2022
1 parent 5656fe4 commit 8ab3d24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public final class GLRenderer implements Renderer {
private int defaultAnisotropicFilter = 1;
private boolean linearizeSrgbImages;
private HashSet<String> extensions;
private boolean generateMipmapsForFramebuffers = true;

private final GL gl;
private final GL2 gl2;
Expand All @@ -118,13 +119,21 @@ public GLRenderer(GL gl, GLExt glext, GLFbo glfbo) {
this.glext = glext;
this.texUtil = new TextureUtil(gl, gl2, glext);
}

/**
* Enable/Disable default automatic generation of mipmaps for framebuffers
* @param v Default is true
*/
public void setGenerateMipmapsForFrameBuffer(boolean v) {
generateMipmapsForFramebuffers = v;
}

@Override
public Statistics getStatistics() {
return statistics;
}

@Override
@Override
public EnumSet<Caps> getCaps() {
return caps;
}
Expand Down Expand Up @@ -2075,7 +2084,7 @@ public void setFrameBuffer(FrameBuffer fb) {
}

// generate mipmaps for last FB if needed
if (context.boundFB != null) {
if (context.boundFB != null && (context.boundFB.getMipMapsGenerationHint()!=null?context.boundFB.getMipMapsGenerationHint():generateMipmapsForFramebuffers)) {
for (int i = 0; i < context.boundFB.getNumColorBuffers(); i++) {
RenderBuffer rb = context.boundFB.getColorBuffer(i);
Texture tex = rb.getTexture();
Expand Down
14 changes: 14 additions & 0 deletions jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class FrameBuffer extends NativeObject {
private RenderBuffer depthBuf = null;
private int colorBufIndex = 0;
private boolean srgb;
private Boolean mipsGenerationHint = null;

/**
* <code>RenderBuffer</code> represents either a texture or a
Expand Down Expand Up @@ -842,4 +843,17 @@ public void setSrgb(boolean srgb) {
public boolean isSrgb() {
return srgb;
}


/**
* Hints the renderer to generate mipmaps for this framebuffer if necessary
* @param v true to enable, null to use the default value for the renderer (default to null)
*/
public void setMipMapsGenerationHint(Boolean v) {

This comment has been minimized.

Copy link
@capdevon

capdevon Apr 18, 2022

Contributor

Hi Guys, just a little tip. To facilitate the reading and maintenance of the code, we could rename the getter / setter methods according to the variable name? get/set MipMapsGenerationHint -> get/set MipsGenerationHint ? Or rename the variable name mipsGenerationHint -> mipMapsGenerationHint?

This comment has been minimized.

Copy link
@stephengold

stephengold Apr 18, 2022

Member

That suggestion makes sense. At this point, renaming the field would be easier. I'll do it.

If you're interested in reviewing code, we have 22 open PRs for you to look at...

This comment has been minimized.

Copy link
@stephengold

stephengold Apr 18, 2022

Member

The field has now been renamed in the "master" branch (at f8251c3). Not worth backporting to "v3.5" in my opinion.

mipsGenerationHint = v;
}

public Boolean getMipMapsGenerationHint() {
return mipsGenerationHint;
}
}

0 comments on commit 8ab3d24

Please sign in to comment.