修改其值的最快方式:

创建:

Mutable Storage

To create mutable storage for a buffer object, you use this API:

void glBufferData​(enum target, sizeiptr size, const void *data, enum usage)

The target parameter is just like the one for glBindBuffer; it says which bound buffer to modify. size represents how many bytes you want to allocate in this buffer object.

The data parameter is a pointer to user memory that will be copied into the buffer object's data store. If this value is NULL, then no copying will occur, and the buffer object's data will be undefined.

The usage parameter can be very confusing.

修改:

glBufferSubData:

We have seen that glBufferData​ can be used to update the data in a buffer object. However, this also reallocates the buffer object's storage. This is not usually what one wants, as recreating the buffer can often be a heavyweight operation.

Instead, one can use the following API:

void glBufferSubData​(enum target, intptr offset, sizeiptr size, const void *data)

The offset parameter is an integer offset into the buffer object where we should begin updating. The size parameter is the number of bytes we should copy out ofdata. For obvious reasons, data cannot be NULL.

Modifiable buffers With Mapping VS glBufferSubData:

Generally speaking, mapping a buffer and writing to it will be equally as efficient as glBufferSubData​. And in most cases, it will be much faster, particularly if invalidation and other Buffer Object Streaming techniques are employed.

To cover this, flags​ should be set to GL_MAP_WRITE_BIT​. This lets the implementation know that you will not be using glBufferSubData​ at all.

glBufferSubData​ is a nice way to present data to a buffer object. But it can be wasteful in performance, depending on your use patterns.

For example, if you have an algorithm that generates data that you want to store in the buffer object, you must first allocate some temporary memory to store that data in. Then you can use glBufferSubData​ to transfer it to OpenGL's memory. Similarly, if you want to read data back, glGetBufferSubData​ is perhaps not what you need, though this is less likely. It would be really nice if you could just get a pointer to the buffer object's storage and write directly to it.

You can. To do this, you must map the buffer. This gives you a pointer to memory that you can write to or read from, theoretically, just like any other. When you unmap the buffer, this invalidates the pointer (don't use it again), and the buffer object will be updated with the changes you made to it.

Mapping a VBO Code:

	glBindBuffer(GL_ARRAY_BUFFER,mVBOtrackMidHandle[0]);
float * pMidPathVertex=(float * )glMapBuffer(GL_ARRAY_BUFFER,GL_WRITE_ONLY); for(int i=1;i<10;++i)
{
pMidPathVertex[i*12+7]=pMidPathVertex[(i-1)*12+4];
pMidPathVertex[i*12+10]=pMidPathVertex[(i-1)*12+1];
pMidPathVertex[i*12+4]=pMidPathVertex[i*12+7]-10;
pMidPathVertex[i*12+1]=pMidPathVertex[i*12+10]-10; } glUnmapBuffer(GL_ARRAY_BUFFER);

mapping weak:

Everything has a price. The price of this is that you must deal with the ordering of reads and writes. By mapping the buffer in this fashion, you are taking full responsibility for synchronizing mapped access operations with OpenGL (and with other direct uses of the API).

When you use a mapped pointer to write to a buffer, the data you write does not immediately become visible to OpenGL. It only becomes visible to OpenGL when you issue a glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT)​ call.

One thing to remember about buffer mapping is this: the implementation is not obligated in any way to give you an actual pointer to the buffer object's memory. It is perfectly capable of giving you a pointer to some memory that OpenGL allocated just for the purpose of mapping, then it will do the copy on its own time.

If you are attempting to stream data to the buffer, you should always map the buffer only for writing and you should write sequentially. You do not need to write every byte, but you should avoid going backwards or skipping around in the memory.

Problem:Buffer Object Streaming

OpenGL puts in place all the guarantees to make this process work, but making it work fast is the real problem. The biggest danger in streaming, the one that causes the most problems, is implicit synchronization.

The OpenGL specification permits an implementation to delay the execution of drawing commands. This allows you to draw a lot of stuff, and then let OpenGL handle things on its own time. Because of this, it is entirely possible that, well after you call whatever operation that uses the buffer object, you might start trying to upload new data to that buffer. If this happens, the OpenGL specification requires that the thread halt until all drawing commands that could be affected by your update of the buffer object complete.

This implicit synchronization is the primary enemy when streaming vertex data.

There are a number of strategies to solve this problem. Some implementations work better with certain ones than others. Each one has its benefits and drawbacks.

试验:定点数组大小,sizeof(float)*3*4*100*100*300, 共100*100*300个面片 GT755m,此时GPU和CPU处理数据的时间基本相同。

但是 经过试验后 发现如果需要替换全部数据glBufferData与glBufferSubData效率基本相同,可能是因为CPU与GPU本身存在并行的时候 使得glBufferData(Null)所体现的GPU并行数据方面无效。大概80ms左右

glMapBuffer()会非常慢 竟然需要1300ms 是前者的15倍,分析后 发现 glMapBuffer后获得GPU的指针,然后直接对其操作 ,这种行为会导致GPU进行synchronization, 而本身又是使CPU对GPU的直接操作,从而使CPU和GPU的同步,因此效率很低。

而避免synchronization的方法 使用glBufferData(Null)和glMapBufferRange(),使用glBufferData(Null)后则没有效果(是数据大小不够典型?),而glMapBufferRange()待续。。

glsl-BufferObject- change的更多相关文章

  1. 使用Visual Studio SDK制作GLSL词法着色插件

    使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...

  2. 基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#)

    基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#) 为了完美解析GLSL源码,获取其中的信息(都有哪些in/out/uniform等),我决定做个GLSL编译器的前端(以后简称编译器或 ...

  3. CSharpGL(39)GLSL光照示例:鼠标拖动太阳(光源)观察平行光的漫反射和镜面反射效果

    CSharpGL(39)GLSL光照示例:鼠标拖动太阳(光源)观察平行光的漫反射和镜面反射效果 开始 一图抵千言.首先来看鼠标拖动太阳(光源)的情形. 然后是鼠标拖拽旋转模型的情形. 然后我们移动摄像 ...

  4. CSharpGL(15)用GLSL渲染2种类型的文字

    CSharpGL(15)用GLSL渲染2种类型的文字 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立的Demo,更适合 ...

  5. CSharpGL(13)用GLSL实现点光源(point light)和平行光源(directional light)的漫反射(diffuse reflection)

    CSharpGL(13)用GLSL实现点光源(point light)和平行光源(directional light)的漫反射(diffuse reflection) 2016-08-13 由于CSh ...

  6. CSharpGL(11)用C#直接编写GLSL程序

    CSharpGL(11)用C#直接编写GLSL程序 +BIT祝威+悄悄在此留下版了个权的信息说: 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharp ...

  7. 代码的坏味道(10)——发散式变化(Divergent Change)

    坏味道--发散式变化(Divergent Change) 发散式变化(Divergent Change) 类似于 霰弹式修改(Shotgun Surgery) ,但实际上完全不同.发散式变化(Dive ...

  8. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  9. input事件与change事件

    输入框的change事件: 必须等到输入框失去焦点的时候才会触发,鼠标在空白的地方点一下: 输入框的input事件: 在输入内容变化的同时,实时的触发,不需要等到失去焦点.

  10. Change the Target Recovery Time of a Database (SQL Server) 间接-checkpoints flushcache flushcache-message

    Change the Target Recovery Time of a Database (SQL Server) 间接checkpoints   flushcache flushcache-mes ...

随机推荐

  1. VIM 及正则表达式

    VIM及正则表达式 一.查找/Search + 统计 1.统计某个关键字 方法是:%s:keyword:&:gn. 其中,keyword是要搜索的关键字,&表示前面匹配的字符串,n表示 ...

  2. JPA的泛型DAO设计及使用

    使用如Hibernate或者JPA作为持久化的解决方案时,设计一个泛型的DAO抽象父类可以方便各个实体的通用CRUD操作.由于此时大部分实体DAO的CRUD操作基本一样,采用泛型设计解决这个问题,带来 ...

  3. ASP.NET数据绑定控件

    数据绑定控件简介 数据绑定分为:数据源 和 数据绑定控件 两部分,数据绑定控件通过数据源来获得数据,通过数据源来隔离数据提供者和数据使用者,数据源有:SqlDataSource,AccessDataS ...

  4. Fedora 21 安装QQ国际版

    首先安装依赖包 sudo yum install freetype.i686 libpng.i686 libgcc.i686 libXau.i686 点击下载wine-2012qq国际版 unzip ...

  5. js在php 中出现 unterminated string literal 解决方法

    出现这个问题就是空格造成的(可清空格符,换行符等) 示例代码如下: php 下报错 <?php echo "<a href=javascript:if(window.confir ...

  6. Swift语言 1小时速学教程

    本文由 张渊杰 (网名寂静)编写 Swift语言 1小时速学教程 写在前面的话 有些人可能想, 呵呵, 1小时学一门语言, 你不是搞笑吧, 我想说, 是的, 完全可以, 就要看你怎么学了 要想在1小时 ...

  7. maya2105 - windows8 - numpy/scipy

    To compile numpy, create a site.cfg file in numpy's source directory with the following or similar c ...

  8. 2014年度辛星html教程夏季版第二节

    上面一节中我们介绍了HTML文件的书写和几个标签,接下来我们来认识几个其他的标签,这里我们主要介绍一下head标签和文本标签. ***************head标签*************** ...

  9. 从IT的角度思考BIM(三):敏捷开发

    人们看到了远处BIM的美丽胜景和阻挡在眼前的宽广河流.有些人自信满满地跳入河中打算孤身游过彼岸,可是却失败了.有些人匆匆忙忙地造了船胡乱地滑向彼岸,可是也失败了. 要如何继续这段探索之旅? 无论是&l ...

  10. 毕向东_Java基础视频教程第19天_IO流(06~10)

    第19天-06-IO流(装饰设计模式) 装饰设计模式: 当想要对已有的对象进行功能增强时, 可以定义类,将已有对象传入,基于已有的功能,并提供加强功能.那么这个自定义的类称为装饰类. 装饰类通常会通过 ...