使用模板管理glUniform功能 [英] Using templates to manage glUniform functions

查看:70
本文介绍了使用模板管理glUniform功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次问好,欢迎来到另一个如果我们把我真的不了解的两件事结合在一起,那不是很好吗?"问题;)

Hi again and welcome to another 'wouldn't it be great if we'd combine two things that i really don't understand anything about'-question ;)

本集:OpenGL制服和c ++模板

This Episode: OpenGL Uniforms and c++ Templates

想法:如果您可以编写一个模板函数来在OpenGL着色器中设置制服,那岂不是很棒吗?

The Idea: Wouldn't it be great if you could write a single template function to set uniforms in an OpenGL shader?

问题:使用许多glUniform *函数设置着色器中的均匀度.这些区别在于:

The Problem: Uniforms in shaders are set using a number of glUniform* functions. These differ in:

  1. 类型:制服可以采用多种类型.这样会在OpenGL中产生不同的函数名称,如下所示:glUniform1f,glUniform1i,glUniform1fv等.

  1. Type: there are several types a uniform can take. This results in different function names in OpenGL looking like: glUniform1f, glUniform1i, glUniform1fv, etc.

使用函数重载可以很容易地将它们统一".但这会导致大量类似的功能.

These could easily be 'unified' using overloading of functions. But this results in a huge amount of similiar functions.

第一个问题:可以在这个地方使用模板吗?据我了解模板,您将必须专门研究每个新功能.最后,您将拥有与简单重载相同的功能.

First question: is it possible to use templates in this place? As far as i understand templates you would have to specialize for every new function. And in the end you'd have the same amount of functions like with simple overloading.

参数计数:glUniform函数中的数字是指给定参数的数字.有1到4个参数与简单值相关,直到具有4个元素的矢量.

Parameter Count: The number in glUniform functions referes to the number the given parameters. There are one to 4 parameters which relates to simple values up to vectors with 4 elements.

第二个问题:是否可以通过模板实现动态"参数计数?

Second question: is it possible to implement a 'dynamic' parameter count with templates?

矩阵:为了使事情变得复杂,还有另一类发送矩阵的统一函数,但是由于我并不真正使用它们,所以我对它们并不感兴趣.

Matrices: To make things complicated there is another class of uniform functions which send matrices but as I am not really using these I am not really interested in them.

可能没有真正的方法可以简化统一方法...但是也许有人可以使用强大的模板提出一个很好的解决方案?

Possibly there is no real way to simplify uniform methods ... but maybe someone can come up with a great solution using mighty templates?

亲切的问候, 弗洛里安

Kind regards, Florian

推荐答案

1:是的,是的,但是至少当编译器抱怨它无法在float和double重载之间进行选择时,您可以非常简单地强迫他,即setUniform<float>(blah)而不是setUniform(blah)

1 : Yes, and yes, but at least when the compiler complains that it can't choose between float and double overloads, you can force him very simply, ie setUniform<float>(blah) instead of setUniform(blah)

2:这一次重载是一个更简单的解决方案:)

2 : This time overloading is a simpler solution :)

3:问题是什么?

问题是,您为什么要做这样的事情?

The question is, why would you want to do such a thing ?

这篇关于使用模板管理glUniform功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆