本文整理汇总了C++中CreateShader函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateShader函数的具体用法?C++ CreateShader怎么用?C++ CreateShader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateShader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadShaders
void loadShaders() {
std::vector<GLuint> shaderList;
shaderList.push_back(CreateShader(GL_VERTEX_SHADER, SPED3_VertexShader));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, SPED3_FragmentShader));
shaderProgram = CreateProgram(shaderList);
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
projMatrixLoc = glGetUniformLocation(shaderProgram, "projMatrix");
rotMatrixLoc = glGetUniformLocation(shaderProgram, "rotMatrix");
//viewMatrixLoc = glGetUniformLocation(shaderProgram, "viewMatrix");
setIdentityMatrix(rotMatrix, 4);
rotMatrix[3*4+2] = 5.0f;
}
示例2: BTDebugDrawer
void RenderManager::Init()
{
if (!m_bulletDebugDrawer)
m_bulletDebugDrawer = new BTDebugDrawer();
glewInit();
//Create shaders and add to vector
std::vector<GLuint> shaderList;
shaderList.push_back(CreateShader(GL_VERTEX_SHADER, ReadFileToString("VertexShader.glsl")));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, ReadFileToString("FragmentShader.glsl")));
//Create program
m_program = CreateProgram(shaderList);
m_bulletDebugDrawer->SetProgram(m_program);
m_ui.m_openGLWidget->rm = this;
}
示例3: CreateEffect
//----------------------------------------------------------------------------
bool FxCompiler::CreateEffect (const Program& vProgram,
const Program& pProgram)
{
InputArray vInputs, pInputs;
OutputArray vOutputs, pOutputs;
ConstantArray vConstants, pConstants;
SamplerArray vSamplers, pSamplers;
if (!Process(vProgram, vInputs, vOutputs, vConstants, vSamplers))
{
return false;
}
if (!Process(pProgram, pInputs, pOutputs, pConstants, pSamplers))
{
return false;
}
mVShader = (VertexShader*)CreateShader(true, vProgram, vInputs, vOutputs,
vConstants, vSamplers);
mPShader = (PixelShader*)CreateShader(false, pProgram, pInputs, pOutputs,
pConstants, pSamplers);
VisualPass* pass = new0 VisualPass();
pass->SetVertexShader(mVShader);
pass->SetPixelShader(mPShader);
// TODO. Once Cg FX files are parsed, the global state from each pass
// should be set here. For now, the application is responsible for
// setting the global state after the *.wmfx file is loaded.
pass->SetAlphaState(new0 AlphaState());
pass->SetCullState(new0 CullState());
pass->SetDepthState(new0 DepthState());
pass->SetOffsetState(new0 OffsetState());
pass->SetStencilState(new0 StencilState());
pass->SetWireState(new0 WireState());
// TODO. Once Cg FX files are parsed, we might have multiple techniques
// or multiple passes per technique.
VisualTechnique* technique = new0 VisualTechnique();
technique->InsertPass(pass);
mEffect = new0 VisualEffect();
mEffect->InsertTechnique(technique);
return true;
}
示例4: SPADES_MARK_FUNCTION
GLProgram *GLProgramManager::CreateProgram(const std::string &name) {
SPADES_MARK_FUNCTION();
SPLog("Loading GLSL program '%s'", name.c_str());
std::string text = FileManager::ReadAllBytes(name.c_str());
std::vector<std::string> lines = SplitIntoLines(text);
GLProgram *p = new GLProgram(device, name);
for (size_t i = 0; i < lines.size(); i++) {
std::string text = TrimSpaces(lines[i]);
if (text.empty())
break;
if (text == "*shadow*") {
std::vector<GLShader *> shaders =
GLShadowShader::RegisterShader(this, settings, false);
for (size_t i = 0; i < shaders.size(); i++)
p->Attach(shaders[i]);
continue;
} else if (text == "*shadow-lite*") {
std::vector<GLShader *> shaders =
GLShadowShader::RegisterShader(this, settings, false, true);
for (size_t i = 0; i < shaders.size(); i++)
p->Attach(shaders[i]);
continue;
} else if (text == "*shadow-variance*") {
std::vector<GLShader *> shaders =
GLShadowShader::RegisterShader(this, settings, true);
for (size_t i = 0; i < shaders.size(); i++)
p->Attach(shaders[i]);
continue;
} else if (text == "*dlight*") {
std::vector<GLShader *> shaders = GLDynamicLightShader::RegisterShader(this);
for (size_t i = 0; i < shaders.size(); i++)
p->Attach(shaders[i]);
continue;
} else if (text == "*shadowmap*") {
std::vector<GLShader *> shaders = GLShadowMapShader::RegisterShader(this);
for (size_t i = 0; i < shaders.size(); i++)
p->Attach(shaders[i]);
continue;
} else if (text[0] == '*') {
SPRaise("Unknown special shader: %s", text.c_str());
} else if (text[0] == '#') {
continue;
}
GLShader *s = CreateShader(text);
p->Attach(s);
}
Stopwatch sw;
p->Link();
SPLog("Successfully linked GLSL program '%s' in %.3fms", name.c_str(),
sw.GetTime() * 1000.);
// p->Validate();
return p;
}
示例5: glut_viewer_load_program
GLhandleARB glut_viewer_load_program(char* vp, char* fp) {
GLhandleARB result ;
if(!CreateShader(vp, fp, &result)) {
std::cerr << "Could not create shader from " << vp << " and " << fp << std::endl ;
abort() ;
}
return result ;
}
示例6: CreateShader
Shader::Shader(const std::string& filename)
{
m_shaders[0] = CreateShader("./Res/Shaders/" + filename + ".vs", GL_VERTEX_SHADER); //Creates shader ID
m_shaders[1] = CreateShader("./Res/Shaders/" + filename + ".fs", GL_FRAGMENT_SHADER);
m_program = glCreateProgram();
glAttachShader(m_program, m_shaders[0]);
glAttachShader(m_program, m_shaders[1]);
glLinkProgram(m_program);
CheckShaderError(m_program, true, GL_LINK_STATUS, "Error: Program linking failed.");
glValidateProgram(m_program);
CheckShaderError(m_program, true, GL_VALIDATE_STATUS, "Error: Program validation failed.");
glUseProgram(m_program);
}
示例7: Init
void CUIStaticItem::Init(LPCSTR tex, LPCSTR sh, float left, float top, u32 align)
{
uFlags.set(flValidRect, FALSE);
CreateShader (tex,sh);
SetPos (left,top);
SetAlign (align);
}
示例8: LoadShader
bool cShader::BuildShader(const std::string& vs_filename, const std::string& ps_filename)
{
GLuint vs = LoadShader(vs_filename, GL_VERTEX_SHADER);
GLuint ps = LoadShader(ps_filename, GL_FRAGMENT_SHADER);
mProg = CreateShader(vs, ps);
return mProg != -1;
}
示例9: while
void cShaderManager::CreateProgramWithFile( const std::string ShaderName )
{
std::fstream File;
File.open( ShaderName, std::ios::in );
if( !File.is_open() )
{
std::cerr << "ERROR: Blad wczytywania shaderow z pliku: " << ShaderName << std::endl;
return;
}
std::string buffor;
std::string name;
std::vector< std::string > Shaders;
//std::vector< std::string > Fragment;
while( !File.eof() )
{
File >> buffor;
switch (buffor[0])
{
case 'v':
File >> buffor;
name = GetName( buffor );
Shaders.push_back( name );
CreateShader( name, SHADERTYPE::VertexShader, buffor );
break;
case 'f':
File >> buffor;
name = GetName( buffor );
Shaders.push_back( name );
CreateShader( name, SHADERTYPE::FragmentShader, buffor );
break;
default:
break;
}
}
File.close();
std::string ProgramName = GetName( ShaderName );
CreateProgram( ProgramName );
cProgramShader* Program = GetProgram( ProgramName );
for( unsigned i = 0; i < Shaders.size(); i++ )
{
Program->AttachShader( GetShader( Shaders[i] ) );
}
Program->Link();
}
示例10: WebGLContextBoundObject
WebGLShader::WebGLShader(WebGLContext* webgl, GLenum type)
: WebGLContextBoundObject(webgl)
, mGLName(CreateShader(webgl->GL(), type))
, mType(type)
, mTranslationSuccessful(false)
, mCompilationSuccessful(false)
{
mContext->mShaders.insertBack(this);
}
示例11: attach_shader
// Compiles a GL shader and attaches it to a program. Returns the shader ID if
// successful, or 0 if not.
static GrGLuint attach_shader(const GrGLContext& glCtx,
GrGLuint programId,
GrGLenum type,
const SkString& shaderSrc) {
const GrGLInterface* gli = glCtx.interface();
GrGLuint shaderId;
GR_GL_CALL_RET(gli, shaderId, CreateShader(type));
if (0 == shaderId) {
return 0;
}
const GrGLchar* sourceStr = shaderSrc.c_str();
GrGLint sourceLength = static_cast<GrGLint>(shaderSrc.size());
GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength));
GR_GL_CALL(gli, CompileShader(shaderId));
// Calling GetShaderiv in Chromium is quite expensive. Assume success in release builds.
bool checkCompiled = !glCtx.isChromium();
#ifdef SK_DEBUG
checkCompiled = true;
#endif
if (checkCompiled) {
GrGLint compiled = GR_GL_INIT_ZERO;
GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled));
if (!compiled) {
GrGLint infoLen = GR_GL_INIT_ZERO;
GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoLen));
SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
if (infoLen > 0) {
// retrieve length even though we don't need it to workaround bug in Chromium cmd
// buffer param validation.
GrGLsizei length = GR_GL_INIT_ZERO;
GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1,
&length, (char*)log.get()));
GrPrintf(shaderSrc.c_str());
GrPrintf("\n%s", log.get());
}
SkDEBUGFAIL("Shader compilation failed!");
GR_GL_CALL(gli, DeleteShader(shaderId));
return 0;
}
}
if (c_PrintShaders) {
GrPrintf(shaderSrc.c_str());
GrPrintf("\n");
}
// Attach the shader, but defer deletion until after we have linked the program.
// This works around a bug in the Android emulator's GLES2 wrapper which
// will immediately delete the shader object and free its memory even though it's
// attached to a program, which then causes glLinkProgram to fail.
GR_GL_CALL(gli, AttachShader(programId, shaderId));
return shaderId;
}
示例12: wmain
/*-------------------------------------------
main関数
--------------------------------------------*/
int wmain(int argc, WCHAR* argv[])
{
HRESULT hr;
// ロケールを設定
_wsetlocale(LC_ALL, L"Japanese");
// **********************************************************
// Direct3D11デバイスの作成
hr = CreateDevice();
// **********************************************************
// コンピュート・シェーダの作成
if (SUCCEEDED(hr))
hr = CreateShader();
// **********************************************************
// 定数バッファの作成
if (SUCCEEDED(hr))
hr = CreateCBuffer();
// **********************************************************
// リソースの作成
if (SUCCEEDED(hr))
hr = CreateResource();
// **********************************************************
// シェーダ リソース ビューの作成
if (SUCCEEDED(hr))
hr = CreateSRV();
// **********************************************************
// アンオーダード・アクセス・ビューの作成
if (SUCCEEDED(hr))
hr = CreateUAV();
// **********************************************************
// コンピュート・シェーダを使った演算
if (SUCCEEDED(hr))
ComputeShader();
// **********************************************************
// 開放
SAFE_RELEASE(g_pUAV[1]);
SAFE_RELEASE(g_pUAV[0]);
SAFE_RELEASE(g_pSRV[1]);
SAFE_RELEASE(g_pSRV[0]);
SAFE_RELEASE(g_pReadBackBuffer);
SAFE_RELEASE(g_pBuffer[1]);
SAFE_RELEASE(g_pBuffer[0]);
SAFE_RELEASE(g_pCBuffer);
SAFE_RELEASE(g_pComputeShader);
SAFE_RELEASE(g_pImmediateContext);
SAFE_RELEASE(g_pD3DDevice);
return 0;
}
示例13: CreateProgram
// Function to load both vertex and fragment shaders, and create the program
static GLuint CreateProgram(const char *vertex_shader_src, const char *fragment_shader_src)
{
GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER, vertex_shader_src);
if(!vertex_shader)
return 0;
GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER, fragment_shader_src);
if(!fragment_shader)
{
glDeleteShader(vertex_shader);
return 0;
}
GLuint program_object = glCreateProgram();
if(!program_object)
return 0;
glAttachShader(program_object, vertex_shader);
glAttachShader(program_object, fragment_shader);
// Link the program
glLinkProgram(program_object);
// Check the link status
GLint linked = 0;
glGetProgramiv(program_object, GL_LINK_STATUS, &linked);
if(!linked)
{
GLint info_len = 0;
glGetProgramiv(program_object, GL_INFO_LOG_LENGTH, &info_len);
if(info_len > 1)
{
char* info_log = (char *)malloc(info_len);
glGetProgramInfoLog(program_object, info_len, NULL, info_log);
// TODO(dspringer): We could really use a logging API.
printf("Error linking program:\n%s\n", info_log);
free(info_log);
}
glDeleteProgram(program_object);
return 0;
}
// Delete these here because they are attached to the program object.
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
return program_object;
}
示例14: FBXFile
AdvancedNav::AdvancedNav()
{
m_sponza = new FBXFile();
m_sponza->load("./Resources/SponzaSimple.fbx", FBXFile::UNITS_CENTIMETER);
CreateShader();
CreateBuffers();
}
示例15: m_name
ShaderStage::ShaderStage(const std::string& name, ShaderType type, U32 program)
: m_name(name)
, m_type(type)
, m_program(program)
, m_shader(0)
, m_source("")
{
ReadShaderSource(g_resourceCache.GetShadersPath() + name + s_GLSLExtensions[type]);
CreateShader();
}