我到处寻找,但是没有ruby绑定可以创建OpenGL 3/4上下文.
它不必是完整的OpenGL绑定库,只是创建OpenGL上下文的部分.
更新:如果我非常绝望,我将使用ruby ffi进行部分glfw ruby绑定.所以请拯救我;)
在OpenGL中,为了获得适当的透明效果,我应该使用glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)但是使用混合函数时,alpha参数glClearColor变得毫无意义.当我在I中更改alpha参数时glClearColor仍然可以获得相同的效果.我什么时候可以使用alpha参数glClearColor?我能达到什么样的效果?
如何获取当前绑定的顶点数组对象的名称?
我查看了手册,但找不到与glGet()一起使用的枚举.
我没有在网上找到任何有效的更新资源并比较桌面版 OpenGL 的纹理压缩格式。一切要么已经过时,要么适合移动设备。
查看我的平台,我看到许多不同的格式:
GL_ARB_compressed_texture_pixel_storage
GL_ARB_texture_compression
GL_ARB_texture_compression_bptc
GL_ARB_texture_compression_rgtc
GL_EXT_texture_compression_dxt1
GL_EXT_texture_compression_latc
GL_EXT_texture_compression_rgtc
GL_EXT_texture_compression_s3tc
GL_NV_texture_compression_vtc
Run Code Online (Sandbox Code Playgroud)
如果我直接查询,我还有其他一些GL_COMPRESSED_TEXTURE_FORMATS
public static final int GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776;
public static final int GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 33778;
public static final int GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779;
public static final int GL_PALETTE4_RGB8_OES = 0x8B90 = 35728;
public static final int GL_PALETTE4_RGBA8_OES = 0x8B91;
public static final int GL_PALETTE4_R5_G6_B5_OES = 0x8B92;
public static final int GL_PALETTE4_RGBA4_OES = 0x8B93;
public static final int GL_PALETTE4_RGB5_A1_OES = 0x8B94;
public static final int GL_PALETTE8_RGB8_OES = 0x8B95; …Run Code Online (Sandbox Code Playgroud) 这是我的片段着色器:
#version 420 core
#extension GL_ARB_explicit_uniform_location : enable
#extension GL_ARB_shader_storage_buffer_object : require
layout(early_fragment_tests) in;
layout(binding = 4, offset = 0) uniform atomic_uint num_fragments;
// ...
void main(void)
{
atomicCounterIncrement(num_fragments);
frag_color = vec4(1.0, 0.0, 0.0, 0.0);
atomicAdd(...);
}
Run Code Online (Sandbox Code Playgroud)
我的三角形完全覆盖了屏幕。预期的行为是num_fragments等于像素数 (640*480 = 307200),这是单层三角形。但是,当我在现有三角形后面添加一个三角形时,num_fragments 会变成一个更高的值,就像正在为被遮挡的三角形执行片段着色器一样。
为什么是这样?我认为 early_fragment_tests 指令会阻止这种行为。这不仅仅是一种优化,因为着色器中有原子存储,应该只为未遮挡的像素运行。
我和一个朋友一直在讨论模板缓冲区.简而言之,我无法找到模板缓冲区比OpenGL 3.2+中的可编程管道工具更具优势的情况.现代OpenGL中的模板缓冲区有用吗?
[编辑]
感谢大家对该主题的所有意见.
从OpenGL文档:
dFdxFine和dFdyFine基于当前片段及其直接邻居的p值,使用本地差分计算导数.
dFdxCoarse和dFdyCoarse使用基于当前片段的邻居的p值的局部差分来计算导数,并且可能但不一定包括当前片段的值.也就是说,在给定区域内,实现可以计算比相应的dFdxFine和dFdyFine函数所允许的更少的唯一位置的导数.
他们之间有什么区别?我应该什么时候关心?
我知道两者都计算值的导数与窗口坐标有关,但我不理解用于计算它们的方法.
我猜它们都是用硬件实现的,但你能发布一个dFdx伪代码实现吗?
我一直在尝试编写一般的计算着色器高斯模糊实现.
它基本上可以工作,但它包含的工件即使在场景静止时也会改变每一帧.我花了几个小时试图调试这个.我已经走了尽可能确保不超出界限,展开所有循环,用常量替换制服,但工件仍然存在.
我已经在3个不同的机器/ GPU(2个nvidia,1个intel)上测试了原始代码和工件,它们都产生相同的结果.使用普通C++代码模拟执行向前和向后执行的工作组的代码执行的展开/常量版本不会产生这些错误.
通过分配[96] [96]而不是[16] [48]的共享数组,我可以消除大部分伪像.
这让我想到了我错过了一个逻辑错误,因此我设法生成了一个非常简单的着色器,它仍然会在较小的范围内产生错误,如果有人能指出原因,我会很感激.我检查了很多文档,找不到任何错误.
分配了一个16x48浮点数的共享数组,这是3072字节,大约是最小共享内存限制的10%.
着色器在16x16工作组中启动,因此每个线程将写入3个唯一位置,并从单个唯一位置读回
然后纹理作为HSV渲染,其中0-1之间的值将映射到色调0-360(红色 - 青色 - 红色),并且超出边界的值将是红色.
#version 430
//Execute in 16x16 sized thread blocks
layout(local_size_x=16,local_size_y=16) in;
uniform layout (r32f) restrict writeonly image2D _imageOut;
shared float hoz[16][48];
void main ()
{
//Init shared memory with a big out of bounds value we can identify
hoz[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = 20000.0f;
hoz[gl_LocalInvocationID.x][gl_LocalInvocationID.y+16] = 20000.0f;
hoz[gl_LocalInvocationID.x][gl_LocalInvocationID.y+32] = 20000.0f;
//Sync shared memory
memoryBarrierShared();
//Write the values we want to actually read back
hoz[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = 0.5f;
hoz[gl_LocalInvocationID.x][gl_LocalInvocationID.y+16] = 0.5f; …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的程序,将虚拟红色纹理映射到四边形.
这是C++中的纹理定义:
struct DummyRGB8Texture2d
{
uint8_t data[3*4];
int width;
int height;
};
DummyRGB8Texture2d myTexture
{
{
255,0,0,
255,0,0,
255,0,0,
255,0,0
},
2u,
2u
};
Run Code Online (Sandbox Code Playgroud)
这就是我设置纹理的方法:
void SetupTexture()
{
// allocate a texture on the default texture unit (GL_TEXTURE0):
GL_CHECK(glCreateTextures(GL_TEXTURE_2D, 1, &m_texture));
// allocate texture:
GL_CHECK(glTextureStorage2D(m_texture, 1, GL_RGB8, myTexture.width, myTexture.height));
GL_CHECK(glTextureParameteri(m_texture, GL_TEXTURE_WRAP_S, GL_REPEAT));
GL_CHECK(glTextureParameteri(m_texture, GL_TEXTURE_WRAP_T, GL_REPEAT));
GL_CHECK(glTextureParameteri(m_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
GL_CHECK(glTextureParameteri(m_texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
// tell the shader that the sampler2d uniform uses the default texture unit (GL_TEXTURE0)
GL_CHECK(glProgramUniform1i(m_program->Id(), /* location in shader …Run Code Online (Sandbox Code Playgroud) 我是OpenGl的专家,因此,我正在尝试仅学习4.x的现代OpenGl。一旦完成了基础教程(例如旋转多维数据集),我就决定尝试创建一个仅处理多维数据集的基于体素的程序。该程序的目标是快速,使用有限的CPU能力和内存以及动态的,因此映射大小可以更改,并且只有在数组中表示已填充块时才绘制块。
我有一个VBO,它具有由三角形构成的多维数据集的顶点和索引。首先,如果我告诉renderGl着色器使用render函数,然后在完成后绑定VBO,则执行此循环
绘制立方体循环:
//The letter_max are the dimensions of the matrix created to store the voxel status in
// The method I use for getting and setting entries in the map are very efficient so I have not included it in this example
for(int z = -(z_max / 2); z < z_max - (z_max / 2); z++)
{
for(int y = -(y_max / 2); y < y_max - (y_max / 2); y++)
{
for(int x = -(x_max / 2); x …Run Code Online (Sandbox Code Playgroud) opengl-4 ×10
opengl ×8
glsl ×5
opengl-3 ×3
graphics ×2
textures ×2
c ×1
compression ×1
format ×1
gpu ×1
optimization ×1
performance ×1
ruby ×1
shader ×1
vao ×1