GLProgram make_program(const char * _vshader_path,const char * _fshader_path){ std::string vshader_path = std::string(_vshader_path); std::string fshader_path = std::string(_fshader_path); GLProgram sprogram; sprogram.vertex_shader=make_shader(vshader_path,GL_VERTEX_SHADER); sprogram.fragment_shader=make_shader(fshader_path,GL_FRAGMENT_SHADER); sprogram.gl_ref = glCreateProgram(); glAttachShader(sprogram.gl_ref, sprogram.vertex_shader); glAttachShader(sprogram.gl_ref, sprogram.fragment_shader); glLinkProgram(sprogram.gl_ref); GLint status; glGetProgramiv (sprogram.gl_ref, GL_LINK_STATUS, &status); if (status == GL_FALSE) { GLint infoLogLength; glGetProgramiv(sprogram.gl_ref, GL_INFO_LOG_LENGTH, &infoLogLength); GLchar *strInfoLog = new GLchar[infoLogLength + 1]; glGetProgramInfoLog(sprogram.gl_ref, infoLogLength, NULL, strInfoLog); fprintf(stderr, "Linker failure: %s\n", strInfoLog); delete[] strInfoLog; } sprogram.link(); return sprogram; }
void CEmbossTest::ShowEffect() { // 1 Size size = Director::getInstance()->getWinSize(); Sprite* pSprite = Sprite::create("HelloWorld.png"); pSprite->setPosition(ccp(size.width / 2, size.height / 2)); this->addChild(pSprite); // 2 const GLchar* fragmentSource = (GLchar*)CCString::createWithContentsOfFile(FileUtils::getInstance()->fullPathFromRelativeFile("CSEEmboss.fsh", "./Resources"))->getCString(); GLProgram* glProgram = new GLProgram(); //glProgram->initWithVertexShaderByteArray(ccPositionTextureA8Color_vert, fragmentSource); glProgram->initWithVertexShaderByteArray(ccPositionTextureColor_noMVP_vert, fragmentSource); pSprite->setShaderProgram(glProgram); pSprite->getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position); pSprite->getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords); pSprite->getShaderProgram()->link(); pSprite->getShaderProgram()->updateUniforms(); // 3 pSprite->getShaderProgram()->use(); }
GLColorBuffer GLLensDustFilter::GaussianBlur(GLColorBuffer tex, bool vertical) { SPADES_MARK_FUNCTION(); GLProgram *program = gauss1d; IGLDevice *dev = renderer->GetGLDevice(); GLQuadRenderer qr(dev); int w = tex.GetWidth(); int h = tex.GetHeight(); static GLProgramAttribute blur_positionAttribute("positionAttribute"); static GLProgramUniform blur_textureUniform("mainTexture"); static GLProgramUniform blur_unitShift("unitShift"); program->Use(); blur_positionAttribute(program); blur_textureUniform(program); blur_textureUniform.SetValue(0); dev->ActiveTexture(0); dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture()); blur_unitShift(program); blur_unitShift.SetValue(vertical ? 0.f : 1.f / w, vertical ? 1.f / h : 0.f); qr.SetCoordAttributeIndex(blur_positionAttribute()); dev->Enable(IGLDevice::Blend, false); GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false); dev->Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight()); dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer()); qr.Draw(); return buf2; }
bool BlurNode::init() { if (!Node::init()) return false; // read and add my shader GLProgram* program = GLProgram::createWithFilenames("ccShader_blur.vert", "BlurNormal.frag"); if (!program) return false; setShaderProgram(program); // get uniform variable location _uSolutionLocation = program->getUniformLocation("u_resolution"); // load texture2D _texture = TextureCache::getInstance()->addImage("cballs.png"); if (!_texture) return false; _texture->retain(); setContentSize(_texture->getContentSize()); Size size = getContentSize(); // init vertices array and texCoord array _vertices.push_back(Point::ZERO); _vertices.push_back(Point(size.width, 0)); _vertices.push_back(Point(0, size.height)); _vertices.push_back(Point(size.width, size.height)); _texCoord.push_back(Point(0, 1)); _texCoord.push_back(Point(1, 1)); _texCoord.push_back(Point::ZERO); _texCoord.push_back(Point(1, 0)); scheduleUpdate(); return true; }
void BeginStencilCommand::init(float depth, bool inverted, float alphaThreshold, Node* stencil, bool clearStencil) { _globalOrder = depth; _inverted = inverted; _alphaThreshold = alphaThreshold; _stencil = stencil; _clearStencil = clearStencil; if (_stencil && _alphaThreshold < 1) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) #else // since glAlphaTest do not exists in OES, use a shader that writes // pixel only if greater than an alpha threshold GLProgram *program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV); GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE); // set our alphaThreshold program->use(); program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold); // we need to recursively apply this shader to all the nodes in the stencil node // FIXME: we should have a way to apply shader to all nodes without having to do this setProgram(_stencil, program); #endif } }
void LayerShaderStudy00::onCustomDraw(const cocos2d::Mat4 &transform, uint32_t flags) { Size winSize = Director::getInstance()->getWinSize(); // data define GLfloat vertercies[] = { 0.0f,0.0f, winSize.width,0.0f, winSize.width*0.5f,winSize.height}; GLfloat color[] = { 1.0f,0.0f,0.0f,1.0f, 0.0f,1.0f,0.0f,1.0f, 0.0f,0.0f,1.0f,1.0f }; // gl programe use GLProgram* pGlPrograme = getGLProgram(); pGlPrograme->use(); // input params uniform-mvp pGlPrograme->setUniformsForBuiltins(); // input params attribute GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, vertercies); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, color); // draw glDrawArrays(GL_TRIANGLES, 0, 3); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 3); CHECK_GL_ERROR_DEBUG(); }
void Utils::setGray(Node *node) { return; USING_NS_CC; do { const GLchar* pszFragSource = "#ifdef GL_ES \n \ precision mediump float; \n \ #endif \n \ uniform sampler2D u_texture; \n \ varying vec2 v_texCoord; \n \ varying vec4 v_fragmentColor; \n \ void main(void) \n \ { \n \ // Convert to greyscale using NTSC weightings \n \ vec4 col = texture2D(u_texture, v_texCoord); \n \ float grey = dot(col.rgb, vec3(0.299, 0.587, 0.114)); \n \ gl_FragColor = vec4(grey, grey, grey, col.a); \n \ }"; GLProgram* pProgram = new GLProgram(); pProgram->initWithByteArrays(ccPositionTextureColor_noMVP_vert, pszFragSource); node->setGLProgram(pProgram); node->getGLProgram()->link(); node->getGLProgram()->updateUniforms(); CHECK_GL_ERROR_DEBUG(); }while(0); }
void draw(GLProgram &s){ set_line_width(ceil(width*scale)); bind_buffer_object(line_vbo,0); s.uniformf("pos",pos_start.x,pos_start.y); //Assume line attr = {(0,0),(1,1)} s.uniformf("size", pos_end.x - pos_start.x , pos_end.y - pos_start.y); s.uniformf("color",line_color.r,line_color.g,line_color.b,line_color.a); draw_buffers_line_loop(2); }
GLProgram* TestFilter::loadShader() { GLProgram* p = new GLProgram(); CCLOG("TestFilter::loadShader, program: %p", p); p->initWithByteArrays(ccFilterShader_test_vert, ccFilterShader_test_frag); return p; }
static void LinkProgram(GLProgram &program) { program.Link(); if (program.GetLinkStatus() != GL_TRUE) { char log[4096]; program.GetInfoLog(log, sizeof(log)); fprintf(stderr, "Shader linker failed: %s\n", log); } }
inline GLProgram buildProgram(std::initializer_list<GLShader> shaders) { GLProgram program; for (const auto& shader : shaders) { program.attachShader(shader); } if (!program.link()) { std::cerr << program.getInfoLog() << std::endl; throw std::runtime_error(program.getInfoLog()); } return program; }
void draw(GLProgram &s){ bind_buffer_object(square_vbo,0); s.uniformf("pos",pos.x,pos.y); s.uniformf("size",size.x,size.y); s.uniformf("color",bg.r,bg.g,bg.b,bg.a); draw_buffers_triangle_fan(4); if(border.a != 0.0 && width > 0.0){ set_line_width(ceil(width*scale)); s.uniformf("color",border.r,border.g,border.b,border.a); draw_buffers_line_loop(4); } }
void ShaderCache::reloadDefaultShaders() { // reset all programs and reload them // Position Texture Color shader GLProgram *p = programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR); p->reset(); loadDefaultShader(p, kShaderType_PositionTextureColor); // Position Texture Color alpha test p = programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST); p->reset(); loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest); // // Position, Color shader // p = programForKey(GLProgram::SHADER_NAME_POSITION_COLOR); p->reset(); loadDefaultShader(p, kShaderType_PositionColor); // // Position Texture shader // p = programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE); p->reset(); loadDefaultShader(p, kShaderType_PositionTexture); // // Position, Texture attribs, 1 Color as uniform shader // p = programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR); p->reset(); loadDefaultShader(p, kShaderType_PositionTexture_uColor); // // Position Texture A8 Color shader // p = programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR); p->reset(); loadDefaultShader(p, kShaderType_PositionTextureA8Color); // // Position and 1 color passed as a uniform (to simulate glColor4ub ) // p = programForKey(GLProgram::SHADER_NAME_POSITION_U_COLOR); p->reset(); loadDefaultShader(p, kShaderType_Position_uColor); // // Position, Legth(TexCoords, Color (used by Draw Node basically ) // p = programForKey(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR); p->reset(); loadDefaultShader(p, kShaderType_PositionLengthTexureColor); }
void ShaderCache::reloadDefaultShaders() { // reset all programs and reload them // Position Texture Color shader GLProgram *p = programForKey(kShader_PositionTextureColor); p->reset(); loadDefaultShader(p, kShaderType_PositionTextureColor); // Position Texture Color alpha test p = programForKey(kShader_PositionTextureColorAlphaTest); p->reset(); loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest); // // Position, Color shader // p = programForKey(kShader_PositionColor); p->reset(); loadDefaultShader(p, kShaderType_PositionColor); // // Position Texture shader // p = programForKey(kShader_PositionTexture); p->reset(); loadDefaultShader(p, kShaderType_PositionTexture); // // Position, Texture attribs, 1 Color as uniform shader // p = programForKey(kShader_PositionTexture_uColor); p->reset(); loadDefaultShader(p, kShaderType_PositionTexture_uColor); // // Position Texture A8 Color shader // p = programForKey(kShader_PositionTextureA8Color); p->reset(); loadDefaultShader(p, kShaderType_PositionTextureA8Color); // // Position and 1 color passed as a uniform (to simulate glColor4ub ) // p = programForKey(kShader_Position_uColor); p->reset(); loadDefaultShader(p, kShaderType_Position_uColor); // // Position, Legth(TexCoords, Color (used by Draw Node basically ) // p = programForKey(kShader_PositionLengthTexureColor); p->reset(); loadDefaultShader(p, kShaderType_PositionLengthTexureColor); }
GLColorBuffer GLDepthOfFieldFilter::Blur(GLColorBuffer buffer, GLColorBuffer coc, Vector2 offset, int divide) { SPADES_MARK_FUNCTION(); // do gaussian blur GLProgram *program = blurProgram; IGLDevice *dev = renderer->GetGLDevice(); GLQuadRenderer qr(dev); int w = buffer.GetWidth(); int h = buffer.GetHeight(); int w2 = w / divide; int h2 = h / divide; static GLProgramAttribute blur_positionAttribute("positionAttribute"); static GLProgramUniform blur_textureUniform("texture"); static GLProgramUniform blur_cocUniform("cocTexture"); static GLProgramUniform blur_offset("offset"); program->Use(); blur_positionAttribute(program); blur_textureUniform(program); blur_cocUniform(program); blur_offset(program); blur_cocUniform.SetValue(1); dev->ActiveTexture(1); dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture()); blur_textureUniform.SetValue(0); dev->ActiveTexture(0); qr.SetCoordAttributeIndex(blur_positionAttribute()); // x-direction float len = offset.GetLength(); float sX = 1.f / (float)w, sY = 1.f / (float)h; while(len > .5f){ GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w2, h2, false); dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer()); dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture()); blur_offset.SetValue(offset.x * sX, offset.y * sY); qr.Draw(); buffer = buf2; offset *= .125f; len *= .125f; } return buffer; }
void MaskShaderEffect::buildCustomUniforms() { GLProgram *shader = getShaderProgram(); _uniformTouchPoint = shader->getUniformLocation("touchPoint"); #ifndef ES_30_SUPPORT _uniformCoefficient = shader->getUniformLocation("coefficient"); _uniformColor = shader->getUniformLocation("color"); #endif }
GLColorBuffer GLDepthOfFieldFilter::FinalMix(GLColorBuffer tex, GLColorBuffer blur1, GLColorBuffer blur2, GLColorBuffer coc) { SPADES_MARK_FUNCTION(); // do gaussian blur GLProgram *program = finalMix; IGLDevice *dev = renderer->GetGLDevice(); GLQuadRenderer qr(dev); int w = tex.GetWidth(); int h = tex.GetHeight(); static GLProgramAttribute blur_positionAttribute("positionAttribute"); static GLProgramUniform blur_textureUniform1("texture"); static GLProgramUniform blur_textureUniform2("blurTexture1"); static GLProgramUniform blur_textureUniform3("blurTexture2"); static GLProgramUniform blur_textureUniform4("cocTexture"); program->Use(); blur_positionAttribute(program); blur_textureUniform1(program); blur_textureUniform1.SetValue(3); dev->ActiveTexture(3); dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture()); blur_textureUniform2(program); blur_textureUniform2.SetValue(2); dev->ActiveTexture(2); dev->BindTexture(IGLDevice::Texture2D, blur1.GetTexture()); blur_textureUniform3(program); blur_textureUniform3.SetValue(1); dev->ActiveTexture(1); dev->BindTexture(IGLDevice::Texture2D, blur2.GetTexture()); blur_textureUniform4(program); blur_textureUniform4.SetValue(0); dev->ActiveTexture(0); dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture()); qr.SetCoordAttributeIndex(blur_positionAttribute()); dev->Enable(IGLDevice::Blend, false); // x-direction GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false); dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer()); qr.Draw(); return buf2; }
void GLProgramCache::reloadDefaultGLProgramsRelativeToLights() { GLProgram *p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL); p->reset(); loadDefaultGLProgram(p, kShaderType_3DPositionNormal); p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_3DPositionNormalTex); p = getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex); }
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; }
void LayerShaderStudy05::onCustomDraw(const cocos2d::Mat4& transform, uint32_t flags) { // gl programe use GLProgram* pGlPrograme = getGLProgram(); pGlPrograme->use(); // input params uniform-mvp pGlPrograme->setUniformsForBuiltins(); glBindVertexArray(m_vao); glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 3); CHECK_GL_ERROR_DEBUG(); }
void ShaderDemoNode::onDraw(const cocos2d::Mat4& transform, uint32_t flags) { // gl programe use GLProgram* pGlPrograme = getGLProgram(); pGlPrograme->use(); // 应用变换矩阵 getGLProgramState()->apply(transform); glBindVertexArray(m_vao); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE,(GLvoid*)0); glBindVertexArray(0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 6); CHECK_GL_ERROR_DEBUG(); }
GLColorBuffer GLLensDustFilter::DownSample(GLColorBuffer tex, bool linearize) { SPADES_MARK_FUNCTION(); GLProgram *program = thru; IGLDevice *dev = renderer->GetGLDevice(); GLQuadRenderer qr(dev); int w = tex.GetWidth(); int h = tex.GetHeight(); static GLProgramAttribute blur_positionAttribute("positionAttribute"); static GLProgramUniform blur_textureUniform("mainTexture"); static GLProgramUniform blur_colorUniform("colorUniform"); static GLProgramUniform blur_texCoordRangeUniform("texCoordRange"); static GLProgramUniform blur_texCoordOffsetUniform("texCoordOffset"); program->Use(); blur_positionAttribute(program); blur_textureUniform(program); blur_textureUniform.SetValue(0); dev->ActiveTexture(0); dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture()); blur_texCoordOffsetUniform(program); blur_texCoordOffsetUniform.SetValue(1.f / w, 1.f / h, -1.f / w, -1.f / h); blur_colorUniform(program); blur_colorUniform.SetValue(1.f,1.f,1.f,1.f); blur_texCoordRangeUniform(program); blur_texCoordRangeUniform.SetValue(0.f, 0.f, (float)((w + 1) & ~1) / w, (float)((h + 1) & ~1) / h); qr.SetCoordAttributeIndex(blur_positionAttribute()); if(linearize){ dev->Enable(IGLDevice::Blend, true); dev->BlendFunc(IGLDevice::SrcColor, IGLDevice::Zero); }else{ dev->Enable(IGLDevice::Blend, false); } GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle((w+1)/2, (h+1)/2, false); dev->Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight()); dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer()); qr.Draw(); return buf2; }
void GLVAO::Draw(GLProgram &prog) { this->Bind(); prog.Bind(); for (unsigned int i = 0; i < this->buffs.size(); i++) { glEnableVertexAttribArray(this->ids[i]); } glDrawArrays(GL_POINTS, 0, this->length); for (unsigned int i = 0; i < this->buffs.size(); i++) { glDisableVertexAttribArray(this->ids[i]); } prog.Unbind(); this->Unbind(); }
static GLProgram * CompileProgram(const char *vertex_shader, const char *fragment_shader) { GLProgram *program = new GLProgram(); CompileAttachShader(*program, GL_VERTEX_SHADER, vertex_shader); CompileAttachShader(*program, GL_FRAGMENT_SHADER, fragment_shader); program->Link(); if (program->GetLinkStatus() != GL_TRUE) { char log[4096]; program->GetInfoLog(log, sizeof(log)); fprintf(stderr, "Shader linker failed: %s\n", log); } return program; }
void DebugGrid::Draw(GLProgram& glProgram, Renderer& renderer) { UNUSED(renderer) g_MVPMatrix->PushMatrix(); glProgram.SetUniform("emissive", 1.0); glProgram.SetUniform("color", GetColor()); glProgram.SetUniform("hasDiffuseMap", false); glProgram.SetUniform("hasNormalMap", false); glProgram.SetUniform("hasSpecularMap", false); glProgram.SetUniform("hasEmissiveMap", false); g_MVPMatrix->Translate(0.0f, -1.0f, 0.0f); m_vbo->Draw(glProgram); g_MVPMatrix->PopMatrix(); }
void deinit() { // GL resources must be accessed from the main thread only. bank.unloadAll(Bank::ImmediatelyInCurrentThread); atlas.reset(); program.clear(); }
void mainLoop() { while (!glfwWindowShouldClose(window) && !glfwGetKey(window, GLFW_KEY_ESCAPE)) { glClear(GL_COLOR_BUFFER_BIT); program.use(); program.setUniform("Material.Kd", 0.2f, 0.8f, 0.3f); program.setUniform("Material.Ka", 0.2f, 0.6f, 0.3f); program.setUniform("Material.Ks", 0.2f, 0.2f, 0.8f); program.setUniform("Material.Shininess", 100.0f); glm::mat4 mv = view * model; program.setUniform("ModelViewMatrix", mv); program.setUniform("NormalMatrix", glm::mat3(glm::vec3(mv[0]), glm::vec3(mv[1]), glm::vec3(mv[2]))); glm::mat4 mvp = projection * mv; program.setUniform("MVP", mvp); cube->render(); glfwPollEvents(); glfwSwapBuffers(window); } }
void MaskShaderEffect::setCustomUniforms() { GLProgram *shader = getShaderProgram(); shader->setUniformLocationWith2f(_uniformTouchPoint, _touchPoint.x, _touchPoint.y); #ifndef ES_30_SUPPORT shader->setUniformLocationWith4f(_uniformCoefficient, _maskParams.inverted, \ _maskParams.radius, _maskParams.gradient, _maskParams.brightness); shader->setUniformLocationWith4f(_uniformColor, _maskParams.color.r, \ _maskParams.color.g, _maskParams.color.b, _maskParams.color.a); #endif if (_textureID != 0) { /* cocos2dx alway binding GL_TEXTURE0 with 2d samlper/CC_Texture0. */ glActiveTexture(GL_TEXTURE0); GL::bindTexture2D(_textureID); } }
void GLVAO::BindWithProgram(GLProgram &prog, std::string arg1) { GLuint loc; this->Bind(); loc = prog.GetArgLocation(arg1.c_str()); this->ids[0] = loc; this->buffs[0]->BindAttrib(loc); this->Unbind(); }
GLColorBuffer GLDepthOfFieldFilter::AddMix(GLColorBuffer buffer1, GLColorBuffer buffer2) { SPADES_MARK_FUNCTION(); // do gaussian blur GLProgram *program = gammaMix; IGLDevice *dev = renderer->GetGLDevice(); GLQuadRenderer qr(dev); int w = buffer1.GetWidth(); int h = buffer1.GetHeight(); static GLProgramAttribute blur_positionAttribute("positionAttribute"); static GLProgramUniform blur_textureUniform1("texture1"); static GLProgramUniform blur_textureUniform2("texture2"); static GLProgramUniform blur_unitShift("unitShift"); static GLProgramUniform blur_mix1("mix1"); static GLProgramUniform blur_mix2("mix2"); program->Use(); blur_positionAttribute(program); blur_textureUniform1(program); blur_textureUniform1.SetValue(1); dev->ActiveTexture(1); dev->BindTexture(IGLDevice::Texture2D, buffer1.GetTexture()); blur_textureUniform2(program); blur_textureUniform2.SetValue(0); dev->ActiveTexture(0); dev->BindTexture(IGLDevice::Texture2D, buffer2.GetTexture()); blur_mix1(program); blur_mix2(program); blur_mix1.SetValue(.5f, .5f, .5f); blur_mix2.SetValue(.5f, .5f, .5f); qr.SetCoordAttributeIndex(blur_positionAttribute()); dev->Enable(IGLDevice::Blend, false); // x-direction GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false); dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer()); qr.Draw(); return buf2; }