mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
recalculate mipmaps in Texture.setNative()
This commit is contained in:
@@ -376,7 +376,7 @@ class PFontTexture implements PConstants {
|
||||
|
||||
|
||||
void updateTex() {
|
||||
textures[texIndex].setNative(pixels, 0, crop[0] - 1, crop[1] + crop[3] - 1, crop[2] + 2, -crop[3] + 2);
|
||||
textures[texIndex].setNative(pixels, crop[0] - 1, crop[1] + crop[3] - 1, crop[2] + 2, -crop[3] + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5577,7 +5577,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
params.sampling = textureSampling;
|
||||
if (params.sampling == Texture.TRILINEAR && !params.mipmaps) {
|
||||
params.sampling = Texture.BILINEAR;
|
||||
PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. I will use BILINEAR instead.");
|
||||
}
|
||||
params.wrapU = textureWrap;
|
||||
params.wrapV = textureWrap;
|
||||
@@ -6312,7 +6311,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0;
|
||||
setUniformMatrix(texcoordMatrixLoc, tcmat);
|
||||
}
|
||||
|
||||
|
||||
setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
|
||||
}
|
||||
|
||||
|
||||
@@ -381,42 +381,64 @@ public class Texture implements PConstants {
|
||||
|
||||
updateTexels(x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// Native set methods
|
||||
|
||||
|
||||
public void setNative(int[] pix, int x, int y, int w, int h) {
|
||||
setNative(pix, 0, x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
public void setNative(int[] pix, int level, int x, int y, int w, int h) {
|
||||
setNative(IntBuffer.wrap(pix), level, x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
public void setNative(IntBuffer buffer, int x, int y, int w, int h) {
|
||||
setNative(buffer, 0, x, y, w, h);
|
||||
}
|
||||
public void setNative(int[] pixels) {
|
||||
setNative(pixels, 0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
public void setNative(IntBuffer buffer, int level, int x, int y, int w, int h) {
|
||||
public void setNative(int[] pixels, int x, int y, int w, int h) {
|
||||
setNative(IntBuffer.wrap(pixels), x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
public void setNative(IntBuffer pixels, int x, int y, int w, int h) {
|
||||
if (pixels == null) {
|
||||
pixels = null;
|
||||
PGraphics.showWarning("The pixel buffer is null.");
|
||||
return;
|
||||
}
|
||||
if (pixels.capacity() != w * h) {
|
||||
PGraphics.showWarning("The pixels array has a length of " + pixels.capacity() + ", but it should be " + w * h);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pixels.capacity() == 0) {
|
||||
// Nothing to do (means that w == h == 0) but not an erroneous situation
|
||||
return;
|
||||
}
|
||||
|
||||
boolean enabledTex = false;
|
||||
if (!pgl.texturingIsEnabled(glTarget)) {
|
||||
pgl.enableTexturing(glTarget);
|
||||
enabledTex = true;
|
||||
}
|
||||
pgl.glBindTexture(glTarget, glName);
|
||||
pgl.glTexSubImage2D(glTarget, level, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
if (usingMipmaps) {
|
||||
if (PGraphicsOpenGL.autoMipmapGenSupported) {
|
||||
pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels);
|
||||
pgl.glGenerateMipmap(glTarget);
|
||||
} else {
|
||||
pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels);
|
||||
}
|
||||
} else {
|
||||
pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels);
|
||||
}
|
||||
|
||||
pgl.glBindTexture(glTarget, 0);
|
||||
if (enabledTex) {
|
||||
pgl.disableTexturing(glTarget);
|
||||
}
|
||||
|
||||
updateTexels(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user