//-------------------------------------------------------------- void ofShader::end() const{ ofGetGLRenderer()->unbind(*this); }
//---------------------------------------- void ofDisableSeparateSpecularLight(){ ofGetGLRenderer()->disableSeparateSpecularLight(); }
//---------------------------------------------------------- void ofTexture::unbind(int textureLocation) const{ ofGetGLRenderer()->unbind(*this,textureLocation); }
//---------------------------------------- void ofLight::setAmbientColor(const ofFloatColor& c) { data->ambientColor = c; ofGetGLRenderer()->setLightAmbientColor(data->glIndex, c); }
//---------------------------------------- void ofLight::setSpecularColor(const ofFloatColor& c) { data->specularColor = c; ofGetGLRenderer()->setLightSpecularColor(data->glIndex, c); }
//---------------------------------------- void ofLight::setSpotlightCutOff( float spotCutOff ) { data->spotCutOff = CLAMP(spotCutOff, 0, 90); ofGetGLRenderer()->setLightSpotlightCutOff(data->glIndex, spotCutOff); }
//---------------------------------------- void ofLight::setSpotConcentration( float exponent ) { data->exponent = CLAMP(exponent, 0, 128); ofGetGLRenderer()->setLightSpotConcentration(data->glIndex, exponent); }
//------------------------------------ void ofVideoPlayer::unbind() const{ shared_ptr<ofBaseGLRenderer> renderer = ofGetGLRenderer(); if(renderer){ renderer->unbind(*this); } }
//---------------------------------------- void ofSetSmoothLighting(bool b) { ofGetGLRenderer()->setSmoothLighting(b); }
//-------------------------------------------------------------- void ofVbo::drawInstanced(int drawMode, int first, int total, int primCount) const{ ofGetGLRenderer()->drawInstanced(*this,drawMode,first,total,primCount); }
//-------------------------------------------------------------- void ofVbo::drawElementsInstanced(int drawMode, int amt, int primCount) const{ ofGetGLRenderer()->drawElementsInstanced(*this,drawMode,amt,primCount); }
//-------------------------------------------------------------- void ofVbo::drawElements(int drawMode, int amt, int offsetelements) const{ ofGetGLRenderer()->drawElements(*this,drawMode,amt,offsetelements); }
//-------------------------------------------------------------- void ofVbo::draw(int drawMode, int first, int total) const{ ofGetGLRenderer()->draw(*this,drawMode,first,total); }
void ofTexture::disableTextureTarget(int textureLocation) const{ if(ofGetGLRenderer()) ofGetGLRenderer()->disableTextureTarget(texData.textureTarget, textureLocation); }
//-------------------------------------------------------------- void ofFbo::allocate(Settings _settings) { if(!checkGLSupport()) return; clear(); auto renderer = _settings.renderer.lock(); if(renderer){ settings.renderer = renderer; }else{ settings.renderer = ofGetGLRenderer(); } // check that passed values are correct if(_settings.width <= 0 || _settings.height <= 0){ ofLogError("ofFbo") << "width and height have to be more than 0"; } if(_settings.numSamples > maxSamples() && maxSamples() > -1) { ofLogWarning("ofFbo") << "allocate(): clamping numSamples " << _settings.numSamples << " to maxSamples " << maxSamples() << " for frame buffer object" << fbo; _settings.numSamples = maxSamples(); } if(_settings.depthStencilAsTexture && _settings.numSamples){ ofLogWarning("ofFbo") << "allocate(): multisampling not supported with depthStencilAsTexture, setting 0 samples for frame buffer object " << fbo; _settings.numSamples = 0; } //currently depth only works if stencil is enabled. // http://forum.openframeworks.cc/index.php/topic,6837.0.html #ifdef TARGET_OPENGLES if(_settings.useDepth){ _settings.useStencil = true; } if( _settings.depthStencilAsTexture ){ _settings.depthStencilAsTexture = false; ofLogWarning("ofFbo") << "allocate(): depthStencilAsTexture is not available for iOS"; } #endif GLenum depthAttachment = GL_DEPTH_ATTACHMENT; if( _settings.useDepth && _settings.useStencil ){ _settings.depthStencilInternalFormat = GL_DEPTH_STENCIL; #ifdef TARGET_OPENGLES depthAttachment = GL_DEPTH_ATTACHMENT; #else depthAttachment = GL_DEPTH_STENCIL_ATTACHMENT; #endif }else if(_settings.useDepth){ depthAttachment = GL_DEPTH_ATTACHMENT; }else if(_settings.useStencil){ depthAttachment = GL_STENCIL_ATTACHMENT; _settings.depthStencilInternalFormat = GL_STENCIL_INDEX; } // set needed values for allocation on instance settings // the rest will be set by the corresponding methods during allocation settings.width = _settings.width; settings.height = _settings.height; settings.numSamples = _settings.numSamples; // create main fbo // this is the main one we bind for drawing into // all the renderbuffers are attached to this (whether MSAA is enabled or not) glGenFramebuffers(1, &fbo); retainFB(fbo); GLint previousFboId = 0; // note that we are using a glGetInteger method here, which may stall the pipeline. // in the allocate() method, this is not that tragic since this will not be called // within the draw() loop. Here, we need not optimise for performance, but for // simplicity and readability . glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFboId); glBindFramebuffer(GL_FRAMEBUFFER, fbo); //- USE REGULAR RENDER BUFFER if(!_settings.depthStencilAsTexture){ if(_settings.useDepth && _settings.useStencil){ stencilBuffer = depthBuffer = createAndAttachRenderbuffer(_settings.depthStencilInternalFormat, depthAttachment); retainRB(stencilBuffer); retainRB(depthBuffer); }else if(_settings.useDepth){ depthBuffer = createAndAttachRenderbuffer(_settings.depthStencilInternalFormat, depthAttachment); retainRB(depthBuffer); }else if(_settings.useStencil){ stencilBuffer = createAndAttachRenderbuffer(_settings.depthStencilInternalFormat, depthAttachment); retainRB(stencilBuffer); } //- INSTEAD USE TEXTURE }else{ if(_settings.useDepth || _settings.useStencil){ createAndAttachDepthStencilTexture(_settings.textureTarget,_settings.depthStencilInternalFormat,depthAttachment); #ifdef TARGET_OPENGLES // if there's depth and stencil the texture should be attached as // depth and stencil attachments // http://www.khronos.org/registry/gles/extensions/OES/OES_packed_depth_stencil.txt if(_settings.useDepth && _settings.useStencil){ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthBufferTex.texData.textureID, 0); } #endif } } settings.useDepth = _settings.useDepth; settings.useStencil = _settings.useStencil; settings.depthStencilInternalFormat = _settings.depthStencilInternalFormat; settings.depthStencilAsTexture = _settings.depthStencilAsTexture; settings.textureTarget = _settings.textureTarget; settings.wrapModeHorizontal = _settings.wrapModeHorizontal; settings.wrapModeVertical = _settings.wrapModeVertical; settings.maxFilter = _settings.maxFilter; settings.minFilter = _settings.minFilter; // if we want MSAA, create a new fbo for textures #ifndef TARGET_OPENGLES if(_settings.numSamples){ glGenFramebuffers(1, &fboTextures); retainFB(fboTextures); }else{ fboTextures = fbo; } #else fboTextures = fbo; if(_settings.numSamples){ ofLogWarning("ofFbo") << "allocate(): multisampling not supported in OpenGL ES"; } #endif // now create all textures and color buffers if(_settings.colorFormats.size() > 0) { for(int i=0; i<(int)_settings.colorFormats.size(); i++) createAndAttachTexture(_settings.colorFormats[i], i); } else if(_settings.numColorbuffers > 0) { for(int i=0; i<_settings.numColorbuffers; i++) createAndAttachTexture(_settings.internalformat, i); _settings.colorFormats = settings.colorFormats; } else { ofLogWarning("ofFbo") << "allocate(): no color buffers specified for frame buffer object " << fbo; } settings.internalformat = _settings.internalformat; dirty.resize(_settings.colorFormats.size(), true); // we start with all color buffers dirty. // if textures are attached to a different fbo (e.g. if using MSAA) check it's status if(fbo != fboTextures) { glBindFramebuffer(GL_FRAMEBUFFER, fboTextures); } // check everything is ok with this fbo bIsAllocated = checkStatus(); // restore previous framebuffer id glBindFramebuffer(GL_FRAMEBUFFER, previousFboId); /* UNCOMMENT OUTSIDE OF DOING RELEASES // this should never happen if(settings != _settings) ofLogWarning("ofFbo") << "allocation not complete, passed settings not equal to created ones, this is an internal OF bug"; */ #ifdef TARGET_ANDROID ofAddListener(ofxAndroidEvents().reloadGL,this,&ofFbo::reloadFbo); #endif }
//---------------------------------------- void ofSetGlobalAmbientColor(const ofFloatColor& c) { ofGetGLRenderer()->setGlobalAmbientColor(c); globalAmbient = c; }
//---------------------------------------- void ofLight::disable() { data->isEnabled = false; ofGetGLRenderer()->disableLight(data->glIndex); }
void ofGrabScreen(ofPixels & p, int x, int y, int w, int h){ std::shared_ptr<ofBaseGLRenderer> renderer = ofGetGLRenderer(); if(renderer){ renderer->saveScreen(x,y,w,h,p); } }
//---------------------------------------- void ofEnableLighting() { ofGetGLRenderer()->enableLighting(); }
void ofMaterial::begin() const{ if(ofGetGLRenderer()){ ofGetGLRenderer()->bind(*this); } }
//---------------------------------------- void ofDisableLighting() { ofGetGLRenderer()->disableLighting(); }
void ofMaterial::end() const{ if(ofGetGLRenderer()){ ofGetGLRenderer()->unbind(*this); } }
//---------------------------------------- void ofLight::setDiffuseColor(const ofFloatColor& c) { data->diffuseColor = c; ofGetGLRenderer()->setLightDiffuseColor(data->glIndex, c); }
void ofTexture::disableTextureTarget(){ if(ofGetGLRenderer()) ofGetGLRenderer()->disableTextureTarget(texData.textureTarget); }
//---------------------------------------- void ofEnableSeparateSpecularLight(){ ofGetGLRenderer()->enableSeparateSpecularLight(); }
//-------------------------------------------------------------- void ofShader::begin() const{ ofGetGLRenderer()->bind(*this); }
//---------------------------------------- bool ofGetLightingEnabled() { return ofGetGLRenderer()->getLightingEnabled(); }
//---------------------------------------------------------- void ofTexture::drawSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ shared_ptr<ofBaseGLRenderer> renderer = ofGetGLRenderer(); if(renderer){ renderer->draw(*this,x,y,z,w,h,sx,sy,sw,sh); } }