com.daxie.joglf.gl.drawer.DynamicSpheresDrawer Maven / Gradle / Ivy
package com.daxie.joglf.gl.drawer;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.daxie.basis.coloru8.ColorU8;
import com.daxie.basis.vector.Vector;
import com.daxie.basis.vector.VectorFunctions;
import com.daxie.joglf.gl.shader.GLShaderFunctions;
import com.daxie.joglf.gl.shape.Sphere;
import com.daxie.joglf.gl.wrapper.GLWrapper;
import com.daxie.log.LogFile;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL4;
/**
* Draws spheres.
* @author Daba
*
*/
public class DynamicSpheresDrawer extends Dynamic3DDrawer{
private Map spheres_map;
private Map indices_sizes_map;
private int buffer_num;
private IntBuffer indices_vbo;
private IntBuffer pos_vbo;
private IntBuffer dif_vbo;
private IntBuffer vao;
public DynamicSpheresDrawer() {
spheres_map=new TreeMap<>();
indices_sizes_map=new HashMap<>();
buffer_num=0;
}
@Override
public void SetDefaultProgram() {
this.RemoveAllShaders();
this.AddProgram("color");
}
@Override
public void UpdateBuffers() {
int sphere_num=spheres_map.size();
if(buffer_num!=0)this.DeleteBuffers();
indices_vbo=Buffers.newDirectIntBuffer(sphere_num);
pos_vbo=Buffers.newDirectIntBuffer(sphere_num);
dif_vbo=Buffers.newDirectIntBuffer(sphere_num);
vao=Buffers.newDirectIntBuffer(sphere_num);
GLWrapper.glGenBuffers(sphere_num, indices_vbo);
GLWrapper.glGenBuffers(sphere_num, pos_vbo);
GLWrapper.glGenBuffers(sphere_num, dif_vbo);
GLWrapper.glGenVertexArrays(sphere_num, vao);
buffer_num=sphere_num;
int buffer_count=0;
for(Sphere sphere:spheres_map.values()) {
Vector center=sphere.GetCenter();
float radius=sphere.GetRadius();
int slice_num=sphere.GetSliceNum();
int stack_num=sphere.GetStackNum();
ColorU8 color=sphere.GetColor();
List vertices=new ArrayList<>();
List indices=new ArrayList<>();
int vertex_num=slice_num*(stack_num-1)+2;
//North pole
vertices.add(VectorFunctions.VGet(0.0f, 1.0f, 0.0f));
//Middle
for(int i=1;i program_names=this.GetProgramNames();
for(String program_name:program_names) {
GLShaderFunctions.UseProgram(program_name);
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy