bugfix VolumeRender

This commit is contained in:
wyq 2022-06-10 15:05:57 +08:00
parent bcf93c34d2
commit 20e9848b27
4 changed files with 42 additions and 20 deletions

View File

@ -495,6 +495,14 @@ public class VolumeGraphic extends GraphicCollection3D {
}; };
} }
/**
* Get vertex number
* @return Vertex number
*/
public int getVertexNumber() {
return this.vertexBufferData.length / 3;
}
/** /**
* Calculate normals * Calculate normals
*/ */

View File

@ -2393,14 +2393,10 @@ public class Plot3DGL extends Plot implements GLEventListener {
try { try {
if (this.clipPlane) if (this.clipPlane)
this.disableClipPlane(gl); this.disableClipPlane(gl);
VolumeRender volumeRender = null;
if (!this.renderMap.containsKey(graphic)) { if (!this.renderMap.containsKey(graphic)) {
volumeRender = new VolumeRender(gl, (VolumeGraphic) graphic); renderMap.put(graphic, new VolumeRender(gl, (VolumeGraphic) graphic));
renderMap.put(graphic, volumeRender);
} else {
volumeRender = (VolumeRender) renderMap.get(graphic);
volumeRender.updateShaders();
} }
VolumeRender volumeRender = (VolumeRender) renderMap.get(graphic);
volumeRender.setTransform(this.transform); volumeRender.setTransform(this.transform);
volumeRender.setOrthographic(this.orthographic); volumeRender.setOrthographic(this.orthographic);
volumeRender.updateMatrix(); volumeRender.updateMatrix();

View File

@ -1,7 +1,9 @@
package org.meteoinfo.chart.render.jogl; package org.meteoinfo.chart.render.jogl;
import com.jogamp.common.nio.Buffers; import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2; import com.jogamp.opengl.GL2;
import com.jogamp.opengl.util.GLBuffers;
import org.meteoinfo.chart.graphic.VolumeGraphic; import org.meteoinfo.chart.graphic.VolumeGraphic;
import org.meteoinfo.chart.jogl.Program; import org.meteoinfo.chart.jogl.Program;
import org.meteoinfo.chart.jogl.Transform; import org.meteoinfo.chart.jogl.Transform;
@ -25,6 +27,7 @@ public class VolumeRender extends JOGLGraphicRender {
private int volumeTexture; private int volumeTexture;
private int normalsTexture; private int normalsTexture;
private Program program; private Program program;
private IntBuffer vbo;
/** /**
* Constructor * Constructor
@ -34,6 +37,7 @@ public class VolumeRender extends JOGLGraphicRender {
super(gl); super(gl);
useShader = true; useShader = true;
initVertexBuffer();
} }
/** /**
@ -56,7 +60,7 @@ public class VolumeRender extends JOGLGraphicRender {
public VolumeRender(GL2 gl, VolumeGraphic graphic, Transform transform) { public VolumeRender(GL2 gl, VolumeGraphic graphic, Transform transform) {
this(gl, graphic); this(gl, graphic);
this.transform = transform; this.setTransform(transform);
} }
/** /**
@ -97,6 +101,23 @@ public class VolumeRender extends JOGLGraphicRender {
return this.volume == null ? 1.0f : this.volume.getBrightness(); return this.volume == null ? 1.0f : this.volume.getBrightness();
} }
private void initVertexBuffer() {
vbo = GLBuffers.newDirectIntBuffer(2);
}
@Override
public void setTransform(Transform transform) {
super.setTransform(transform);
float[] vertexBufferData = volume.getVertexBufferData(this.transform);
gl.glGenBuffers(1, vbo);
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo.get(0));
gl.glBufferData(GL_ARRAY_BUFFER, vertexBufferData.length * Float.BYTES,
Buffers.newDirectFloatBuffer(vertexBufferData), GL_STATIC_DRAW);
gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void bindingTextures() { void bindingTextures() {
//ColorMap 2D texture //ColorMap 2D texture
this.colorTexture = getTextureID(); this.colorTexture = getTextureID();
@ -263,12 +284,8 @@ public class VolumeRender extends JOGLGraphicRender {
program.use(gl); program.use(gl);
setUniforms(); setUniforms();
IntBuffer intBuffer = IntBuffer.allocate(1); gl.glBindBuffer(GL_ARRAY_BUFFER, vbo.get(0));
gl.glGenBuffers(1, intBuffer);
int vertexBuffer = intBuffer.get(0);
gl.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
float[] vertexBufferData = volume.getVertexBufferData(this.transform);
gl.glBufferData(GL_ARRAY_BUFFER, vertexBufferData.length * Float.BYTES, Buffers.newDirectFloatBuffer(vertexBufferData), GL_STATIC_DRAW);
// 1st attribute buffer : vertices // 1st attribute buffer : vertices
gl.glEnableVertexAttribArray(0); gl.glEnableVertexAttribArray(0);
//gl.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); //gl.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
@ -293,9 +310,10 @@ public class VolumeRender extends JOGLGraphicRender {
gl.glDisable(GL_DEPTH_TEST); gl.glDisable(GL_DEPTH_TEST);
gl.glDrawArrays(GL_TRIANGLES, 0, vertexBufferData.length / 3); // Starting from vertex 0; 3 vertices total -> 1 triangle gl.glDrawArrays(GL_TRIANGLES, 0, volume.getVertexNumber()); // Starting from vertex 0; 3 vertices total -> 1 triangle
gl.glDisableVertexAttribArray(0); gl.glDisableVertexAttribArray(0);
gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
gl.glActiveTexture(GL_TEXTURE0); gl.glActiveTexture(GL_TEXTURE0);
gl.glBindTexture(GL_TEXTURE_2D, 0); gl.glBindTexture(GL_TEXTURE_2D, 0);

View File

@ -1,34 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile"> <MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"> <Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\calipso"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\calipso"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
</Path> </Path>
<File> <File>
<OpenedFiles> <OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\volumeplot_2.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\volumeplot_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_elev_2.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\volumeplot_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\plot_cuace_3d_volume.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\plot_cuace_3d_volume_specular.py"/>
</OpenedFiles> </OpenedFiles>
<RecentFiles> <RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\volumeplot_2.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\volumeplot_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_elev_2.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\volumeplot_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\plot_cuace_3d_volume.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\plot_cuace_3d_volume_specular.py"/>
</RecentFiles> </RecentFiles>
</File> </File>
<Font> <Font>