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; }
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; }
//---------------------------------------------------------------------------- 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; }
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; }
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 ; }
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); }
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); }
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; }
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(); }
WebGLShader::WebGLShader(WebGLContext* webgl, GLenum type) : WebGLContextBoundObject(webgl) , mGLName(CreateShader(webgl->GL(), type)) , mType(type) , mTranslationSuccessful(false) , mCompilationSuccessful(false) { mContext->mShaders.insertBack(this); }
// 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; }
/*------------------------------------------- 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; }
// 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; }
AdvancedNav::AdvancedNav() { m_sponza = new FBXFile(); m_sponza->load("./Resources/SponzaSimple.fbx", FBXFile::UNITS_CENTIMETER); CreateShader(); CreateBuffers(); }
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(); }
Shader::Shader(const std::string& fileName) { m_program = glCreateProgram(); m_shaders[0] = CreateShader(LoadShader(fileName + ".vs"), GL_VERTEX_SHADER); m_shaders[1] = CreateShader(LoadShader(fileName + ".fs"), GL_FRAGMENT_SHADER); for(unsigned int i = 0; i < NUM_SHADERS; i++) glAttachShader(m_program, m_shaders[i]); glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); glValidateProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Invalid shader program"); m_uniforms[0] = glGetUniformLocation(m_program, "MVP"); m_uniforms[1] = glGetUniformLocation(m_program, "Normal"); m_uniforms[2] = glGetUniformLocation(m_program, "lightDirection"); }
Shader::Shader(const std::string& fileName) { m_program = glCreateProgram(); m_shaders[0] = CreateShader(LoadShader((fileName + ".vs")), GL_VERTEX_SHADER); m_shaders[1] = CreateShader(LoadShader((fileName + ".fs")), GL_FRAGMENT_SHADER); for(unsigned int i = 0; i < NUM_SHADERS; ++i) { glAttachShader(m_program, m_shaders[i]); } glBindAttribLocation(m_program, 0, "position"); glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Error: Program linking failed: "); glValidateProgram(m_program); CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Error: Program is invalid: "); }
Shader::Shader(const std::string& fileName) { m_program = glCreateProgram(); m_shaders[0] = CreateShader(LoadShader(fileName + ".vsh"), GL_VERTEX_SHADER); m_shaders[1] = CreateShader(LoadShader(fileName + ".fsh"), GL_FRAGMENT_SHADER); for (unsigned int i = 0; i < NUM_SHADERS; i++) glAttachShader(m_program, m_shaders[i]); glBindAttribLocation(m_program, 0, "position"); glBindAttribLocation(m_program, 1, "texCoord"); glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); glValidateProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Invalid shader program"); m_uniforms[TRANSFORM_U] = glGetUniformLocation(m_program, "transform"); }
void GLComputeShader::loadShader(const std::string & fileName) { m_program = glCreateProgram(); GLuint m_shader = CreateShader(LoadShader(fileName + ".compute.glsl"), GL_COMPUTE_SHADER); glAttachShader(m_program, m_shader); glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true); }
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); glLinkProgram(program_object); 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); weston_log("\tError linking program:\n\t%s\n", info_log); free(info_log); } glDeleteProgram(program_object); return 0; } glDeleteShader(vertex_shader); glDeleteShader(fragment_shader); return program_object; }
clRenderState* clResourcesManager::CreateCustomShader( const LString& ShaderProgramName, const LString& DefinesList ) const { clRenderState* Shader = CreateShader(); Shader->FDepthTest = false; Shader->FDepthWrites = false; Shader->SetShaderProgram( Env->Resources->LoadSP( ShaderProgramName, DefinesList ) ); return Shader; }
void Shader::init(const std::string& fileName){ m_program = glCreateProgram(); m_shaders[0] = CreateShader(LoadShader(fileName + ".vs"), GL_VERTEX_SHADER); m_shaders[1] = CreateShader(LoadShader(fileName + ".fs"), GL_FRAGMENT_SHADER); for(unsigned int i = 0; i < NUM_SHADERS; i++) glAttachShader(m_program, m_shaders[i]); //this maps the variavles in the vertex shader to the //data in functions out glBindAttribLocation(m_program, 0, "position"); glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); glValidateProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Invalid shader program"); m_uniforms[TRANSFORM_U] = glGetUniformLocation(m_program, "transform"); m_uniforms[COLOR_U] = glGetUniformLocation(m_program, "color"); }//end func
// // Create Shader Program // int CreateShaderProg(const char* VertFile,const char* FragFile, char ** arrayAttributes) { // Create program int prog = glCreateProgram(); // Create and compile vertex shader if (VertFile) CreateShader(prog,GL_VERTEX_SHADER,VertFile); // Create and compile fragment shader if (FragFile) CreateShader(prog,GL_FRAGMENT_SHADER,FragFile); if(arrayAttributes){ int k; for ( k=0;arrayAttributes[k];k++) if (arrayAttributes[k][0]) glBindAttribLocation(prog,k,arrayAttributes[k]); } // Link program glLinkProgram(prog); // Check for errors PrintProgramLog(prog); // Return name return prog; }
bool Shader::InitializeFromFile(const char* vertFilename, const char* fragFilename) { //std::cout << "Compiling shaders: " << vertFilename << " | " << fragFilename << std::endl; m_vertex = LoadShaderFromFile(vertFilename, GL_VERTEX_SHADER); m_fragment = LoadShaderFromFile(fragFilename, GL_FRAGMENT_SHADER); if(m_vertex == -1 || m_fragment == -1) return false; return CreateShader(); }
void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb) { auto i = std::as_const(m_vs).find(sel); if(i == m_vs.end()) { std::string str[3]; str[0] = format("%d", sel.bppz); str[1] = format("%d", sel.tme); str[2] = format("%d", sel.fst); D3D_SHADER_MACRO macro[] = { {"VS_BPPZ", str[0].c_str()}, {"VS_TME", str[1].c_str()}, {"VS_FST", str[2].c_str()}, {NULL, NULL}, }; D3D11_INPUT_ELEMENT_DESC layout[] = { {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"POSITION", 0, DXGI_FORMAT_R16G16_UINT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"POSITION", 1, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 2, DXGI_FORMAT_R16G16_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0}, }; GSVertexShader11 vs; std::vector<char> shader; theApp.LoadResource(IDR_TFX_FX, shader); CreateShader(shader, "tfx.fx", nullptr, "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); m_vs[sel] = vs; i = m_vs.find(sel); } if(m_vs_cb_cache.Update(cb)) { ID3D11DeviceContext* ctx = m_ctx; ctx->UpdateSubresource(m_vs_cb, 0, NULL, cb, 0, 0); } VSSetShader(i->second.vs, m_vs_cb); IASetInputLayout(i->second.il); }
GLShader::GLShader(const std::string& fileName) { //create program m_program = glCreateProgram(); m_shaders[0] = CreateShader(LoadShader(fileName + ".vert.glsl"), GL_VERTEX_SHADER); m_shaders[1] = CreateShader(LoadShader(fileName + ".frag.glsl"), GL_FRAGMENT_SHADER); m_shaders[2] = CreateShader(LoadShader(fileName + ".geom.glsl"), GL_GEOMETRY_SHADER); for (unsigned int i = 0; i < NUM_SHADERS; i++) { glAttachShader(m_program, m_shaders[i]); } glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true); m_uniforms[TRANSFROM_U] = glGetUniformLocation(m_program, "TransformMatrix"); m_uniforms[PROJVIEW_U] = glGetUniformLocation(m_program, "ProjectionViewMatrix"); m_uniforms[VIEWPOS_U] = glGetUniformLocation(m_program, "ViewPos"); }
// Compiles a GL shader, attaches it to a program, and releases the shader's reference. // (That way there's no need to hang on to the GL shader id and delete it later.) static bool 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 false; } 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.info().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 false; } } if (c_PrintShaders) { GrPrintf(shaderSrc.c_str()); GrPrintf("\n"); } GR_GL_CALL(gli, AttachShader(programId, shaderId)); GR_GL_CALL(gli, DeleteShader(shaderId)); return true; }
GLuint CreateProgram(const char *a_vertex, const char *a_frag) { std::vector<GLuint> shaderList; shaderList.push_back(CreateShader(GL_VERTEX_SHADER, a_vertex)); shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, a_frag)); //create shader program ID GLuint uiProgram = glCreateProgram(); //attach shaders for (auto shader = shaderList.begin(); shader != shaderList.end(); shader++) glAttachShader(uiProgram, *shader); //link program glLinkProgram(uiProgram); //check for link errors and output them GLint status; glGetProgramiv(uiProgram, GL_LINK_STATUS, &status); if (status == GL_FALSE) { GLint infoLogLength; glGetProgramiv(uiProgram, GL_INFO_LOG_LENGTH, &infoLogLength); GLchar *strInfoLog = new GLchar[infoLogLength + 1]; glGetProgramInfoLog(uiProgram, infoLogLength, NULL, strInfoLog); fprintf(stderr, "Linker failure: %s\n", strInfoLog); delete[] strInfoLog; } for (auto shader = shaderList.begin(); shader != shaderList.end(); shader++) { glDetachShader(uiProgram, *shader); glDeleteShader(*shader); } return uiProgram; }
void CInfoTextureCombiner::SwitchMode(const std::string& name) { if (name.empty()) { curMode = name; disabled = true; CreateShader("", true); return; } // WTF? fully reloaded from disk on every switch? if (name == "los") { disabled = !CreateShader("shaders/GLSL/infoLOS.lua", true , float4(0.5f, 0.5f, 0.5f, 0.5f)); } else if (name == "metal") { disabled = !CreateShader("shaders/GLSL/infoMetal.lua", true, float4(0.f, 0.f, 0.f, 1.0f)); } else if (name == "height") { disabled = !CreateShader("shaders/GLSL/infoHeight.lua"); } else if (name == "path") { disabled = !CreateShader("shaders/GLSL/infoPath.lua"); } else { //FIXME allow "info:myluainfotex" disabled = !CreateShader(name); } curMode = (disabled) ? "" : name; }
GLShader *GLProgramManager::RegisterShader(const std::string &name) { SPADES_MARK_FUNCTION(); std::map<std::string, GLShader *>::iterator it; it = shaders.find(name); if(it == shaders.end()){ GLShader *prog = CreateShader(name); shaders[name] = prog; return prog; }else{ return it->second; } }