Example usage for org.lwjgl.opengl GL11 glGetInteger

List of usage examples for org.lwjgl.opengl GL11 glGetInteger

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glGetInteger.

Prototype

@NativeType("void")
public static int glGetInteger(@NativeType("GLenum") int pname) 

Source Link

Document

Returns the current integer value of the specified state variable.

Usage

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

final int tempBind() {
    int oldID = GL11.glGetInteger(binding);
    if (oldID != id)
        GL11.glBindTexture(target, id);//from w  w  w  .  j  a v  a 2  s.  com
    return oldID;
}

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

/**
 * Temporarily activates the given texture unit, binds this texture to it,
 * then activates whichever unit was active before this method was called.
 * //  www. ja  v a2s  .c  o m
 * @param texture The OpenGL texture unit enum to bind to.
 * @return This texture.
 */
public final T bind(int texture) {
    if (deleted)
        throw new IllegalStateException("Cannot bind deleted texture.");
    if (texture < GL13.GL_TEXTURE0)
        throw new IllegalArgumentException();
    int old = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
    GL13.glActiveTexture(texture);
    bind();
    GL13.glActiveTexture(old);
    return getThis();
}

From source file:com.samrj.devil.gl.VertexBuffer.java

License:Open Source License

/**
 * Completes this vertex buffer, uploading its vertex data to the GPU and
 * freeing local resources.//  w  w w  .j  ava  2s  .  c o  m
 */
public void end() {
    ensureState(State.READY);
    if (numVertices <= 0)
        throw new IllegalStateException("No vertices emitted.");

    vbo = GL15.glGenBuffers();
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.nglBufferData(GL15.GL_ARRAY_BUFFER, numVertices * vertexSize(), vertexBlock.address,
            GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    vramUsage += vertexBlock.size * 8L;
    vertexBlock.free();
    vertexBlock = null;
    vertexBuffer = null;

    if (maxIndices > 0) {
        if (numIndices > 0) {
            ibo = GL15.glGenBuffers();
            prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
            GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
            GL15.nglBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, numIndices * 4, indexBlock.address,
                    GL15.GL_STATIC_DRAW);
            GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);
        }

        vramUsage += indexBlock.size * 8L;
        indexBlock.free();
        indexBlock = null;
        indexBuffer = null;
    }

    state = State.COMPLETE;

    Profiler.addUsedVRAM(vramUsage);
}

From source file:com.samrj.devil.gl.VertexStream.java

License:Open Source License

@Override
void onBegin() {/*from w ww .  j  a  v a 2s. c om*/
    vboSize = maxVertices * vertexSize();
    vertexBlock = new Memory(vboSize);
    vertexBuffer = vertexBlock.buffer;
    vbo = GL15.glGenBuffers();
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vboSize, GL15.GL_STREAM_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    if (maxIndices > 0) {
        eboSize = maxIndices * 4;
        indexBlock = new Memory(eboSize);
        indexBuffer = indexBlock.buffer;
        ibo = GL15.glGenBuffers();
        prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, eboSize, GL15.GL_STREAM_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);
    }

    state = State.READY;

    Profiler.addUsedVRAM(vboSize * 8L);
    Profiler.addUsedVRAM(eboSize * 8L);
}

From source file:com.samrj.devil.gl.VertexStream.java

License:Open Source License

/**
 * Uploads this vertex data to the GPU and clears the stream, allowing new
 * data to be emitted.//from   w  ww  .ja  v  a 2 s.c om
 */
public void upload() {
    ensureState(State.READY);

    //Allocate new stores, orphaning the old ones to allow for asynchronous drawing.
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vboSize, GL15.GL_STREAM_DRAW);
    GL15.nglBufferSubData(GL15.GL_ARRAY_BUFFER, 0, bufferedVerts * vertexSize(), vertexBlock.address);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    if (maxIndices > 0) {
        prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, eboSize, GL15.GL_STREAM_DRAW);
        GL15.nglBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, bufferedInds * 4, indexBlock.address);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);
    }

    uploadedVerts = bufferedVerts;
    uploadedInds = bufferedInds;

    clear();
}

From source file:com.samrj.devil.graphics.MeshDrawer.java

License:Open Source License

public MeshDrawer(Mesh mesh) {
    this.mesh = mesh;

    //Set up attributes.
    position = new Attribute(VEC3, mesh.positionOffset, true);
    normal = new Attribute(VEC3, mesh.normalOffset, mesh.hasNormals);
    uvs = new HashMap<>();
    for (int i = 0; i < mesh.uvLayers.length; i++) {
        Attribute color = new Attribute(VEC2, mesh.uvOffsets[i], true);
        uvs.put(mesh.uvLayers[i], color);
    }//w w w. j  ava  2s .c o  m
    tangent = new Attribute(VEC3, mesh.tangentOffset, mesh.hasTangents);
    colors = new HashMap<>();
    for (int i = 0; i < mesh.colorLayers.length; i++) {
        Attribute color = new Attribute(VEC3, mesh.colorOffsets[i], true);
        colors.put(mesh.colorLayers[i], color);
    }

    AttributeType groupsType, weightType;
    switch (mesh.numGroups) {
    case 0:
        groupsType = NONE;
        weightType = NONE;
        break;
    case 1:
        groupsType = INT;
        weightType = FLOAT;
        break;
    case 2:
        groupsType = VEC2I;
        weightType = VEC2;
        break;
    case 3:
        groupsType = VEC3I;
        weightType = VEC3;
        break;
    case 4:
        groupsType = VEC4I;
        weightType = VEC4;
        break;
    default:
        throw new IllegalArgumentException("Vertex group count over four.");
    }

    groups = new Attribute(groupsType, mesh.groupIndexOffset, mesh.numGroups > 0);
    weights = new Attribute(weightType, mesh.groupWeightOffset, mesh.numGroups > 0);
    material = new Attribute(INT, mesh.materialOffset, mesh.hasMaterials);

    vbo = GL15.glGenBuffers();
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.nglBufferData(GL15.GL_ARRAY_BUFFER, mesh.vertexBlock.size, mesh.vertexBlock.address,
            GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    ibo = GL15.glGenBuffers();
    prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
    GL15.nglBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.indexBlock.size, mesh.indexBlock.address,
            GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);

    attributes = new HashMap<>();

    Profiler.addUsedVRAM(mesh.vertexBlock.size * 8L);
    Profiler.addUsedVRAM(mesh.indexBlock.size * 8L);
}

From source file:com.xrbpowered.gl.Client.java

License:Open Source License

public static void printInfo() {
    System.out.println("\n--------------------------------\nSYSTEM INFO\n--------------------------------");
    System.out.println("Device: " + GL11.glGetString(GL11.GL_RENDERER));
    System.out.println("Device vendor: " + GL11.glGetString(GL11.GL_VENDOR));
    System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));

    System.out.printf("Max texture size: %d\n", GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE));
    System.out.printf("Max MSAA samples: %d\n", GL11.glGetInteger(GL30.GL_MAX_SAMPLES));
    System.out.printf("Max anisotropy: %d\n",
            GL11.glGetInteger(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT));
    System.out.printf("Max texture array layers: %d\n", GL11.glGetInteger(GL30.GL_MAX_ARRAY_TEXTURE_LAYERS));
    System.out.printf("Max vertex attribs: %d\n", GL11.glGetInteger(GL20.GL_MAX_VERTEX_ATTRIBS));
    System.out.printf("Max uniform components: %d\n", GL11.glGetInteger(GL20.GL_MAX_VERTEX_UNIFORM_COMPONENTS));
    System.out.printf("Available video memory (NVIDIA only): %.1f%%\n", getAvailMemoryNVidia() * 100f);
    System.out.println("--------------------------------");
    System.out.println();//from  w w w.ja v a2  s . co m

    GL11.glGetError(); // clear errors
}

From source file:com.xrbpowered.gl.Client.java

License:Open Source License

public static float getAvailMemoryNVidia() {
    try {/*from  w  ww.  j  av a2 s.c  o  m*/
        return (float) GL11.glGetInteger(NVXGpuMemoryInfo.GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX)
                / (float) GL11.glGetInteger(NVXGpuMemoryInfo.GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX);
    } catch (Exception e) {
        return -1f;
    }
}

From source file:com.xrbpowered.gl.Client.java

License:Open Source License

public static boolean isGLExtensionSupported(String name) {
    int count = GL11.glGetInteger(GL30.GL_NUM_EXTENSIONS);
    for (int i = 0; i < count; i++) {
        String ext = GL30.glGetStringi(GL11.GL_EXTENSIONS, i);
        if (name.equals(ext))
            return true;
    }//  www  .j  a va2s .  co m
    return false;
}

From source file:com.xrbpowered.gl.examples.ExampleMenu.java

License:Open Source License

protected void addQualitySettings(WidgetMenuBuilder mb) {
    int max = GL11.glGetInteger(GL30.GL_MAX_SAMPLES);
    int index = 0;
    LinkedList<String> options = new LinkedList<>();
    options.add("Off");
    for (int i = 1, d = 2; d <= max; i++, d <<= 1) {
        options.add(d + "x");
        if (d == settings.multisample)
            index = i;// ww  w .j ava 2 s.  c om
    }
    mb.addMenuItem(new MenuOptionItem(mb.getPageRoot(), "Anti-aliasing", options.toArray(), index, 0) {
        @Override
        public void onChangeValue(int index) {
            String s = getValueName();
            settings.multisample = s.equals("Off") ? 0 : Integer.parseInt(s.substring(0, s.length() - 1));
        }
    });

    max = GL11.glGetInteger(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
    index = 0;
    options.clear();
    options.add("Off");
    for (int i = 1, d = 2; d <= max; i++, d <<= 1) {
        options.add(d + "x");
        if (d == settings.anisotropy)
            index = i;
    }
    mb.addMenuItem(new MenuOptionItem(mb.getPageRoot(), "Anisotropic filtering", options.toArray(), index, 0) {
        @Override
        public void onChangeValue(int index) {
            String s = getValueName();
            settings.anisotropy = s.equals("Off") ? 1 : Integer.parseInt(s.substring(0, s.length() - 1));
        }
    });
}