我用 UBO 替换了着色器中像 mvp 矩阵这样的制服,以避免大量的 glUniform...() 调用。但是为了在每一帧中更新 UBO,我必须调用 glBufferData(),这也会降低性能。现在我有点困惑是回到使用uniforms还是在着色器中使用uniform块。
目前我正在学习OpenGL的曲面细分着色器.但是当涉及曲面细分评估着色器中的内置变量"gl_TessCoord"时,我无法理解它是如何计算的.
我知道当使用不同的镶嵌模式(四边形或三角形)时,"gl_TessCoord"是不同的.我检查了蓝皮书和红皮书,但他们只给出了一个粗略的解释,告诉它代表输入顶点的权重.有任何想法吗?
以下是矩形曲面细分的示例代码:
#version 430 core
layout ( quads) in;
void main( void)
{
// Interpolate along bottom edge using x component of the
// tessellation coordinate
vec4 p1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);
// Interpolate along top edge using x component of the
// tessellation coordinate
vec4 p2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, gl_TessCoord.x);
// Now interpolate those two results using the y component
// of tessellation coordinate
gl_Position = mix(p1, p2, gl_TessCoord.y);
}
Run Code Online (Sandbox Code Playgroud)
以下是三角形曲面细分的示例代码:
#version 430 core
layout ( triangles) in; …Run Code Online (Sandbox Code Playgroud) 这是为阴影映射设置帧缓冲区的代码,但在检查帧缓冲区状态时返回 36054。有任何想法吗?
//bind framebuffer for shadow mapping
gl.glGenFramebuffers(1, framebuff);
gl.glBindFramebuffer(GL4.GL_FRAMEBUFFER, framebuff.get(0));
gl.glGenTextures(1, textureBuff);
gl.glBindTexture(GL4.GL_TEXTURE_2D, textureBuff.get(0));
gl.glTexStorage2D(GL4.GL_TEXTURE_2D, 1, GL4.GL_DEPTH_COMPONENT32F, displayWidth, displayHeight);
gl.glTexParameteri(GL4.GL_TEXTURE_2D, GL4.GL_TEXTURE_MAG_FILTER, GL4.GL_LINEAR);
gl.glTexParameteri(GL4.GL_TEXTURE_2D, GL4.GL_TEXTURE_MIN_FILTER, GL4.GL_LINEAR);//GL_LINEAR_MIPMAP_LINEAR
gl.glTexParameteri(GL4.GL_TEXTURE_2D, GL4.GL_TEXTURE_WRAP_S, GL4.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL4.GL_TEXTURE_2D, GL4.GL_TEXTURE_WRAP_T, GL4.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL4.GL_TEXTURE_2D, GL4.GL_TEXTURE_COMPARE_MODE, GL4.GL_COMPARE_REF_TO_TEXTURE);
gl.glTexParameteri(GL4.GL_TEXTURE_2D, GL4.GL_TEXTURE_COMPARE_FUNC, GL4.GL_LEQUAL);
gl.glFramebufferTexture(GL4.GL_FRAMEBUFFER, GL4.GL_DEPTH_ATTACHMENT, textureBuff.get(0), 0);
gl.glDrawBuffer(GL4.GL_NONE);
if(gl.glCheckFramebufferStatus(GL4.GL_FRAMEBUFFER) != GL4.GL_FRAMEBUFFER_COMPLETE)
return gl.glCheckFramebufferStatus(GL4.GL_FRAMEBUFFER);
Run Code Online (Sandbox Code Playgroud) 我正在使用与SSAO绑定的计算着色器.我在计算着色器中使用以下结构:
struct Particle
{
vec4 pAnds;
vec3 velocity;
float lifespan;
float age;
};
layout (std430, binding = 0) buffer members_in
{
Particle particle[];
} input_data;
Run Code Online (Sandbox Code Playgroud)
但似乎为这些数据结构中的每一个分配的内存块不等于(4 + 3 + 1 + 1)*4.我还尝试了另一个:
struct Particle
{
vec4 pAnds;
vec3 velocity;
float lifespan;
};
Run Code Online (Sandbox Code Playgroud)
这次它工作得很好.我想知道如何使用std430限定符分配内存.如何使我的第一个数据结构像第二个一样工作?
更新:我将其更改为以下形式:
struct Particle
{
float px, py, pz, s;
float vx, vy, vz;
float lifespan;
float age;
};
Run Code Online (Sandbox Code Playgroud)
这次它工作正常,但我仍然不知道为什么使用vec4/vec3有问题.
我正在使用JavaFX创建一个简单的用户界面,其中使用了一些显示文本的标签.我尝试使用以下规则将文本移动到标签的中心:
-fx-text-alignment: center
Run Code Online (Sandbox Code Playgroud)
但它不起作用,默认情况下文本仍位于左侧.我还检查过我没有使用任何其他可以覆盖它的规则.有任何想法吗?这是css代码:
#subtitle
{
-fx-font: bold italic 18pt "Arial";
-fx-text-alignment: center;
-fx-effect: dropshadow( one-pass-box, black, 8, 0.0, 2, 0 );
-fx-text-fill: #1ebd1e;
}
Run Code Online (Sandbox Code Playgroud)
Java代码:
Label title = new Label("Trees");
title.setId("subtitle");
grid.add(title, 0, 0, 2, 1);
Run Code Online (Sandbox Code Playgroud)

我有一个 dotnet core gRPC 项目,我正在尝试在我的 proto 文件中包含路由注释,如下所示:
import "google/api/annotations.proto";
Run Code Online (Sandbox Code Playgroud)
文件结构是这样的(因为我将googleapis存储库作为 git 子模块导入):
protos/
myproto.proto
googleapis/
google/
api/
annotations.proto
...
Run Code Online (Sandbox Code Playgroud)
在 go 项目中,它可以通过以下方式完成:
protoc -I . -I ./googleapis --go_out=plugins=grpc:. *.proto
Run Code Online (Sandbox Code Playgroud)
where-I ./googleapis为编译器提供了可以找到annotations.proto文件及其依赖项的目录。
但是,当我使用如下配置在 dotnet grpc 项目中使用 MSBuild 时,我无法弄清楚如何包含自定义目录。
<ItemGroup>
<Protobuf Include="protos/*.proto" GrpcServices="Server" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
官方文档提到了自定义目标构建的替代方法,以便我可以使用protoc:
protoc --plugin=protoc-gen-grpc=$(gRPC_PluginFullPath) -I $(Protobuf_StandardImportsPath) ...
Run Code Online (Sandbox Code Playgroud)
但是上面的命令会忽略服务定义并且不会像这里提到的那样生成服务器存根代码,而 MSBuild 会。
我发现但不理想的解决方法:
我意识到Grpc.Toolsdotnet 包分发了一些常用的 proto 文件,所以我annotations.proto在那里(在 macOS 中)复制了它的依赖项并且它工作了:
`~\.nuget\packages\grpc.tools\2.25.0\build\native\include`
Run Code Online (Sandbox Code Playgroud)
更新:
另一种解决方法:
默认情况下包含项目根目录,因此将其用作基本路径并将导入的 proto 文件复制到那里也可以工作(更好但仍然不理想)。 …
我目前正在使用eclipse进行Java开发.在使用像FileReader这样的类时,有人能解释为什么文件放在src目录下的原因吗?有时在使用getClass()等方法时,必须将文件放在bin目录下.getResourceAsStream("...")用于读取图像?是否有任何替代方法getClass().getResourceAsStream("...")需要src目录下的文件?
opengl ×4
glsl ×3
java ×2
jogl ×2
.net-core ×1
grpc ×1
grpc-dotnet ×1
javafx ×1
javafx-css ×1
msbuild ×1