update setTransform function in JOGL renders

This commit is contained in:
wyq 2022-06-17 14:15:50 +08:00
parent 56237c6d17
commit f686e30fd6
5 changed files with 86 additions and 67 deletions

View File

@ -196,6 +196,9 @@ public class Transform {
* @return Cloned transform
*/
public Object clone() {
return new Transform(xmin, xmax, ymin, ymax, zmin, zmax);
Transform transform = new Transform(xmin, xmax, ymin, ymax, zmin, zmax);
transform.aspectType = this.aspectType;
return transform;
}
}

View File

@ -62,23 +62,29 @@ public class MeshRender extends JOGLGraphicRender {
@Override
public void setTransform(Transform transform) {
super.setTransform(transform);
boolean updateBuffer = true;
if (this.transform != null && this.transform.equals(transform))
updateBuffer = false;
vertexPosition = meshGraphic.getVertexData(this.transform);
FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexPosition);
meshGraphic.calculateNormalVectors(vertexPosition);
FloatBuffer normalBuffer = GLBuffers.newDirectFloatBuffer(meshGraphic.getVertexNormal());
int sizePosition = vertexBuffer.capacity() * Float.BYTES;
int sizeNormal = normalBuffer.capacity() * Float.BYTES;
super.setTransform((Transform) transform.clone());
gl.glGenBuffers(1, vbo);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo.get(0));
gl.glBufferData(GL.GL_ARRAY_BUFFER, sizePosition + sizeNormal,
ByteBuffer.allocateDirect(sizePosition + sizeNormal).asFloatBuffer(), GL.GL_STATIC_DRAW);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, vertexBuffer.capacity() * Float.BYTES, vertexBuffer);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, vertexBuffer.capacity() * Float.BYTES,
normalBuffer.capacity() * Float.BYTES, normalBuffer);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
if (updateBuffer) {
vertexPosition = meshGraphic.getVertexData(this.transform);
FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexPosition);
meshGraphic.calculateNormalVectors(vertexPosition);
FloatBuffer normalBuffer = GLBuffers.newDirectFloatBuffer(meshGraphic.getVertexNormal());
int sizePosition = vertexBuffer.capacity() * Float.BYTES;
int sizeNormal = normalBuffer.capacity() * Float.BYTES;
gl.glGenBuffers(1, vbo);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo.get(0));
gl.glBufferData(GL.GL_ARRAY_BUFFER, sizePosition + sizeNormal,
ByteBuffer.allocateDirect(sizePosition + sizeNormal).asFloatBuffer(), GL.GL_STATIC_DRAW);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, vertexBuffer.capacity() * Float.BYTES, vertexBuffer);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, vertexBuffer.capacity() * Float.BYTES,
normalBuffer.capacity() * Float.BYTES, normalBuffer);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
}
}
void compileShaders() throws Exception {

View File

@ -77,38 +77,44 @@ public class SurfaceRender extends JOGLGraphicRender {
@Override
public void setTransform(Transform transform) {
super.setTransform(transform);
boolean updateBuffer = true;
if (this.transform != null && this.transform.equals(transform))
updateBuffer = false;
float[] vertexData = surfaceGraphic.getVertexPosition(this.transform);
FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
surfaceGraphic.calculateNormalVectors(vertexData);
FloatBuffer normalBuffer = GLBuffers.newDirectFloatBuffer(surfaceGraphic.getVertexNormal());
sizePosition = vertexBuffer.capacity() * Float.BYTES;
sizeNormal = normalBuffer.capacity() * Float.BYTES;
int totalSize = sizePosition + sizeNormal;
super.setTransform((Transform) transform.clone());
FloatBuffer ctBuffer;
if (surfaceGraphic.isUsingTexture()) {
ctBuffer = GLBuffers.newDirectFloatBuffer(surfaceGraphic.getVertexTexture());
} else {
ctBuffer = GLBuffers.newDirectFloatBuffer(surfaceGraphic.getVertexColor());
if (updateBuffer) {
float[] vertexData = surfaceGraphic.getVertexPosition(this.transform);
FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
surfaceGraphic.calculateNormalVectors(vertexData);
FloatBuffer normalBuffer = GLBuffers.newDirectFloatBuffer(surfaceGraphic.getVertexNormal());
sizePosition = vertexBuffer.capacity() * Float.BYTES;
sizeNormal = normalBuffer.capacity() * Float.BYTES;
int totalSize = sizePosition + sizeNormal;
FloatBuffer ctBuffer;
if (surfaceGraphic.isUsingTexture()) {
ctBuffer = GLBuffers.newDirectFloatBuffer(surfaceGraphic.getVertexTexture());
} else {
ctBuffer = GLBuffers.newDirectFloatBuffer(surfaceGraphic.getVertexColor());
}
sizeColorTexture = ctBuffer.capacity() * Float.BYTES;
totalSize += sizeColorTexture;
gl.glGenBuffers(2, vbo);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo.get(0));
gl.glBufferData(GL.GL_ARRAY_BUFFER, totalSize,
ByteBuffer.allocateDirect(totalSize).asFloatBuffer(), GL.GL_STATIC_DRAW);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, sizePosition, vertexBuffer);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, sizePosition, sizeNormal, normalBuffer);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, sizePosition + sizeNormal, sizeColorTexture, ctBuffer);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
IntBuffer indexBuffer = GLBuffers.newDirectIntBuffer(surfaceGraphic.getVertexIndices());
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vbo.get(1));
gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.capacity() * Integer.BYTES, indexBuffer, GL.GL_STATIC_DRAW);
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
}
sizeColorTexture = ctBuffer.capacity() * Float.BYTES;
totalSize += sizeColorTexture;
gl.glGenBuffers(2, vbo);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo.get(0));
gl.glBufferData(GL.GL_ARRAY_BUFFER, totalSize,
ByteBuffer.allocateDirect(totalSize).asFloatBuffer(), GL.GL_STATIC_DRAW);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, sizePosition, vertexBuffer);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, sizePosition, sizeNormal, normalBuffer);
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, sizePosition + sizeNormal, sizeColorTexture, ctBuffer);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
IntBuffer indexBuffer = GLBuffers.newDirectIntBuffer(surfaceGraphic.getVertexIndices());
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vbo.get(1));
gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.capacity() * Integer.BYTES, indexBuffer, GL.GL_STATIC_DRAW);
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
}
void bindingTextures() {

View File

@ -107,15 +107,21 @@ public class VolumeRender extends JOGLGraphicRender {
@Override
public void setTransform(Transform transform) {
super.setTransform(transform);
boolean updateBuffer = true;
if (this.transform != null && this.transform.equals(transform))
updateBuffer = false;
float[] vertexBufferData = volume.getVertexBufferData(this.transform);
super.setTransform((Transform) transform.clone());
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);
if (updateBuffer) {
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() {

View File

@ -1,36 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\contour">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\taylor"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
<RecentFolder Folder="D:\Temp\test"/>
<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\gui"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\wrf"/>
<RecentFolder Folder="D:\Temp\test\radar"/>
<RecentFolder Folder="D:\Temp\test"/>
<RecentFolder Folder="D:\Temp\test\demo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
</Path>
<File>
<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\volume\volumeplot_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot\plot_JFrame.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_3.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_7.py"/>
</OpenedFiles>
<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\volume\volumeplot_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot\plot_JFrame.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_3.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_7.py"/>
</RecentFiles>
</File>
<Font>
@ -38,5 +36,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,-7" MainFormSize="1293,685"/>
<Startup MainFormLocation="-7,0" MainFormSize="1403,819"/>
</MeteoInfo>