Java Code Examples for org.lwjgl.opengl.KHRDebug

The following examples show how to use org.lwjgl.opengl.KHRDebug. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: OpenModsLib   Source File: CommandGlDebug.java    License: MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length != 1) throw new CommandException("commands.generic.syntax");
	final String arg = args[0].toLowerCase(Locale.ROOT);
	if (arg.equals("disable")) {
		GL11.glDisable(KHRDebug.GL_DEBUG_OUTPUT);
	} else {
		final Set<Integer> allowedLevels = ALLOWED_LEVELS.get(arg);
		if (allowedLevels == null) throw new CommandException("commands.generic.syntax");

		GL11.glEnable(KHRDebug.GL_DEBUG_OUTPUT);
		for (int level : ALL_LEVELS) {
			final boolean isEnabled = allowedLevels.contains(level);
			KHRDebug.glDebugMessageControl(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, level, null, isEnabled);
		}
		KHRDebug.glDebugMessageCallback(new KHRDebugCallback());
	}

}
 
Example 2
Source Project: settlers-remake   Source File: LWJGL20DrawContext.java    License: MIT License 5 votes vote down vote up
@Override
public void drawTrianglesWithTextureColored(TextureHandle textureid, GeometryHandle shapeHandle, GeometryHandle colorHandle, int offset, int lines, int width, int stride, float x, float y) {
	bindTexture(textureid);

	if(backgroundVAO == -1) {
		if(glcaps.GL_ARB_vertex_array_object) {
			backgroundVAO = ARBVertexArrayObject.glGenVertexArrays();
			bindFormat(backgroundVAO);
		}
		GL20.glEnableVertexAttribArray(0);
		GL20.glEnableVertexAttribArray(1);
		GL20.glEnableVertexAttribArray(2);

		bindGeometry(shapeHandle);
		GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * 4, 0);
		GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * 4, 3 * 4);

		bindGeometry(colorHandle);
		GL20.glVertexAttribPointer(2, 1, GL11.GL_FLOAT, false, 0, 0);

		setObjectLabel(GL11.GL_VERTEX_ARRAY, backgroundVAO, "background-vao");
		setObjectLabel(KHRDebug.GL_BUFFER, shapeHandle.getInternalId(), "background-shape");
		setObjectLabel(KHRDebug.GL_BUFFER, colorHandle.getInternalId(), "background-color");
	}
	int starti = offset < 0 ? (int)Math.ceil(-offset/(float)stride) : 0;

	useProgram(prog_background);

	GL20.glUniform2f(prog_background.ufs[TRANS], x, y);

	bindFormat(backgroundVAO);
	for (int i = starti; i != lines; i++) {
		GL11.glDrawArrays(GL11.GL_TRIANGLES, (offset + stride * i) * 3, width * 3);
	}
}
 
Example 3
Source Project: settlers-remake   Source File: LWJGL20DrawContext.java    License: MIT License 5 votes vote down vote up
private int createShader(String name, int type) throws IOException {
	int shader = GL20.glCreateShader(type);
	setObjectLabel(KHRDebug.GL_SHADER, shader, name);

	BufferedReader is = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/"+name)));
	StringBuilder source = new StringBuilder();
	String line;

	while((line = is.readLine()) != null) {
		source.append(line).append("\n");
	}

	GL20.glShaderSource(shader, source);
	GL20.glCompileShader(shader);


	String log = GL20.glGetShaderInfoLog(shader);
	if(debugOutput != null && !log.isEmpty()) System.out.print("info log of " + name + "=====\n" + log + "==== end\n");

	if(GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == 0) {

		GL20.glDeleteShader(shader);
		throw new Error("Could not compile " + name);
	}

	return shader;
}
 
Example 4
Source Project: settlers-remake   Source File: LWJGLDebugOutput.java    License: MIT License 5 votes vote down vote up
LWJGLDebugOutput(LWJGL15DrawContext dc) {
	if(dc.glcaps.GL_KHR_debug) {
		GL11.glEnable(KHRDebug.GL_DEBUG_OUTPUT_SYNCHRONOUS);
		KHRDebug.glDebugMessageCallback(debugCallback, 0);
	} else if(dc.glcaps.GL_ARB_debug_output) {
		GL11.glEnable(ARBDebugOutput.GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
		ARBDebugOutput.glDebugMessageCallbackARB(debugCallbackARB, 0);
	}
}
 
Example 5
Source Project: settlers-remake   Source File: LWJGL15DrawContext.java    License: MIT License 5 votes vote down vote up
@Override
public GeometryHandle storeGeometry(float[] geometry, EGeometryFormatType type, boolean writable, String name) {
	GeometryHandle geometryBuffer = allocateVBO(type, name);

	bindGeometry(geometryBuffer);
	try(MemoryStack stack = MemoryStack.stackPush()) {
		ByteBuffer bfr = stack.malloc(4*geometry.length);
		bfr.asFloatBuffer().put(geometry);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, bfr, writable ? GL15.GL_DYNAMIC_DRAW : GL15.GL_STATIC_DRAW);
		setObjectLabel(KHRDebug.GL_BUFFER, geometryBuffer.getInternalId(), name + "-vertices");
	}

	return geometryBuffer;
}
 
Example 6
Source Project: settlers-remake   Source File: LWJGL15DrawContext.java    License: MIT License 5 votes vote down vote up
@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;
}
 
Example 7
Source Project: settlers-remake   Source File: LWJGL15DrawContext.java    License: MIT License 5 votes vote down vote up
protected void setObjectLabel(int type, int id, String name) {
	if(debugOutput == null) return;

	if(glcaps.GL_KHR_debug) {
		KHRDebug.glObjectLabel(type, id, name);
	}
}
 
Example 8
Source Project: mini2Dx   Source File: DesktopMini2DxGame.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Enables or disables GL debug messages for the specified severity level. Returns false if the severity
 * level could not be set (e.g. the NOTIFICATION level is not supported by the ARB and AMD extensions).
 *
 * See {@link Lwjgl3ApplicationConfiguration#enableGLDebugOutput(boolean, PrintStream)}
 */
public static boolean setGLDebugMessageControl (GLDebugMessageSeverity severity, boolean enabled) {
	GLCapabilities caps = GL.getCapabilities();
	final int GL_DONT_CARE = 0x1100; // not defined anywhere yet

	if (caps.OpenGL43) {
		GL43.glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, severity.gl43, (IntBuffer) null, enabled);
		return true;
	}

	if (caps.GL_KHR_debug) {
		KHRDebug.glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, severity.khr, (IntBuffer) null, enabled);
		return true;
	}

	if (caps.GL_ARB_debug_output && severity.arb != -1) {
		ARBDebugOutput.glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, severity.arb, (IntBuffer) null, enabled);
		return true;
	}

	if (caps.GL_AMD_debug_output && severity.amd != -1) {
		AMDDebugOutput.glDebugMessageEnableAMD(GL_DONT_CARE, severity.amd, (IntBuffer) null, enabled);
		return true;
	}

	return false;
}
 
Example 9
Source Project: settlers-remake   Source File: LWJGL20DrawContext.java    License: MIT License 4 votes vote down vote up
private ShaderProgram(String name) {
	int vertexShader = -1;
	int fragmentShader;

	String vname = name;
	if(name.contains("-")) vname = name.split("-")[0];

	try {
		vertexShader = createShader(vname+".vert", GL20.GL_VERTEX_SHADER);
		fragmentShader = createShader(name+".frag", GL20.GL_FRAGMENT_SHADER);
	} catch (IOException e) {
		e.printStackTrace();

		if(vertexShader != -1) GL20.glDeleteShader(vertexShader);
		throw new Error("could not read shader files", e);
	}

	program = GL20.glCreateProgram();
	setObjectLabel(KHRDebug.GL_PROGRAM, program, name);

	GL20.glAttachShader(program, vertexShader);
	GL20.glAttachShader(program, fragmentShader);

	GL20.glBindAttribLocation(program, 0, "vertex");
	GL20.glBindAttribLocation(program, 1, "texcoord");
	GL20.glBindAttribLocation(program, 2, "color");

	GL20.glLinkProgram(program);
	GL20.glValidateProgram(program);

	GL20.glDetachShader(program, vertexShader);
	GL20.glDetachShader(program, fragmentShader);
	GL20.glDeleteShader(vertexShader);
	GL20.glDeleteShader(fragmentShader);

	String log = GL20.glGetProgramInfoLog(program);
	if(debugOutput != null && !log.isEmpty()) System.out.print("info log of " + name + "=====\n" + log + "==== end\n");

	if(GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == 0) {

		GL20.glDeleteProgram(program);
		throw new Error("Could not link " + name);
	}

	for(int i = 0;i != ufs.length;i++) {
		int uf = GL20.glGetUniformLocation(program, uniform_names[i]);
		ufs[i] = uf;
	}
	shaders.add(this);
}