GPU framework setup.
This commit is contained in:
parent
842d655f33
commit
4b6c012c49
5
pom.xml
5
pom.xml
@ -17,6 +17,11 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aparapi</groupId>
|
||||||
|
<artifactId>aparapi</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -2,6 +2,9 @@ package sig;
|
|||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import com.aparapi.Range;
|
||||||
|
|
||||||
import java.awt.image.ColorModel;
|
import java.awt.image.ColorModel;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
@ -18,7 +21,10 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
public int height=SigKeeper.SCREEN_HEIGHT;
|
public int height=SigKeeper.SCREEN_HEIGHT;
|
||||||
private Image imageBuffer;
|
private Image imageBuffer;
|
||||||
private MemoryImageSource mImageProducer;
|
private MemoryImageSource mImageProducer;
|
||||||
public int pixel[];
|
public int[] pixel;
|
||||||
|
public float[] triPoints;
|
||||||
|
|
||||||
|
RenderKernel renderer;
|
||||||
|
|
||||||
public Panel() {
|
public Panel() {
|
||||||
super(true);
|
super(true);
|
||||||
@ -33,6 +39,7 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init(){
|
public void init(){
|
||||||
|
triPoints = new float[120000000];
|
||||||
cm = getCompatibleColorModel();
|
cm = getCompatibleColorModel();
|
||||||
width = getWidth();
|
width = getWidth();
|
||||||
height = getHeight();
|
height = getHeight();
|
||||||
@ -45,15 +52,43 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
mImageProducer = new MemoryImageSource(width, height, cm, pixel,0, width);
|
mImageProducer = new MemoryImageSource(width, height, cm, pixel,0, width);
|
||||||
mImageProducer.setAnimated(true);
|
mImageProducer.setAnimated(true);
|
||||||
mImageProducer.setFullBufferUpdates(true);
|
mImageProducer.setFullBufferUpdates(true);
|
||||||
|
renderer = new RenderKernel(pixel,triPoints,SigKeeper.SCREEN_WIDTH,SigKeeper.SCREEN_HEIGHT);
|
||||||
|
renderer.setExplicit(true);
|
||||||
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
||||||
if(thread.isInterrupted() || !thread.isAlive()){
|
if(thread.isInterrupted() || !thread.isAlive()){
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
//renderer.setExplicit(true);
|
||||||
|
//renderer.put(pixel);
|
||||||
}
|
}
|
||||||
public /* abstract */ void render(){
|
public /* abstract */ void render(){
|
||||||
int[] p = pixel; // this avoid crash when resizing
|
int[] p = pixel; // this avoid crash when resizing
|
||||||
if(p.length != width * height) return;
|
if(p!=null && p.length != width * height) return;
|
||||||
|
for (int x=0;x<SigKeeper.SCREEN_WIDTH;x++) {
|
||||||
|
for (int y=0;y<SigKeeper.SCREEN_HEIGHT;y++) {
|
||||||
|
pixel[y*SigKeeper.SCREEN_WIDTH+x]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
//a=h/w
|
//a=h/w
|
||||||
|
for (int i=0;i<SigKeeper.tris.size();i++) {
|
||||||
|
Triangle t = SigKeeper.tris.get(i);
|
||||||
|
triPoints[i*12+0]=t.A.x;
|
||||||
|
triPoints[i*12+1]=t.A.y;
|
||||||
|
triPoints[i*12+2]=t.A.z;
|
||||||
|
triPoints[i*12+3]=t.A.w;
|
||||||
|
triPoints[i*12+4]=t.B.x;
|
||||||
|
triPoints[i*12+5]=t.B.y;
|
||||||
|
triPoints[i*12+6]=t.B.z;
|
||||||
|
triPoints[i*12+7]=t.B.w;
|
||||||
|
triPoints[i*12+8]=t.C.x;
|
||||||
|
triPoints[i*12+9]=t.C.y;
|
||||||
|
triPoints[i*12+10]=t.C.z;
|
||||||
|
triPoints[i*12+11]=t.C.w;
|
||||||
|
}
|
||||||
|
//renderer.put(triPoints);
|
||||||
|
if (renderer!=null) {
|
||||||
|
renderer.execute(Range.create(1000000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repaint() {
|
public void repaint() {
|
||||||
|
39
src/sig/RenderKernel.java
Normal file
39
src/sig/RenderKernel.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
import com.aparapi.Kernel;
|
||||||
|
|
||||||
|
public class RenderKernel extends Kernel{
|
||||||
|
|
||||||
|
int[] pixels;
|
||||||
|
float[] tris;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
RenderKernel(int[] pixels,float[] tris,int width,int height) {
|
||||||
|
this.pixels=pixels;
|
||||||
|
this.tris=tris;
|
||||||
|
this.width=width;
|
||||||
|
this.height=height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int id = getGlobalId();
|
||||||
|
tris[id*12+0]+=1;
|
||||||
|
tris[id*12+1]+=1;
|
||||||
|
tris[id*12+4]-=1;
|
||||||
|
tris[id*12+5]+=1;
|
||||||
|
tris[id*12+8]+=1;
|
||||||
|
tris[id*12+9]-=1;
|
||||||
|
int x1=(int)tris[id*12+0];
|
||||||
|
int y1=(int)tris[id*12+1];
|
||||||
|
int x2=(int)tris[id*12+4];
|
||||||
|
int y2=(int)tris[id*12+5];
|
||||||
|
int x3=(int)tris[id*12+8];
|
||||||
|
int y3=(int)tris[id*12+9];
|
||||||
|
if (x1>=0&&x1<width&&y1>=0&&y1<height) {pixels[y1*width+x1]=0xFF;}
|
||||||
|
if (x2>=0&&x2<width&&y2>=0&&y2<height) {pixels[y2*width+x2]=0xFF00;}
|
||||||
|
if (x3>=0&&x3<width&&y3>=0&&y3<height) {pixels[y3*width+x3]=0xFF0000;}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,8 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.awt.GraphicsDevice;
|
import java.awt.GraphicsDevice;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@ -29,7 +31,10 @@ public class SigKeeper implements WindowFocusListener,KeyListener,MouseListener,
|
|||||||
|
|
||||||
public static Cursor invisibleCursor;
|
public static Cursor invisibleCursor;
|
||||||
|
|
||||||
|
public static List<Triangle> tris = new ArrayList<Triangle>();
|
||||||
|
|
||||||
SigKeeper() {
|
SigKeeper() {
|
||||||
|
|
||||||
frame = new JFrame("SigKeeper");
|
frame = new JFrame("SigKeeper");
|
||||||
panel = new Panel();
|
panel = new Panel();
|
||||||
|
|
||||||
@ -44,19 +49,15 @@ public class SigKeeper implements WindowFocusListener,KeyListener,MouseListener,
|
|||||||
invisibleCursor = frame.getToolkit().createCustomCursor(new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB),new Point(),null);
|
invisibleCursor = frame.getToolkit().createCustomCursor(new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB),new Point(),null);
|
||||||
|
|
||||||
panel.setCursor(invisibleCursor);
|
panel.setCursor(invisibleCursor);
|
||||||
frame.setVisible(true);
|
|
||||||
GraphicsDevice screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
GraphicsDevice screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||||
frame.setLocation((screen.getDisplayMode().getWidth()-SCREEN_WIDTH)/2,(screen.getDisplayMode().getHeight()-SCREEN_HEIGHT)/2);
|
frame.setLocation((screen.getDisplayMode().getWidth()-SCREEN_WIDTH)/2,(screen.getDisplayMode().getHeight()-SCREEN_HEIGHT)/2);
|
||||||
|
frame.setVisible(true);
|
||||||
panel.init();
|
panel.init();
|
||||||
for (int x=30;x<=100;x++) {
|
|
||||||
for (int y=30;y<=100;y++) {
|
for (int i=0;i<1000000;i++) {
|
||||||
if (y==30||y==100) {
|
tris.add(new Triangle(new Vertex((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100),
|
||||||
panel.pixel[y*SCREEN_WIDTH+x]=0xFF;
|
new Vertex((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100),
|
||||||
} else
|
new Vertex((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100)));
|
||||||
if (x==30||x==100){
|
|
||||||
panel.pixel[y*SCREEN_WIDTH+x]=0xFF00;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
|
12
src/sig/Triangle.java
Normal file
12
src/sig/Triangle.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
public class Triangle {
|
||||||
|
Vertex A;
|
||||||
|
Vertex B;
|
||||||
|
Vertex C;
|
||||||
|
public Triangle(Vertex a, Vertex b, Vertex c) {
|
||||||
|
A = a;
|
||||||
|
B = b;
|
||||||
|
C = c;
|
||||||
|
}
|
||||||
|
}
|
20
src/sig/Vertex.java
Normal file
20
src/sig/Vertex.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
public class Vertex {
|
||||||
|
float x,y,z,w;
|
||||||
|
|
||||||
|
public Vertex() {
|
||||||
|
this(0,0,0,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vertex(float x, float y, float z) {
|
||||||
|
this(x,y,z,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vertex(float x, float y, float z,float w) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.w = w;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user