OpenGL的Cg问题 [英] Cg problems with OpenGL

查看:154
本文介绍了OpenGL的Cg问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows上的OpenGL项目中进行工作,使用GLEW来提供所提供的Windows标头缺少的功能.为了支持着色器,我使用的是NVIDIA Cg.我阅读的所有文档和代码示例均表明以下是使用着色器加载的正确方法,并且我已在代码中以这种方式实现了这些事情:

I'm working on an OpenGL project on Windows, using GLEW to provide the functionality the provided Windows headers lack. For shader support, I'm using NVIDIA's Cg. All the documentation and code samples I have read indicate that the following is the correct method for loading an using shaders, and I've implemented things this way in my code:

  1. 使用cgCreateContext创建Cg上下文.
  2. 分别使用cgGLGetLatestProfileCG_GL_VERTEXCG_GL_FRAGMENT获取最新的顶点和像素着色器配置文件.使用cgGLSetContextOptimalOptions为两个配置文件创建最佳设置.
  3. 使用您编写的这些配置文件和着色器,使用cgCreateProgramFromFile创建着色器程序.
  4. 使用cgGLLoadProgram加载着色器程序.
  1. Create a Cg context with cgCreateContext.
  2. Get the latest vertex and pixel shader profiles using cgGLGetLatestProfile with CG_GL_VERTEX and CG_GL_FRAGMENT, respectively. Use cgGLSetContextOptimalOptions to create the optimal setup for both profiles.
  3. Using these profiles and shaders you have written, create shader programs using cgCreateProgramFromFile.
  4. Load the shader programs using cgGLLoadProgram.

然后,对于使用给定着色器的对象,每一帧:

Then, each frame, for an object that uses a given shader:

  1. 使用cgGLBindProgram绑定所需的着色器(顶点和/或像素).
  2. 使用cgGLEnableProfile为所需的着色器启用配置文件.
  3. 使用cgGetNamedParameter和各种参数设置功能检索并设置任何所需的统一着色器参数.
  4. 正常渲染对象
  5. 通过调用cgGLDisableProfile
  6. 清理着色器
  1. Bind the desired shader(s) (vertex and/or pixel) using cgGLBindProgram.
  2. Enable the profile(s) for the desired shader(s) using cgGLEnableProfile.
  3. Retrieve and set any needed uniform shader parameters using cgGetNamedParameter and the various parameter setting functions.
  4. Render your object normally
  5. Clean up the shader by calling cgGLDisableProfile

但是,事情开始变得奇怪.当使用单个着色器时,一切正常,但是用cgGLLoadProgram加载第二个着色器的行为似乎使使用第一个着色器的对象停止渲染.切换绘制顺序似乎可以解决问题,但这几乎不能解决.我和我的伴侣的笔记本电脑(相当早的带有Intel集成芯片组的计算机)上都出现了此问题.

However, things start getting strange. When using a single shader everything works just fine, but the act of loading a second shader with cgGLLoadProgram seems to make objects using the first one cease to render. Switching the draw order seems to resolve the issue, but that's hardly a fix. This problem occurs on both my and my partner's laptops (fairly recent machines with Intel integrated chipsets).

我使用GeForce GTX 260在台式机上测试了相同的代码,并且一切正常.由于笔记本电脑的GPU无法与Cg融为一体,所以我将其注销,但是我已经使用

I tested the same code on my desktop with a GeForce GTX 260, and everything worked fine. I would just write this off as my laptop GPU not getting along with Cg, but I've successfully built and run programs that use several Cg shaders simultaneously on my laptop using the OGRE graphics engine (unfortunately the assignment I'm currently working on is for a computer graphics class, so I can't just use OGRE).

总而言之,我很困惑. OGRE在做什么,我的代码却没有?我使用Cg的方式不正确吗?

In conclusion, I'm stumped. What is OGRE doing that my code is not? Am I using Cg improperly?

推荐答案

在致电cgGLBindProgram之前必须先致电cgGLEnableProfile.从您的问题来看,您似乎采取了另一种方法.

You have to call cgGLEnableProfile before you call cgGLBindProgram. From your question it appears you do it the other way around.

来自 cgGLBindProgram 的Cg文档:

From the Cg documentation for cgGLBindProgram:

cgGLBindProgram将程序绑定到当前状态.必须先用cgGLLoadProgram加载程序,然后才能进行绑定.另外,必须启用程序的配置文件才能使绑定起作用.这可以通过cgGLEnableProfile函数完成.

cgGLBindProgram binds a program to the current state. The program must have been loaded with cgGLLoadProgram before it can be bound. Also, the profile of the program must be enabled for the binding to work. This may be done with the cgGLEnableProfile function.

这篇关于OpenGL的Cg问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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