所以,我想实现通过ID采摘。 这意味着每drawArray不同的唯一ID将被设置为统一的,并保存在纹理的红色成分。
16位是绰绰有余(65000元)以上,所以我选择用短裤,我知道均匀变量可以是唯一的用户界面,但我决定给它一个想试试
我还发现了另外一个问题, 在这里 ,这里的答案中包含与短裤的小例子
但是我在这里的代码来初始化帧缓冲和两个纹理,一个是深度,一个用于只与16的红色成分的color_attachment0
textures = new int[2];
fbo = new int[1];
gl3.glGenTextures(2, textures, 0);
gl3.glGenFramebuffers(1, fbo, 0);
/**
* Depth.
*/
gl3.glBindTexture(GL3.GL_TEXTURE_RECTANGLE, textures[depth]);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_NEAREST);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_NEAREST);
gl3.glTexImage2D(GL3.GL_TEXTURE_RECTANGLE, 0, GL3.GL_DEPTH_COMPONENT32F, width, height, 0, GL3.GL_DEPTH_COMPONENT, GL3.GL_FLOAT, null);
/**
* IDs.
*/
gl3.glBindTexture(GL3.GL_TEXTURE_RECTANGLE, textures[id]);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_NEAREST);
gl3.glTexParameteri(GL3.GL_TEXTURE_RECTANGLE, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_NEAREST);
gl3.glTexImage2D(GL3.GL_TEXTURE_RECTANGLE, 0, GL3.GL_R16UI, width, height, 0, GL3.GL_RED, GL3.GL_UNSIGNED_SHORT, null);
/**
* FBO.
*/
gl3.glBindFramebuffer(GL3.GL_FRAMEBUFFER, fbo[0]);
gl3.glFramebufferTexture2D(GL3.GL_FRAMEBUFFER, GL3.GL_DEPTH_ATTACHMENT, GL3.GL_TEXTURE_RECTANGLE, textures[depth], 0);
gl3.glFramebufferTexture2D(GL3.GL_FRAMEBUFFER, GL3.GL_COLOR_ATTACHMENT0, GL3.GL_TEXTURE_RECTANGLE, textures[id], 0);
我得到以下错误的ID-glTexImage2D
GLDebugEvent[ id 0x502
type Error
severity High: dangerous undefined behavior
source GL API
msg GL_INVALID_OPERATION error generated. Texture type and format combination is not valid.
when 1391769197680
source 4.4 (Compat profile, arb, debug, ES2 compat, ES3 compat, FBO, hardware) - 4.4.0 - hash 0x1c19b340]
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1364)
at jogamp.opengl.GLDebugMessageHandler$StdErrGLDebugListener.messageSent(GLDebugMessageHandler.java:308)
at jogamp.opengl.GLDebugMessageHandler.sendMessage(GLDebugMessageHandler.java:293)
at jogamp.opengl.GLDebugMessageHandler.glDebugMessageARB(GLDebugMessageHandler.java:319)
at jogamp.opengl.gl4.GL4bcImpl.dispatch_glTexImage2D1(Native Method)
at jogamp.opengl.gl4.GL4bcImpl.glTexImage2D(GL4bcImpl.java:27313)
at javax.media.opengl.DebugGL4bc.glTexImage2D(DebugGL4bc.java:19874)
at ec.rendering.input.picking.EC_Picking.initRenderingTargets(EC_Picking.java:107)
为了完整起见,这里的VS:
#version 330
layout (location = 0) in vec3 position;
uniform mat4 modelToWorldMatrix;
layout(std140) uniform GlobalMatrices {
mat4 worldToCameraMatrix;
mat4 cameraToClipMatrix;
};
void main() {
gl_Position = cameraToClipMatrix * (worldToCameraMatrix * vec4(position, 1.0));
}
modelToWorldMatrix尚未采取帐户的那一刻
这里的FS:
#version 330
uniform uint id;
out vec4 outputColor;
void main() {
outputColor = vec4(id, 0, 0, 1);
}
使用短裤是可行的?
JOGL时,OpenGL 3.3
编辑:现在看来我解决了部分与
gl3.glTexImage2D(GL3.GL_TEXTURE_RECTANGLE, 0, GL3.GL_R16I, width, height, 0, GL3.GL_RED_INTEGER, GL3.GL_SHORT, null);
但现在我得到一个错误,当我尝试设置短均匀值
gl3.glUniform1i(pickModel.getIdUL(), (int)mesh.getId());
错误
GLDebugEvent[ id 0x502
type Error
severity High: dangerous undefined behavior
source GL API
msg GL_INVALID_OPERATION error generated. Wrong component type or count.
when 1391779682993
source 4.4 (Compat profile, arb, debug, ES2 compat, ES3 compat, FBO, hardware) - 4.4.0 - hash 0x5ee072e3]
统一的位置似乎是正确的,因为它不是-1(1实际上)...
所以,我怎么可以上传短?