glsl-VBO- change

修改其值的最快方式:

创建:

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.

glsl-VBO- change,布布扣,bubuko.com

时间: 2024-08-06 07:13:37

glsl-VBO- change的相关文章

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

CSharpGL(15)用GLSL渲染2种类型的文字 下载 这个示例是CSharpGL的一部分,CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入(https://github.com/bitzhuwei/CSharpGL) 血条 玩家头顶的血条.名字随着玩家在3D世界移动,但始终朝向摄像机,且在屏幕上的大小不变. 始终朝向camera 如何使模型始终朝向camera? 对模型进行坐标变换,使模型的顶点坐标从物体坐标系变换到世界坐标系再到屏幕坐标系.这过程需要三个矩阵. 1

C#+OpenGL+FreeType显示3D文字(3) - 用PointSprite绘制文字

C#+OpenGL+FreeType显示3D文字(3) - 用PointSprite绘制文字 上一篇实现了把文字绘制到OpenGL窗口,但实质上只是把含有文字的贴图贴到矩形模型上.本篇我们介绍用PointSprite绘制文字,这可以只用1个点绘制文字,并确保文字始终面相窗口.用PointSprite绘制的文字,其大小范围有限,本篇提供的Demo中,Max Row Width最大只有256.现在能够绘制少量的文字,为其指定的位置的过程与为一个点指定位置的过程是相同的,所以此方式的应用范围还是比较广

OpenGL 4.0 GLSL 基础教程概览——VAO和VBO常用操作接口

OpenGL  4.3 最新渲染管线图 从OpenGL 2.0 到 OpenGL 3.0变化非常大,但从OpenGL 3.0 到OpenGL 4.0 变化不是太大. 着色器程序直接运行在GPU上,并且是并行的,一个片元着色器可能一次执行所有象素. deprecation model, 在OpenGL3.0 提出,为了保持向后兼容,兼容模式compatibility profile.和核心模式core profile的概念在OpenGL 3.2 中提出. 在Qt 4.7以后版本,可以通过下列方式选

第4章:缓冲区、着色器、GLSL

原文链接: http://www.rastertek.com/gl40tut04.html Tutorial 4: Buffers, Shaders, and GLSL This tutorial will be the introduction to writing vertex and pixel shaders in OpenGL 4.0. It will also be the introduction to using vertex and index buffers in OpenG

OpenGL顶点缓冲区对象(VBO)

转载 http://blog.csdn.net/dreamcs/article/details/7702701 创建VBO        GL_ARB_vertex_buffer_object 扩展可以提升OpenGL的性能.它提供了顶点数组和显示列表,这避免了低效实现这些功能.Vertex buffer object (VBO) 允许顶点数据储存在高性能显卡上,即服务端的内存中,改善数据传输效率.如果缓冲区对象保存了像素数据,它就被称做Pixel Buffer Object (PBO). 使用

Modern OpenGL用Shader拾取VBO内单一图元的思路和实现(2)

Modern OpenGL用Shader拾取VBO内单一图元的思路和实现(2) 上一篇里介绍了Color-Coded Picking的思路和最基本的实现.在处理GL_POINTS时已经没有问题,但是处理GL_LINES.GL_TRIANGLES等时会遇到同一图元的各个顶点颜色不同的问题,这就不能正确拾取了,本问来解决这个问题. 对于GL_LINES,可以用 int objectID = gl_VertexID / 2; 来使得每个线段图元的两个顶点颜色分别相同:对于GL_TRIANGLES,则用

Modern OpenGL用Shader拾取VBO内单一图元的思路和实现

Modern OpenGL用Shader拾取VBO内单一图元的思路和实现 什么意思? 拾取 最简单的理解拾取的方式大概是到(http://www.yakergong.net/nehe/course/tutorial_32.html)玩一下NEHE的拾取游戏.用鼠标点击飞过屏幕的物体就会击中它,这就是拾取的意义. Legacy OpenGL VS Modern OpenGL Legacy OpenGL就是使用glTranslate.glRotate.glScale.gluLookAt.glPers

OpenGL入门4:着色器 GLSL

本文是个人学习记录,非原创,学习建议看教程 https://learnopengl-cn.github.io/ 非常感谢原作者JoeyDeVries和多为中文翻译者提供的优质教程 近况 在家呆久了真的是咸 前几天检查出下巴骨头出问题了,没什么治疗手段,有点难受,但也想开了 前言 经过之前一段时间的学习(渲染管线简介)我们已经知道了着色器(Shader)是运行在GPU上的小程序,这些小程序为图形渲染管线的某个特定部分而运行,着色器只是一种把输入转化为输出的程序,着色器也是一种非常独立的程序,因为它

centos yum安装ftp 及解决vsftp错误500 OOPS: cannot change directory:/home/**

centos yum安装ftp 及解决vsftp错误500 OOPS: cannot changedirectory:/home/**   1.查看服务器有没有安装ftp包 rpm -qa |grep vsftp 2.yum  安装 yum -y install vsftpd 3.启动vsftp的服务 service vsftpd start 4.关闭防火墙 service iptables stop 5.测试匿名访问 修改配置文件 vsftpd.conf [[email protected]

How to change SMTP Banner, HELO,EHLO Greetings for Zimbra

1- Take Zimbra backup or VM snapshot before doing any changes 2- Enter the following command to change SMTP Banner: # su - zimbra $ zmlocalconfig -e postfix_smtpd_banner="yourmailserver.yourdomain.com" 3- Then if you want to change HELO/EHLO nam