- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
所以我一直在尝试使用 OpenGL ES 2.0 创建拖尾粒子效果 ( seen here )。不幸的是,使这成为可能的 OpenGL 命令(累积缓冲区)似乎在 OpenGL es 中不可用。这意味着有必要走很长的路。
This主题描述了一种可能的方法来做这样的事情。但是,我对如何将内容存储在缓冲区中以及如何组合缓冲区感到很困惑。所以我的想法是执行以下操作。
到目前为止,我的理解是缓冲区以与纹理相同的方式存储像素数据,只是使用着色器可以更轻松地绘制缓冲区。
所以这个想法可能是渲染到缓冲区,然后将其移动到纹理中。
我发现的一个这样做的理论是
In retrospect, you should create two FBOs (each with its own texture); using the default framebuffer isn't reliable (the contents aren't guaranteed to be preserved between frames).
After binding the first FBO, clear it then render the scene normally. Once the scene has been rendered, use the texture as a source and render it to the second FBO with blending (the second FBO is never cleared). This will result in the second FBO containing a mix of the new scene and what was there before. Finally, the second FBO should be rendered directly to the window (this can be done by rendering a textured quad, similarly to the previous operation, or by using glBlitFramebuffer).
Essentially, the first FBO takes the place of the default framebuffer while the second FBO takes the place of the accumulation buffer.
In summary:
Initialisation:
For each FBO: - glGenTextures - glBindTexture - glTexImage2D - glBindFrameBuffer - glFramebufferTexture2D
Each frame:
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, fbo1) glClear glDraw* // scene
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, fbo2) glBindTexture(tex1) glEnable(GL_BLEND) glBlendFunc glDraw* // full-screen quad
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, 0) glBindFrameBuffer(GL_READ_FRAMEBUFFER, fbo2) glBlitFramebuffer
不幸的是它没有足够的代码(尤其是初始化让我开始)。
但我已经尝试过了,到目前为止我得到的只是一个令人失望的空白屏幕。我真的不知道我在做什么,所以这段代码可能是错误的。
var fbo1:GLuint = 0
var fbo2:GLuint = 0
var tex1:GLuint = 0
Init()
{
//...Loading shaders OpenGL etc.
//FBO 1
glGenFramebuffers(1, &fbo1)
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), fbo1)
//Create texture for shader output
glGenTextures(1, &tex1)
glBindTexture(GLenum(GL_TEXTURE_2D), tex1)
glTexImage2D(GLenum(GL_TEXTURE_2D), 0, GL_RGB, width, height, 0, GLenum(GL_RGB), GLenum(GL_UNSIGNED_BYTE), nil)
glFramebufferTexture2D(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_TEXTURE_2D), tex1, 0)
//FBO 2
glGenFramebuffers(1, &fbo2)
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), fbo2)
//Create texture for shader output
glGenTextures(1, &tex1)
glBindTexture(GLenum(GL_TEXTURE_2D), tex1)
glTexImage2D(GLenum(GL_TEXTURE_2D), 0, GL_RGB, width, height, 0, GLenum(GL_RGB), GLenum(GL_UNSIGNED_BYTE), nil)
glFramebufferTexture2D(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_TEXTURE_2D), tex1, 0)
}
func drawFullScreenTex()
{
glUseProgram(texShader)
let rect:[GLint] = [0, 0, GLint(width), GLint(height)]
glBindTexture(GLenum(GL_TEXTURE_2D), tex1)
//Texture is allready
glTexParameteriv(GLenum(GL_TEXTURE_2D), GLenum(GL_TEXTURE_CROP_RECT_OES), rect)
glDrawTexiOES(0, 0, 0, width, height)
}
fun draw()
{
//Prep
glBindFramebuffer(GLenum(GL_DRAW_FRAMEBUFFER), fbo1)
glClearColor(0, 0.1, 0, 1.0)
glClear(GLbitfield(GL_COLOR_BUFFER_BIT))
//1
glUseProgram(pointShader);
passTheStuff() //Just passes in uniforms
drawParticles(glGetUniformLocation(pointShader, "color"), size_loc: glGetUniformLocation(pointShader, "pointSize")) //Draws particles
//2
glBindFramebuffer(GLenum(GL_DRAW_FRAMEBUFFER), fbo2)
drawFullScreenTex()
//3
glBindFramebuffer(GLenum(GL_DRAW_FRAMEBUFFER), 0)
glBindFramebuffer(GLenum(GL_READ_FRAMEBUFFER), fbo2)
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GLbitfield(GL_COLOR_BUFFER_BIT), GLenum(GL_NEAREST))
}
顺便说一下,这里有一些我觉得有用的资源。
我的主要问题是:有人可以为此写出代码吗?我想我理解所涉及的理论,但我花了很多时间尝试应用它,但徒劳无功。
如果你想要一个起点,我有 Xcode project绘制点,并且有一个蓝色的点在屏幕上周期性地移动,而且不起作用的代码也在它们中。
注意:如果您要编写代码,您可以使用任何语言 c++、java、swift、objective-c,这将是完美的选择。只要是 OpenGL-ES 就可以
最佳答案
您使用相同的变量 tex1 调用了两次 glGenTextures(1, &tex1)
。这会覆盖变量。稍后调用 glBindTexture(GLenum(GL_TEXTURE_2D), tex1)
时,它不会绑定(bind) fbo1 对应的纹理,而是绑定(bind) fbo2 对应的纹理。每个 fbo 都需要不同的纹理。
作为引用,下面是我的一个工作程序的示例,它使用多个 FBO 并渲染到纹理。
GLuint fbo[n];
GLuint tex[n];
init() {
glGenFramebuffers(n, fbo);
glGenTextures(n, tex);
for (int i = 0; i < n; ++i) {
glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);
glBindTexture(GL_TEXTURE_2D, tex[i]);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex[i], 0);
}
}
render() {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[0]);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Draw scene into buffer 0
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, fbo[1]);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(cbo[0]);
//Draw full screen tex
...
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, 0);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(cbo[n - 1]);
// Draw to screen
return;
}
一些注意事项。为了让它工作,我必须添加纹理参数。
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
这是因为在我的系统上它们默认为 GL_NEAREST_MIPMAP_LINEAR。这对 FBO 纹理不起作用,因为没有生成 mipmap。将这些设置为您喜欢的任何内容。
此外,请确保您启用了纹理
glEnable(GL_TEXTURE_2D)
希望对您有所帮助。
关于ios - 如何在 OpenGL es 2.0 中模拟累积缓冲区(尾随粒子效应),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33975621/
美好的一天! 我正在制作一个出勤检查程序,单击一次时显示橙色按钮,单击两次时显示红色按钮,单击 3 次时显示黑色按钮。我在如何累积 getClickCount() 值方面遇到问题,因为对于按钮要注册
我似乎无法在 Adobe 网站上找到明确的答案。使用 ColdFusion 10,11 甚至 2016,更新(修补程序)是否累积? 例如,ColdFusion 的修补程序高达 hotfix_023
我是随机森林新手,我有一个关于回归的问题。我正在使用 R 包 randomForests 来计算 RF 模型。 我的最终目标是选择对预测连续性状很重要的变量集,因此我正在计算一个模型,然后删除准确度平
目前我们有一个发布/消费者服务,消费者将收到的消息写入 AWS S3。我们目前每月编写超过 100.000.000 个对象。但是,我们可以根据一些规则对这些消息进行分组,以节省一些钱。这些规则可以是这
假设我有一个二叉树: data BinTree a = Nil | Branch a (BinTree a) (BinTree a) 我想在这样的结构上做一个累积映射: mapAccum ::
我正在使用内核估计,我应用了 density函数从 R 到我的数据文件(双变量),经过几次统计处理后,我需要转换这些数据,这就是我的问题: 是否有非参数方法的逆累积分布函数? 我尝试过 Google、
不确定以前是否有人问过这个问题,尝试搜索它但找不到任何相关内容。 我试图获得一个累积的字符串聚合,即仅运行不同值的聚合。这是我正在寻找的结果的示例。 我尝试使用 string_agg 函数,但它仅在用
我想找到累积的 bind.rows。这是我想要实现的小例子。我将使用 dslabs 包中的 gapminder 数据集进行演示。 library(tidyverse) library(dslabs)
在 Linux 中使用 tomcat 进程时,我们观察到时间字段显示5506:34(累积 CPU 时间)。在探索时,这是在进程的整个生命周期中运行所花费的 CPU 时间的百分比。 由于这是一个 Jav
我有一些数据可以使用 pyparsing 中的 OneorMore 函数进行解析。比如, fun = OneorMore( foo.setResultsName("foo") + bar.setRe
我试图弄清楚是否有一种简单的方法可以解决 pandas 的以下问题。假设我有四个容器,A、B、C、D,每个容器都有特定的体积。假设我现在得到了一定量的液体,我想用它来填充这些容器。我怎样才能想出一个“
我正在尝试编写一个函数来检测所有上升沿 - 向量中值超过特定阈值的索引。这里描述了类似的东西:Python rising/falling edge oscilloscope-like trigger
这个问题在这里已经有了答案: Multiplying elements of a column in skipping an element after each iteration (3 个答案)
有没有办法获取数据框中每一行的值计数? |f1|f2| ------- v1 | a value_counts -> {a:1} v2 | a value_counts -> {a:2} v3 |
我目前正在尝试对我正在构建的计算器(使用复合模式)进行测试。第一种方法应该添加 75 美元,效果很好,但是当第二种方法运行时,“服务”被重置并且有0 美元作为工作成本。如果我将这两种方法合二为一,那么
我有一个如下所示的文档: 数据.txt 100, "some text" 101, "more text" 102, "even more text" 我使用正则表达式处理它并返回一个新的处理文档,如
假设我有这个: function getAllPromises(key: string, val: any): Promise { const subDeps = someHash[key]; c
我在 mysql 中有表“cumul_sum”,我想根据条件划分“cumulative”列,即如果此列中的值 >= 70,则这些值应存储在名为“others”的新列中"并且前面应该存放对应的sku_i
我正在做一个用 C++ 刺激 ATM 的项目,但在使用累加器时遇到了一些问题,我的问题是:我正在使用开关(这里是情况 1)来更改在包含的函数中声明的 2 个变量的值switch(),但是值只在情况 1
我希望能够使用 accumulate 对 vector 中的每隔一对元素进行累加。我尝试了以下但没有成功,为非空、非零 vector 返回错误 return std::accumulate(vec.b
我是一名优秀的程序员,十分优秀!