本文整理汇总了C++中GLShader::Compile方法的典型用法代码示例。如果您正苦于以下问题:C++ GLShader::Compile方法的具体用法?C++ GLShader::Compile怎么用?C++ GLShader::Compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLShader
的用法示例。
在下文中一共展示了GLShader::Compile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitProgramWithShaders
/**
* Loads the vertex and fragment shader, compiles the program and returns a
* new and ready for use GLShader* object.
*/
GLShader* GLShader::InitProgramWithShaders(const std::string& vertexShaderFile
, const std::string& fragmentShaderFile)
{
GLShader* shader = new GLShader();
qui::VirtualFS fs;
cpp0x::shared_ptr<char> vertexFile = fs.GetFileContentsAsText(vertexShaderFile);
char *vertexShader = vertexFile.get();
if (vertexShader == NULL)
{
LOG(FATAL) << "Vertex Shader wasn't loaded!";
}
GLuint vsh = qui::GLShader::LoadShader(GL_VERTEX_SHADER, vertexShader);
cpp0x::shared_ptr<char> fragmentFile = fs.GetFileContentsAsText(fragmentShaderFile);
char *fragmentShader = fragmentFile.get();
if (fragmentShader == NULL)
{
LOG(FATAL) << "Fragment Shader wasn't loaded!";
}
GLuint fsh = qui::GLShader::LoadShader(GL_FRAGMENT_SHADER, fragmentShader);
shader->SetVertexShader(vsh);
shader->SetFragmentShader(fsh);
shader->CreateProgramAndAttachShaders();
shader->Compile();
return shader;
}
示例2: if
GLShader *GLProgramManager::CreateShader(const std::string &name) {
SPADES_MARK_FUNCTION();
SPLog("Loading GLSL shader '%s'", name.c_str());
std::string text = FileManager::ReadAllBytes(name.c_str());
GLShader::Type type;
if (name.find(".fs") != std::string::npos)
type = GLShader::FragmentShader;
else if (name.find(".vs") != std::string::npos)
type = GLShader::VertexShader;
else if (name.find(".gs") != std::string::npos)
type = GLShader::GeometryShader;
else
SPRaise("Failed to determine the type of a shader: %s", name.c_str());
GLShader *s = new GLShader(device, type);
std::string finalSource;
if (settings.r_hdr) {
finalSource += "#define USE_HDR 1\n";
finalSource += "#define LINEAR_FRAMEBUFFER 1\n";
} else {
finalSource += "#define USE_HDR 0\n";
finalSource += "#define LINEAR_FRAMEBUFFER 0\n";
}
if (settings.r_fogShadow) {
finalSource += "#define USE_VOLUMETRIC_FOG 1\n";
} else {
finalSource += "#define USE_VOLUMETRIC_FOG 0\n";
}
if (settings.r_ssao) {
finalSource += "#define USE_SSAO 1\n";
} else {
finalSource += "#define USE_SSAO 0\n";
}
finalSource += text;
s->AddSource(finalSource);
Stopwatch sw;
s->Compile();
SPLog("Successfully compiled GLSL program '%s' in %.3fms", name.c_str(), // should this be "program" or "shader"?
sw.GetTime() * 1000.);
return s;
}
示例3: if
GLShader *GLProgramManager::CreateShader(const std::string &name) {
SPADES_MARK_FUNCTION();
SPLog("Loading GLSL shader '%s'", name.c_str());
std::string text = FileManager::ReadAllBytes(name.c_str());
GLShader::Type type;
if(name.find(".fs") != std::string::npos)
type = GLShader::FragmentShader;
else if(name.find(".vs") != std::string::npos)
type = GLShader::VertexShader;
else
SPRaise("Failed to determine the type of a shader: %s",
name.c_str());
GLShader *s = new GLShader(device, type);
s->AddSource(text);
Stopwatch sw;
s->Compile();
SPLog("Successfully compiled GLSL program '%s' in %.3fms", name.c_str(),
sw.GetTime() * 1000.);
return s;
}
示例4: window
/*
GL interop test.
Julia.
*/
TEST(GLInteropTest, Julia)
{
try
{
const int width = 1280;
const int height = 720;
const int bufWidth = 1920;
const int bufHeight = 1080;
// ------------------------------------------------------------
GLTestWindow window(width, height, true);
GLContextParam param;
param.DebugMode = true;
param.Multisample = 8;
GLContext context(window.Handle(), param);
GLUtil::EnableDebugOutput(GLUtil::DebugOutputFrequencyLow);
// ------------------------------------------------------------
// Choose device
cudaDeviceProp prop;
memset(&prop, 0, sizeof(cudaDeviceProp));
prop.major = 2;
prop.minor = 0;
int devID;
HandleCudaError(cudaChooseDevice(&devID, &prop));
HandleCudaError(cudaGLSetGLDevice(devID));
// Get properties
HandleCudaError(cudaGetDeviceProperties(&prop, devID));
// Create texture and PBO
GLTexture2D texture;
texture.SetMagFilter(GL_LINEAR);
texture.SetMinFilter(GL_LINEAR);
texture.SetWrap(GL_CLAMP_TO_EDGE);
texture.Allocate(bufWidth, bufHeight, GL_RGBA8);
GLPixelUnpackBuffer pbo;
pbo.Allocate(bufWidth * bufHeight * 4, NULL, GL_DYNAMIC_DRAW);
// Register
cudaGraphicsResource* cudaPbo;
HandleCudaError(cudaGraphicsGLRegisterBuffer(&cudaPbo, pbo.ID(), cudaGraphicsMapFlagsWriteDiscard));
// ------------------------------------------------------------
GLShader shader;
shader.Compile("../resources/texturetest_simple2d.vert");
shader.Compile("../resources/texturetest_simple2d.frag");
shader.Link();
GLVertexArray vao;
GLVertexBuffer positionVbo;
GLIndexBuffer ibo;
glm::vec3 v[] =
{
glm::vec3( 1.0f, 1.0f, 0.0f),
glm::vec3(-1.0f, 1.0f, 0.0f),
glm::vec3(-1.0f, -1.0f, 0.0f),
glm::vec3( 1.0f, -1.0f, 0.0f)
};
GLuint i[] =
{
0, 1, 2,
2, 3, 0
};
positionVbo.AddStatic(12, &v[0].x);
vao.Add(GLDefaultVertexAttribute::Position, &positionVbo);
ibo.AddStatic(6, i);
// ------------------------------------------------------------
double fps = 0.0;
double timeSum = 0.0;
double prevTime = GLTestUtil::CurrentTimeMilli();
int frameCount = 0;
double start = GLTestUtil::CurrentTimeMilli();
float xcparam = -0.8f;
float ycparam = 0.165f;
float inc = 0.001f;
while (window.ProcessEvent())
{
// ------------------------------------------------------------
double currentTime = GLTestUtil::CurrentTimeMilli();
double elapsedTime = currentTime - prevTime;
//.........这里部分代码省略.........