com.daxie.joglf.gl.drawer.Dynamic2DFilledCirclesDrawer Maven / Gradle / Ivy
package com.daxie.joglf.gl.drawer;
import java.awt.Point;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
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.joglf.gl.shader.GLShaderFunctions;
import com.daxie.joglf.gl.shape.Circle2D;
import com.daxie.joglf.gl.tool.CoordinateFunctions;
import com.daxie.joglf.gl.wrapper.GLWrapper;
import com.daxie.log.LogFile;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL4;
/**
* Draws 2D filled circles.
* @author Daba
*
*/
public class Dynamic2DFilledCirclesDrawer extends Dynamic2DDrawer{
private Map circles_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 Dynamic2DFilledCirclesDrawer() {
circles_map=new TreeMap<>();
indices_sizes_map=new HashMap<>();
buffer_num=0;
}
@Override
public void SetDefaultProgram() {
this.RemoveAllShaders();
this.AddProgram("line_drawer");
}
@Override
public void UpdateBuffers() {
int circle_num=circles_map.size();
if(buffer_num!=0)this.DeleteBuffers();
indices_vbo=Buffers.newDirectIntBuffer(circle_num);
pos_vbo=Buffers.newDirectIntBuffer(circle_num);
dif_vbo=Buffers.newDirectIntBuffer(circle_num);
vao=Buffers.newDirectIntBuffer(circle_num);
GLWrapper.glGenBuffers(circle_num, indices_vbo);
GLWrapper.glGenBuffers(circle_num, pos_vbo);
GLWrapper.glGenBuffers(circle_num, dif_vbo);
GLWrapper.glGenVertexArrays(circle_num, vao);
buffer_num=circle_num;
int window_width=this.GetWindowWidth();
int window_height=this.GetWindowHeight();
int count=0;
for(Circle2D circle:circles_map.values()) {
Point center=circle.GetCenter();
int radius=circle.GetRadius();
ColorU8 color=circle.GetColor();
int div_num=circle.GetDivNum();
FloatBuffer pos_buffer=Buffers.newDirectFloatBuffer(2*(div_num+1));
FloatBuffer dif_buffer=Buffers.newDirectFloatBuffer(4*(div_num+1));
int center_x=center.x;
int center_y=center.y;
float normalized_center_x=CoordinateFunctions.NormalizeCoordinate(center_x, window_width);
float normalized_center_y=CoordinateFunctions.NormalizeCoordinate(center_y, window_height);
pos_buffer.put(normalized_center_x);
pos_buffer.put(normalized_center_y);
for(int i=0;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