当前位置: 首页 > news >正文

glmark2代码阅读总结

glmark2代码阅读总结

一、总体

  1. 用输入参数生成testbench项
  2. 用scene和benchmark管理进行复用
  3. 通过类的重载,创建出不同的分支和具体的实现点,如scene和mainloop类
  4. 用例执行又规划,每个scene都统一有setup,等
  5. 使用scene的继承关系,整体的调用流程就比较简单,好组织

二、小技巧

一组字符串添加间隔方法

用一个static的变量控制第一个

std::string Values;
for (iterator It = Map.begin();It != Map.end();It++)
{static bool doSeparator(false);if (doSeparator){Values += ",";}const std::string& curName = It->first;Values += curName;doSeparator = true;
}

列出目录下的文件

只限于Linux下,用dirent.h头文件的目录操作函数:opendir、readdir 和 closedir。

#include <fstream>
#include <dirent.h>void
Util::list_files(const std::string& dirName, std::vector<std::string>& fileVec)
{DIR* dir = opendir(dirName.c_str());if (!dir){Log::error("Failed to open models directory '%s'\n", dirName.c_str());return;}struct dirent* entry = readdir(dir);while (entry){std::string pathname(dirName + "/");pathname += std::string(entry->d_name);// Skip '.' and '..'if (entry->d_name[0] != '.'){fileVec.push_back(pathname);}entry = readdir(dir);}closedir(dir);
}

字符串定义时截取

使用了std::string模板的特性,在定义字符串时,从原赋值字符串中取部分字串初始化。

string des(src, startPos, len);

表示des是src从startPos开始len长的字符串
类似的用法还有:

std::string s(n, 'x'); // 把s初始化为由连续n个字符x组成的串
string s(s2, pos); // s是string s2从下标pos开始的字符的拷贝

计算模型perspective参数的方法

/* Calculate a projection matrix that is a good fit for the model */
vec3 maxVec = model.maxVec();
vec3 minVec = model.minVec();
vec3 diffVec = maxVec - minVec;
centerVec_ = maxVec + minVec;
centerVec_ /= 2.0;
float diameter = diffVec.length();
radius_ = diameter / 2;
float fovy = 2.0 * atanf(radius_ / (2.0 + radius_));
fovy /= M_PI;
fovy *= 180.0;
float aspect(static_cast<float>(canvas_.width())/static_cast<float>(canvas_.height()));
perspective_.setIdentity();
perspective_ *= LibMatrix::Mat4::perspective(fovy, aspect, 2.0, 2.0 + diameter);

shader管理

shader是用了拼接的方式:
提供的shader中添加变量的方法:ShaderSource::add_const 函数,字符串操作,先生成变量的定义字符串,然后调用 ShaderSource::add 函数,这个函数中可以区分是否加到函数内还是函数外,函数内使用 ShaderSource::add_local, 函数外使用 ShaderSource::add_global。add_local:先找到对应函数名,换到 “{” 和 “\n” 之后插入要添加的定义字符串;add_global:先找到 “precious”所在行和 “\n”,在下面一行插入要添加的定义字符串,同时会检测 “#if” 和 “#endif” 对。

program管理

,过程比较明晰,阅读和书写方便:
Program::init createprogram对象
Program::addShader 加载并编译shader,在这里面都对 shader 的处理也都进行了友好的封装:valid发给发判断shader是否有效,erroMessage输出error log,compile进行编译,ready判断编译结果,attach将shader和program绑定。
所有shader对象存放在一个Shader的vector中,用push_back可以方便的管理。
program也包装了类似的接口:addShader、valid、ready、release
start:use program

mesh类型

convert_to_mesh
set_attrib_locations: 设置attrib_location
vbo_update_method
interleave
build_vbo
build_array

顶点数据的存放:next_vertex set_attrib set_vertex_format set_attrib_locations

http://www.lryc.cn/news/375299.html

相关文章:

  • 第 6 章 监控系统 | 监控套路 - 总结
  • VsCode中C文件调用其他C文件函数失败
  • css中content属性你了解多少?
  • JVM-GC-G1垃圾回收器
  • 【Ubuntu通用压力测试】Ubuntu16.04 CPU压力测试
  • Artix Linux 默认不使用 systemd
  • JVM-GC-CMS垃圾回收器
  • 【玩转google云】实战:如何在GKE上使用Helm安装和配置3节点的RabbitMQ集群
  • 【神经网络】深度神经网络
  • 机器学习算法 —— K近邻(KNN分类)
  • Thinkphp5内核流浪猫流浪狗宠物领养平台H5源码
  • c++ 智能指针使用注意事项及解决方案
  • SQLite Delete 语句
  • vue3的基本使用方法
  • Java数据结构与算法(盛水的容器贪心算法)
  • MYSQL 数字(Aggregate)函数
  • 【TensorFlow深度学习】如何处理不平衡数据集与欠采样、过采样技术
  • 【考研数学】如何保证进度不掉队?暑假强化保姆级规划
  • Vue3【二十一】Vue 路由模式(createWebHashHistory /createWebHistory )和RouterLink写法
  • 【交易策略】#22-24 残差资金流强度因子
  • CentOS 7.9检测硬盘坏区、实物定位(三)
  • redis持久化方式—RDB
  • java8实战1(让方法参数具备行为能力)
  • C#(C Sharp)学习笔记_多态【十九】
  • 电子竞赛1——基于DDS的AM信号发生器
  • CentOS7的#!bash #!/bin/bash #!/bin/env bash #!/usr/bin/bash #!/usr/bin/env bash
  • 代码随想录第四十一天打卡
  • 矩阵补全IGMC 学习笔记
  • 面试题之CSS
  • MFC扩展库BCGControlBar Pro v35.0新版亮点:重新设计的工具栏编辑器等