当前位置: 编程技术>综合
本页文章导读:
▪为何要在GLSL中使用UBO 关于UBO的介绍和使用详情,请看http://www.zwqxin.com/archives/shaderglsl/communication-between-opengl-glsl-2.html
除了OpenGL手册,应该没有比这个更详细的了。
最近在一个GLSL项目中,需要循环绘制多块buffer,.........
▪android-我的百度地图研究 - 随心 1. 如何初始化百度地图
BMapManager mapManager = new BMapManager(getApplication());
//mStrKey为百度应用key
mapManager.init(mStrKey, null);
// 如果使用地图SDK,需要初始化地图Activity
super.initMapActivity(mapManager);
//开启.........
▪编程之美_001写一个函数,返回一个数组中所有元素被第一个元素除的结果 // 写一个函数,返回一个数组中所有元素被第一个元素除的结果
public class Test
{
public static void main(String[] args)
{
int[] arr1 =
{
0, 1, 3, 6, 7, 9, 2, 33, 22, 11
};
i.........
[1]为何要在GLSL中使用UBO
来源: 互联网 发布时间: 2013-11-07
关于UBO的介绍和使用详情,请看http://www.zwqxin.com/archives/shaderglsl/communication-between-opengl-glsl-2.html
除了OpenGL手册,应该没有比这个更详细的了。
最近在一个GLSL项目中,需要循环绘制多块buffer,而每次循环都要给buffer传入大量的uniform,导致shader的渲染效率极低。
比如之前的代码是类似这个样子:
m_pProgramBlock->sendUniform3fv(A); m_pProgramBlock->sendUniform3fv(B); m_pProgramBlock->sendUniform3fv(C); m_pProgramBlock->sendUniform3fv(D); glDrawElements(...);
相应的,在shader中uniform有如下定义:
#version 330 uniform vec3 A; uniform vec3 B; uniform vec3 C; uniform vec3 D;
结果在性能测试中发现,每执行一次sendUniform的操作耗费的时间居然大于执行一次glDrawElements的时间!
GLSL提供了UBO技术能很好的解决这个问题。通过把uniform绑定到显卡的缓冲区,可以极大提升修改Uniform数据的速度。
修改后的opengl代码是类似这个样子:
glBindBuffer(GL_UNIFORM_BUFFER, m_uboHandle); glBufferSubData(GL_UNIFORM_BUFFER, 0, 16, (char*)(&A); glBufferSubData(GL_UNIFORM_BUFFER, 16, 16, (char*)(&B); glBufferSubData(GL_UNIFORM_BUFFER, 32, 16, (char*)(&B); glBufferSubData(GL_UNIFORM_BUFFER, 48, 16, (char*)(&B); glDrawElements(...);
相应的,在shader中uniform有如下定义:
#version 330
layout(std140) uniform BlobSettings{
vec3 A;
vec3 B;
vec3 C;
vec3 D;
}Blob;
那么到底性能差异有多大呢?使用VS2012的性能测试,可以得到如下数据:
sendUniform占用了9.4%的渲染时间,而一条glBufferSubData只占用了0.1%!
使用glBufferSubData的效率比使用sendUniform高将近2个数量级!
然而使用UBO也要付出代价。因为每个显卡不同,UBO里每个uniform所占用字节数都未必相同,即使你指定了layout(std140)。
作者:lsldd 发表于2013-1-7 11:40:45 原文链接
阅读:16 评论:0 查看评论
[2]android-我的百度地图研究 - 随心
来源: 互联网 发布时间: 2013-11-07
1. 如何初始化百度地图
2. 开启百度地图的定位导航,共有两个方法
1)利用百度地图提供的MyLocationOverlay
2)利用百度地图提供的LocationListener进行监听我的位置的变化
3)百度画路线----待定
BMapManager mapManager = new BMapManager(getApplication()); //mStrKey为百度应用key mapManager.init(mStrKey, null); // 如果使用地图SDK,需要初始化地图Activity super.initMapActivity(mapManager); //开启百度地图API mapManager.start(); //mapView为百度地图控件MapView mapView.setBuiltInZoomControls(false); mapView.setClickable(true); mapView.setEnabled(true); // 得到MapController实例,该实例可以对百度地图进行相关功能的设置,如设置百度地图的放大级别、定位等 mapController = mapView.getController(); //设置显示百度地图的缩放级别 mapController.setZoom(15);// 最大18级,(15)
1)利用百度地图提供的MyLocationOverlay
// 添加定位图层 MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView); // 注册GPS位置更新的事件,让地图能实时显示当前位置 myLocationOverlay.enableMyLocation(); // 开启磁场感应传感器 myLocationOverlay.enableCompass(); mapView.getOverlays().add(myLocationOverlay);
MKLocationManager locationManager = mapManager.getLocationManager();
locationManager.requestLocationUpdates(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null) {
updateMyLoading(location.getLatitude(), location.getLongitude());
}
}
});
private void updateMyLoading(double latitude, double longitude){
List o = mapView.getOverlays();
final GeoPoint pt = new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6));
if (pt != null) {
o.remove(myOverItemT);
myOverItemT = getOverItemT(myLocation, pt);
o.add(myOverItemT);
mapView.invalidate();
}
}
public OverItemT getOverItemT(Drawable scenicIcon, GeoPoint geo){
//OverItemT该类我自个定义的,继承ItemizedOverlay,以来显示我的位置的点
OverItemT overLay = new OverItemT(scenicIcon, MapSearchActivity.this, geo, view, mapView);
return overLay;
}
作者:Super_Level 发表于2013-1-7 11:37:24 原文链接
阅读:0 评论:0 查看评论
[3]编程之美_001写一个函数,返回一个数组中所有元素被第一个元素除的结果
来源: 互联网 发布时间: 2013-11-07
// 写一个函数,返回一个数组中所有元素被第一个元素除的结果
public class Test
{
public static void main(String[] args)
{
int[] arr1 =
{
0, 1, 3, 6, 7, 9, 2, 33, 22, 11
};
int[] arr2 =
{
2, 1, 3, 6, 7, 9, 2, 33, 22, 11
};
for (int n : arr1)
{
System.out.print(n + " ");
}
System.out.println();
for (int n : arr2)
{
System.out.print(n + " ");
}
System.out.println("\n除数组中第一个数字后:");
divisor(arr1);
divisor(arr2);
for (int n : arr1)
{
System.out.print(n + " ");
}
System.out.println();
for (int n : arr2)
{
System.out.print(n + " ");
}
}
static void divisor(int[] arr)
{
if (arr[0] == 0)
{
System.out.println("arr[0] 不能为0.");
}
else
{
for (int i = 1, leng = arr.length - 1; i < leng; i++)
{
arr[i] = arr[i] / arr[0];
}
}
}
}
输出结果:
0 1 3 6 7 9 2 33 22 11 2 1 3 6 7 9 2 33 22 11 除数组中第一个数字后: arr[0] 不能为0. 0 1 3 6 7 9 2 33 22 11 2 0 1 3 3 4 1 16 11 11
作者:adam_zs 发表于2013-1-7 11:32:58 原文链接
阅读:0 评论:0 查看评论
最新技术文章: