protected void specifyFormat(EGeometryFormatType format) { if (format.getTexCoordPos() == -1) { if(tex_coord_on) GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0); } else { if(!tex_coord_on) GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); int stride = format.getBytesPerVertexSize(); GL11.glVertexPointer(2, GL11.GL_FLOAT, stride, 0); GL11.glTexCoordPointer(2, GL11.GL_FLOAT, stride, format.getTexCoordPos()); } tex_coord_on = format.getTexCoordPos() != -1; }
@Override GeometryHandle allocateVBO(EGeometryFormatType type, String name) { GeometryHandle geometry = super.allocateVBO(type, name); if (glcaps.GL_ARB_vertex_array_object && type.isSingleBuffer()) { geometry.setInternalFormatId(ARBVertexArrayObject.glGenVertexArrays()); bindFormat(geometry.getInternalFormatId()); specifyFormat(type); } if(type.isSingleBuffer()) { setObjectLabel(GL11.GL_VERTEX_ARRAY, geometry.getInternalFormatId(), name + "-vao"); } return geometry; }
@Override public GeometryHandle generateGeometry(int vertices, EGeometryFormatType type, boolean writable, String name) { GeometryHandle vertexBufferId = allocateVBO(type, name); bindGeometry(vertexBufferId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices*type.getBytesPerVertexSize(), writable ? GL15.GL_DYNAMIC_DRAW : GL15.GL_STATIC_DRAW); setObjectLabel(KHRDebug.GL_BUFFER, vertexBufferId.getInternalId(), name + "-vertices"); return vertexBufferId; }
public void draw2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity) { if(lx != x || ly != y || lz != z || lsx != sx || lsy != sy || lsz != sz) { if(lsz != -1) GL11.glPopMatrix(); GL11.glPushMatrix(); if(x != 0 || y != 0 || z != 0) GL11.glTranslatef(x, y, z); if(sx != 1 || sy != 1 || sz != 1) GL11.glScalef(sx, sy, sz); lx = x; lsx = sx; ly = y; lsy = sy; lz = z; lsz = sz; } if(color != null) { float r = color.red*intensity; float g = color.green*intensity; float b = color.blue*intensity; float a = color.alpha; if(lr != r || lg != g || lb != b || la != a) GL11.glColor4f(lr=r, lg=g, lb=b, la=a); } else { if(lr != lg || lr != lb || lr != intensity || la != 1) GL11.glColor4f(intensity, intensity, intensity, 1); lr = lg = lb = intensity; la = 1; } bindTexture(texture); bindGeometry(geometry); EGeometryFormatType format = geometry.getFormat(); if(format.getTexCoordPos() == -1) GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); specifyFormat(format); GL11.glDrawArrays(primitive, offset * vertices, vertices); if(format.getTexCoordPos() == -1) GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); }
@Override protected void specifyFormat(EGeometryFormatType format) { GL20.glEnableVertexAttribArray(0); if (format.getTexCoordPos() == -1) { GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 0, 0); } else { GL20.glEnableVertexAttribArray(1); int stride = format.getBytesPerVertexSize(); GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, stride, 0); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, stride, format.getTexCoordPos()); } }