public void unbind()
{
GL11 localGL11 = Gdx.gl11;
int i = this.attributes.size();
int j = 0;
int k = 0;
if (j < i)
{
VertexAttribute localVertexAttribute = this.attributes.get(j);
switch (localVertexAttribute.usage)
{
case 4:
default:
throw new GdxRuntimeException("unkown vertex attribute type: " + localVertexAttribute.usage);
case 1:
case 5:
localGL11.glDisableClientState(32886);
case 0:
case 2:
case 3:
}
while (true)
{
j++;
break;
localGL11.glDisableClientState(32885);
continue;
localGL11.glClientActiveTexture(33984 + k);
localGL11.glDisableClientState(32888);
k++;
}
}
localGL11.glBindBuffer(34962, 0);
this.isBound = false;
}
java类com.badlogic.gdx.graphics.VertexAttribute的实例源码
VertexBufferObjectSubData.java 文件源码
项目:ingress-indonesia-dev
阅读 27
收藏 0
点赞 0
评论 0
TestCamera.java 文件源码
项目:GDX-Engine
阅读 32
收藏 0
点赞 0
评论 0
@Override
public void create() {
rotationSpeed = 0.5f;
mesh = new Mesh(true, 4, 6,
new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"),
new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords"));
texture = new Texture(Gdx.files.internal("data/Jellyfish.jpg"));
mesh.setVertices(new float[] {
-1024f, -1024f, 0, 0, 1,
1024f, -1024f, 0, 1, 1,
1024f, 1024f, 0, 1, 0,
-1024f, 1024f, 0, 0, 0
});
mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
xScale = Gdx.graphics.getWidth()/(float)TARGET_WIDTH;
yScale = Gdx.graphics.getHeight()/(float)TARGET_HEIGHT;
font = loadBitmapFont("default.fnt", "default.png");
scale = Math.min(xScale, yScale);
cam.zoom = 1/scale;
// cam.project(start_position);
cam.position.set(0, 0, 0);
batch = new SpriteBatch();
}
ShaderEffect.java 文件源码
项目:gdx-gfx
阅读 22
收藏 0
点赞 0
评论 0
/**
* Instantiates a new ShaderEffect. The ShaderEffect will NOT own shader
* program, so it will not dispose it either!
*
* @param program
* the ShaderProgram to use for this effect
*/
public ShaderEffect(ShaderProgram program) {
this.program = program;
if (meshRefCount++ <= 0) {
mesh = new Mesh(VertexDataType.VertexArray, true, 4, 0,
new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
// @formatter:off
float[] verts = {
// vertex texture
-1, -1, 0f, 0f,
1, -1, 1f, 0f,
1, 1, 1f, 1f,
-1, 1, 0f, 1f,
};
// @formatter:on
mesh.setVertices(verts);
}
}
DepthMapShader.java 文件源码
项目:nhglib
阅读 23
收藏 0
点赞 0
评论 0
private String createPrefix(Renderable renderable) {
String prefix = "";
if (params.useBones) {
prefix += "#define numBones " + 12 + "\n";
final int n = renderable.meshPart.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i);
if (attr.usage == VertexAttributes.Usage.BoneWeight) {
prefix += "#define boneWeight" + attr.unit + "Flag\n";
}
}
}
return prefix;
}
PBRShader.java 文件源码
项目:LibGDX-PBR
阅读 39
收藏 0
点赞 0
评论 0
protected final int[] getAttributeLocations(Renderable renderable) {
final IntIntMap attributes = new IntIntMap();
final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes();
final int c = attrs.size();
for (int i = 0; i < c; i++) {
final VertexAttribute attr = attrs.get(i);
final int location = program.getAttributeLocation(attr.alias);
if (location >= 0)
attributes.put(attr.getKey(), location);
}
tempArray.clear();
final int n = attrs.size();
for (int i = 0; i < n; i++) {
tempArray.add(attributes.get(attrs.get(i).getKey(), -1));
}
return tempArray.items;
}
PBRSadherTexture.java 文件源码
项目:LibGDX-PBR
阅读 24
收藏 0
点赞 0
评论 0
protected final int[] getAttributeLocations(Renderable renderable) {
final IntIntMap attributes = new IntIntMap();
final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes();
final int c = attrs.size();
for (int i = 0; i < c; i++) {
final VertexAttribute attr = attrs.get(i);
final int location = program.getAttributeLocation(attr.alias);
if (location >= 0)
attributes.put(attr.getKey(), location);
}
tempArray.clear();
final int n = attrs.size();
for (int i = 0; i < n; i++) {
tempArray.add(attributes.get(attrs.get(i).getKey(), -1));
}
return tempArray.items;
}
Ground.java 文件源码
项目:exterminate
阅读 34
收藏 0
点赞 0
评论 0
public void makeMesh() {
int rayon = Math.max(ExterminateGame.rendu, ExterminateGame.MAX_VIEW_DISTANCE)+5;
int nbTriangles=ChunkBuilder.GRIDSIZE*ChunkBuilder.GRIDSIZE*2*rayon*2*rayon*2;
int nbVertex=(ChunkBuilder.GRIDSIZE+1)*(ChunkBuilder.GRIDSIZE+1)*rayon*2*rayon*2;
FloatBuffer vertexL = org.lwjgl.BufferUtils.createFloatBuffer(nbVertex*ChunkBuilder.SOL_VERTICE_SIZE);
IntBuffer indicesL = org.lwjgl.BufferUtils.createIntBuffer(nbTriangles*3);
mesh = new UniMesh(true, true, nbVertex, nbTriangles*3, new VertexAttributes(VertexAttribute.Position(), VertexAttribute.NormalPacked(), VertexAttribute.TexCoords(0), VertexAttribute.ColorPacked()));
mesh.setVertices(vertexL, 0, nbVertex*ChunkBuilder.SOL_VERTICE_SIZE);
mesh.setIndices(indicesL, 0, nbTriangles*3);
mesh.setCapacity(0);
usedSol = new boolean[rayon*2*rayon*2];
forChunk = new Chunk[rayon*2*rayon*2];
for(int i=0;i<rayon*2*rayon*2;i++) {
usedSol[i] = false;
}
UniVertexBufferObject.showMem();
}
PositionalLight.java 文件源码
项目:fabulae
阅读 24
收藏 0
点赞 0
评论 0
public PositionalLight (RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) {
super(rayHandler, rays, color, directionDegree, distance);
start.x = x;
start.y = y;
sin = new float[rays];
cos = new float[rays];
endX = new float[rays];
endY = new float[rays];
lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
setMesh();
}
DirectionalLight.java 文件源码
项目:fabulae
阅读 23
收藏 0
点赞 0
评论 0
/** Directional lights simulate light source that locations is at infinite distance. Direction and intensity is same everywhere.
* -90 direction is straight from up.
*
* @param rayHandler
* @param rays
* @param color
* @param directionDegree */
public DirectionalLight (RayHandler rayHandler, int rays, Color color, float directionDegree) {
super(rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY);
vertexNum = (vertexNum - 1) * 2;
start = new Vector2[rayNum];
end = new Vector2[rayNum];
for (int i = 0; i < rayNum; i++) {
start[i] = new Vector2();
end[i] = new Vector2();
}
setDirection(direction);
lightMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
softShadowMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
update();
}
RavChainLight.java 文件源码
项目:RavTech
阅读 22
收藏 0
点赞 0
评论 0
/** Creates chain light from specified vertices
*
* @param rayHandler not {@code null} instance of RayHandler
* @param rays number of rays - more rays make light to look more realistic but will decrease performance, can't be less than
* MIN_RAYS
* @param color color, set to {@code null} to use the default color
* @param distance distance of light
* @param rayDirection direction of rays
* <ul>
* <li>1 = left</li>
* <li>-1 = right</li>
* </ul>
* @param chain float array of (x, y) vertices from which rays will be evenly distributed */
public RavChainLight (RayHandler rayHandler, int rays, Color color, float distance, int rayDirection, float[] chain) {
super(rayHandler, rays, color, distance, 0f);
rayStartOffset = ChainLight.defaultRayStartOffset;
this.rayDirection = rayDirection;
vertexNum = (vertexNum - 1) * 2;
endX = new float[rays];
endY = new float[rays];
startX = new float[rays];
startY = new float[rays];
this.chain = (chain != null) ? new FloatArray(chain) : new FloatArray();
lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0,
new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0,
new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
setMesh();
}
Sprite3DCache.java 文件源码
项目:ForgE
阅读 19
收藏 0
点赞 0
评论 0
private void buildMesh() {
mesh = new Mesh(true, SIZE, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
mesh.setVertices(vertices);
short[] indices = new short[6];
int v = 0;
for (int i = 0; i < indices.length; i += 6, v += 4) {
indices[i] = (short)(v);
indices[i + 1] = (short)(v + 2);
indices[i + 2] = (short)(v + 1);
indices[i + 3] = (short)(v + 1);
indices[i + 4] = (short)(v + 2);
indices[i + 5] = (short)(v + 3);
}
mesh.setIndices(indices);
}
QuadBuilder.java 文件源码
项目:ForgE
阅读 37
收藏 0
点赞 0
评论 0
public static Mesh build(float size, TextureRegion region) {
Mesh mesh = new Mesh(true, SIZE, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
mesh.setVertices(verticies(size, region));
mesh.setAutoBind(false);
short[] indices = new short[6];
int v = 0;
for (int i = 0; i < indices.length; i += 6, v += 4) {
indices[i] = (short)(v);
indices[i + 1] = (short)(v + 2);
indices[i + 2] = (short)(v + 1);
indices[i + 3] = (short)(v + 1);
indices[i + 4] = (short)(v + 2);
indices[i + 5] = (short)(v + 3);
}
mesh.setIndices(indices);
return mesh;
}
ImmediateModeRenderer20.java 文件源码
项目:libgdxcn
阅读 45
收藏 0
点赞 0
评论 0
public ImmediateModeRenderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) {
this.maxVertices = maxVertices;
this.numTexCoords = numTexCoords;
this.shader = shader;
VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords);
mesh = new Mesh(false, maxVertices, 0, attribs);
vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)];
vertexSize = mesh.getVertexAttributes().vertexSize / 4;
normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0;
colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4
: 0;
texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh
.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0;
shaderUniformNames = new String[numTexCoords];
for (int i = 0; i < numTexCoords; i++) {
shaderUniformNames[i] = "u_sampler" + i;
}
}
DepthShader.java 文件源码
项目:libgdxcn
阅读 34
收藏 0
点赞 0
评论 0
@Override
public boolean canRender (Renderable renderable) {
if (renderable.material.has(BlendingAttribute.Type)) {
if ((materialMask & BlendingAttribute.Type) != BlendingAttribute.Type)
return false;
if (renderable.material.has(TextureAttribute.Diffuse) != ((materialMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse))
return false;
}
final boolean skinned = ((renderable.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight);
if (skinned != (numBones > 0)) return false;
if (!skinned) return true;
int w = 0;
final int n = renderable.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.mesh.getVertexAttributes().get(i);
if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit);
}
return w == weights;
}
DecalBatch.java 文件源码
项目:libgdxcn
阅读 25
收藏 0
点赞 0
评论 0
/** Initializes the batch with the given amount of decal objects the buffer is able to hold when full.
*
* @param size Maximum size of decal objects to hold in memory */
public void initialize (int size) {
vertices = new float[size * Decal.SIZE];
mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, size * 4, size * 6, new VertexAttribute(
VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(
VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
short[] indices = new short[size * 6];
int v = 0;
for (int i = 0; i < indices.length; i += 6, v += 4) {
indices[i] = (short)(v);
indices[i + 1] = (short)(v + 2);
indices[i + 2] = (short)(v + 1);
indices[i + 3] = (short)(v + 1);
indices[i + 4] = (short)(v + 2);
indices[i + 5] = (short)(v + 3);
}
mesh.setIndices(indices);
}
MeshBuilder.java 文件源码
项目:libgdxcn
阅读 34
收藏 0
点赞 0
评论 0
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and
* TextureCoordinates is supported. */
public static VertexAttributes createAttributes (long usage) {
final Array<VertexAttribute> attrs = new Array<VertexAttribute>();
if ((usage & Usage.Position) == Usage.Position)
attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if ((usage & Usage.Color) == Usage.Color) attrs.add(new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.ColorPacked) == Usage.ColorPacked)
attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.Normal) == Usage.Normal)
attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates)
attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final VertexAttribute attributes[] = new VertexAttribute[attrs.size];
for (int i = 0; i < attributes.length; i++)
attributes[i] = attrs.get(i);
return new VertexAttributes(attributes);
}
PolygonSpriteBatch.java 文件源码
项目:libgdxcn
阅读 26
收藏 0
点赞 0
评论 0
/** Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards,
* x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect
* with respect to the current screen resolution.
* <p>
* The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than
* the ones expect for shaders set with {@link #setShader(ShaderProgram)}. See {@link SpriteBatch#createDefaultShader()}.
* @param size The max number of vertices and number of triangles in a single batch. Max of 10920.
* @param defaultShader The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately. */
public PolygonSpriteBatch (int size, ShaderProgram defaultShader) {
// 32767 is max index, so 32767 / 3 - (32767 / 3 % 3) = 10920.
if (size > 10920) throw new IllegalArgumentException("Can't have more than 10920 triangles per batch: " + size);
mesh = new Mesh(VertexDataType.VertexArray, false, size, size * 3, new VertexAttribute(Usage.Position, 2,
ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE),
new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
vertices = new float[size * VERTEX_SIZE];
triangles = new short[size * 3];
if (defaultShader == null) {
shader = SpriteBatch.createDefaultShader();
ownsShader = true;
} else
shader = defaultShader;
projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
ProjectiveTextureTest.java 文件源码
项目:libgdxcn
阅读 28
收藏 0
点赞 0
评论 0
public void setupScene () {
plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(
Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
plane.setVertices(new float[] {-10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0});
plane.setIndices(new short[] {3, 2, 1, 1, 0, 3});
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 5, 10);
cam.lookAt(0, 0, 0);
cam.update();
controller = new PerspectiveCamController(cam);
projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
projector.position.set(2, 3, 2);
projector.lookAt(0, 0, 0);
projector.normalizeUp();
projector.update();
}
MeshShaderTest.java 文件源码
项目:libgdxcn
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void create () {
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n"
+ "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;"
+ "void main() \n" + "{ \n" + " v_color = vec4(1, 1, 1, 1); \n"
+ " v_texCoords = a_texCoord0; \n" + " gl_Position = u_worldView * a_position; \n"
+ "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n"
+ "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n"
+ "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n"
+ "}";
shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false) {
Gdx.app.log("ShaderTest", shader.getLog());
Gdx.app.exit();
}
mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0));
mesh.setVertices(new float[] {-0.5f, -0.5f, 0, 1, 1, 1, 1, 0, 1, 0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1, 0.5f, 0.5f, 0, 1, 1, 1,
1, 1, 0, -0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0});
mesh.setIndices(new short[] {0, 1, 2, 2, 3, 0});
texture = new Texture(Gdx.files.internal("data/bobrgb888-32x32.png"));
}
FrameBufferTest.java 文件源码
项目:libgdxcn
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void create () {
mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4,
"a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
float c1 = Color.toFloatBits(255, 0, 0, 255);
float c2 = Color.toFloatBits(255, 0, 0, 255);
float c3 = Color.toFloatBits(0, 0, 255, 255);
mesh.setVertices(new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1});
stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(
Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
stencilMesh.setVertices(new float[] {-0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1});
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
spriteBatch = new SpriteBatch();
frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false);
stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true);
createShader(Gdx.graphics);
}
IndexBufferObjectShaderTest.java 文件源码
项目:libgdxcn
阅读 36
收藏 0
点赞 0
评论 0
@Override
public void create () {
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n"
+ "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n"
+ "{ \n" + " v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n"
+ " v_texCoords = a_texCoords; \n" + " gl_Position = a_position; \n" + "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n"
+ "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n"
+ "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n"
+ "}";
shader = new ShaderProgram(vertexShader, fragmentShader);
vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"),
new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute(
VertexAttributes.Usage.ColorPacked, 4, "a_color"));
float[] vertices = new float[] {-1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f,
Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f)};
vbo.setVertices(vertices, 0, vertices.length);
ibo = new IndexBufferObject(true, 3);
ibo.setIndices(new short[] {0, 1, 2}, 0, 3);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
BillboardStarRenderSystem.java 文件源码
项目:gaiasky
阅读 27
收藏 0
点赞 0
评论 0
private void init(String tex0, float w, float h) {
setTexture0(tex0);
// Init comparator
comp = new DistToCameraComparator<IRenderable>();
// Init vertices
float[] vertices = new float[20];
fillVertices(vertices, w, h);
// We wont need indices if we use GL_TRIANGLE_FAN to draw our quad
// TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3
mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
mesh.setVertices(vertices, 0, vertices.length);
mesh.getIndicesBuffer().position(0);
mesh.getIndicesBuffer().limit(6);
short[] indices = new short[] { 0, 1, 2, 0, 2, 3 };
mesh.setIndices(indices);
quaternion = new Quaternion();
aux = new Vector3();
}
LineRenderSystem.java 文件源码
项目:gaiasky
阅读 24
收藏 0
点赞 0
评论 0
@Override
protected void initVertices() {
meshes = new MeshData[2];
maxVertices = MAX_VERTICES;
// ORIGINAL LINES
curr = new MeshData();
meshes[0] = curr;
VertexAttribute[] attribs = buildVertexAttributes();
curr.mesh = new Mesh(false, maxVertices, 0, attribs);
curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)];
curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4;
curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0;
}
LineQuadRenderSystem.java 文件源码
项目:gaiasky
阅读 22
收藏 0
点赞 0
评论 0
private void initVertices(int index) {
if (meshes[index] == null) {
currext = new MeshDataExt();
meshes[index] = currext;
curr = currext;
maxVertices = MAX_VERTICES;
currext.maxIndices = maxVertices + maxVertices / 2;
VertexAttribute[] attribs = buildVertexAttributes();
currext.mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, maxVertices, currext.maxIndices, attribs);
currext.indices = new short[currext.maxIndices];
currext.vertexSize = currext.mesh.getVertexAttributes().vertexSize / 4;
currext.vertices = new float[maxVertices * currext.vertexSize];
currext.colorOffset = currext.mesh.getVertexAttribute(Usage.ColorPacked) != null ? currext.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0;
currext.uvOffset = currext.mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? currext.mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0;
} else {
currext = (MeshDataExt) meshes[index];
curr = currext;
}
}
PixelRenderSystem.java 文件源码
项目:gaiasky
阅读 28
收藏 0
点赞 0
评论 0
@Override
protected void initVertices() {
meshes = new MeshData[1];
curr = new MeshData();
meshes[0] = curr;
aux = new Vector3();
/** Init renderer **/
maxVertices = 3000000;
VertexAttribute[] attribs = buildVertexAttributes();
curr.mesh = new Mesh(false, maxVertices, 0, attribs);
curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)];
curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4;
curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0;
pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0;
sizeOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0;
}
BillboardSpriteRenderSystem.java 文件源码
项目:gaiasky
阅读 26
收藏 0
点赞 0
评论 0
private void init(float w, float h) {
// Init comparator
comp = new DistToCameraComparator<IRenderable>();
// Init vertices
float[] vertices = new float[20];
fillVertices(vertices, w, h);
// We wont need indices if we use GL_TRIANGLE_FAN to draw our quad
// TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3
mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
mesh.setVertices(vertices, 0, vertices.length);
mesh.getIndicesBuffer().position(0);
mesh.getIndicesBuffer().limit(6);
short[] indices = new short[] { 0, 1, 2, 0, 2, 3 };
mesh.setIndices(indices);
quaternion = new Quaternion();
aux = new Vector3();
}
ParticleGroupRenderSystem.java 文件源码
项目:gaiasky
阅读 23
收藏 0
点赞 0
评论 0
@Override
protected void initVertices() {
/** STARS **/
meshes = new MeshData[1];
curr = new MeshData();
meshes[0] = curr;
aux1 = new Vector3();
maxVertices = 10000000;
VertexAttribute[] attribs = buildVertexAttributes();
curr.mesh = new Mesh(false, maxVertices, 0, attribs);
curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)];
curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4;
curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0;
pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0;
additionalOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0;
}
MeshBuilder2.java 文件源码
项目:gaiasky
阅读 22
收藏 0
点赞 0
评论 0
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and
* TextureCoordinates is supported. */
public static VertexAttributes createAttributes(long usage) {
final Array<VertexAttribute> attrs = new Array<VertexAttribute>();
if ((usage & Usage.Position) == Usage.Position)
attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if ((usage & Usage.ColorUnpacked) == Usage.ColorUnpacked)
attrs.add(new VertexAttribute(Usage.ColorUnpacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.ColorPacked) == Usage.ColorPacked)
attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.Normal) == Usage.Normal)
attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates)
attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final VertexAttribute attributes[] = new VertexAttribute[attrs.size];
for (int i = 0; i < attributes.length; i++)
attributes[i] = attrs.get(i);
return new VertexAttributes(attributes);
}
ImmediateRenderer.java 文件源码
项目:gaiasky
阅读 30
收藏 0
点赞 0
评论 0
public ImmediateRenderer(int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) {
this.maxVertices = maxVertices;
this.numTexCoords = numTexCoords;
this.shader = shader;
VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords);
mesh = new Mesh(false, maxVertices, 0, attribs);
vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)];
vertexSize = mesh.getVertexAttributes().vertexSize / 4;
normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0;
colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0;
texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0;
shaderUniformNames = new String[numTexCoords];
for (int i = 0; i < numTexCoords; i++) {
shaderUniformNames[i] = "u_sampler" + i;
}
}
LibraryTest.java 文件源码
项目:libgdx-opencl
阅读 31
收藏 0
点赞 0
评论 0
@Override
public void create ()
{
// Init camera
this.camera = new PerspectiveCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
this.camera.position.set(0,0,-20);
this.camera.lookAt(0,0,0);
this.camera.near = 0.05f;
this.camera.far = 600.0f;
this.camera.update();
// Init test shader
this.testShader = ShaderLoader.loadShader("test");
// Init test buffer
this.testBufferObject = new DynamicVertexBufferObject(3, new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position")));
float[] vertices = new float[]
{
-10,0,0,1,0,2.5f,0,1,10,0,0,1
};
this.testBufferObject.setVertices(vertices, 0, vertices.length);
}