我正在完成一个波前对象解析器,我想用它来构造泛型网格对象.我的引擎使用OpenGL 4和着色器绘制引擎中的所有内容.
我的问题是如何确保渲染网格的最佳渲染效率.
甲波前obj文件通常具有指定的许多对象的子组.
可以为子组分配特定材料(例如闪亮的红色).
因此,网格可能是一个相当复杂的子组集合,每个子组都分配了自己的材料.
我的问题是 -
问:我是否需要单独绘制每个子组,例如每个子组调用glDrawElements?(所以,如果我有4个独立的子组,我必须进行四次glDrawElements调用,从而通过4次统一更改(对于材质/纹理)调用着色器4次)
glDrawElements( GL_TRIANGLES, nNumIndicesInGroup, GL_UNSIGNED_INT, ((char*)NULL)+ first-vertex-offset );
Run Code Online (Sandbox Code Playgroud)
如果这是正确的,那么我将不得不计算:
每个子组中的索引(表示每个子组的单独索引数组和VAO)子组开始的顶点偏移量
这看起来非常低效,我咆哮错了树吗?
另外,从Wavefront obj wiki页面:
Smooth shading across polygons is enabled by smoothing groups.
s 1
...
# Smooth shading can be disabled as well.
s off
...
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议平滑阴影值表示什么?例如s1,s2,s4等
我正在用c ++编写矩阵3x3类.
glm :: mat3通过[][] operator语法提供对矩阵数据的访问.
例如,myMatrix[0][0] = 1.0f; 将第一行,第一列输入设置为1.0f.
我想提供类似的访问权限.怎么能超载[][] operators?
我尝试了以下内容,但是我收到了错误:
必须将运算符名称声明为函数
const real operator[][](int row, int col) const
{
// should really throw an exception for out of bounds indices
return ((row >= 0 && row <= 2) && (col >= 0 && col <= 2)) ? _data[row][col] : 0.0f;
}
Run Code Online (Sandbox Code Playgroud)
重载此运算符的正确方法是什么?
我有一个字符串向量.我希望能够搜索该向量的字符串,如果我在向量中得到匹配,我希望能够返回位置,例如向量中项目的向量索引.
这是我试图解决问题的代码:
enum ActorType { at_none, at_plane, at_sphere, at_cylinder, at_cube, at_skybox, at_obj, at_numtypes };
class ActorTypes
{
private:
std::vector<std::string> _sActorTypes;
public:
ActorTypes()
{
// initializer lists don't work in vs2012 :/
using std::string;
_sActorTypes.push_back( string("plane") );
_sActorTypes.push_back( string("sphere") );
_sActorTypes.push_back( string("cylinder") );
_sActorTypes.push_back( string("cube") );
_sActorTypes.push_back( string("skybox") );
_sActorTypes.push_back( string("obj") );
}
const ActorType FindType( const std::string & s )
{
auto itr = std::find( _sActorTypes.cbegin(), _sActorTypes.cend(), s );
uint32_t nIndex = ???;
// I want to be able to …Run Code Online (Sandbox Code Playgroud) 我std::variate_generator在VS2010项目中使用了如下方式:
#include <random>
...
using std::variate_generator;
using std::mt19937;
using std::uniform_real_distribution;
typedef mt19937 Engine;
typedef uniform_real_distribution<float> Distribution;
typedef variate_generator< Engine, Distribution > Generator;
Generator r( Engine((DWORD)time(NULL)), Distribution(0.0f, 1.0f) );
// from now, calling float rnd = r() gave me a random number between 0.0f and 1.0f in rnd.
Run Code Online (Sandbox Code Playgroud)
我现在已将此代码放入 VS2012 解决方案中,我收到的错误消息是,它std::variate_generator不是std.
已std::variate_generator移动或已删除?
我正在尝试编译一个简单的 C++ 程序,该程序在 eclipse kepler/mingw 4.8.1 和 win32 上使用 std::thread。我希望在 Windows 开发多年后的某个时候将开发转移到 linux。
#include "test.h"
#include <thread>
#include <algorithm>
int main()
{
Test::CreateInstance();
std::thread(
[&]()
{
Test::I()->Output2();
}
);
Test::DestroyInstance();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
忽略测试的目的(它是一个单例,它只产生一些我将扩展的输出,一旦我让 std::thread 工作!)
我在 Eclipse 中设置的 g++ 编译器设置是:
-c -fmessage-length=0 -std=c++0x -Wc++0x-compat
Run Code Online (Sandbox Code Playgroud)
我定义的预处理器符号是:
__GXX_EXPERIMENTAL_CXX0X__
Run Code Online (Sandbox Code Playgroud)
建筑抱怨 std::thread 不是 std 的成员:
10:30:13 **** Incremental Build of configuration Debug for project test ****
Info: Internal Builder is used for build
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -Wc++0x-compat -o …Run Code Online (Sandbox Code Playgroud)