void ComputeShaderChunk::onDestroy(UInt32 uiId) { if(getGLId() > 0) Window::destroyGLObject(getGLId(), 1); Inherited::onDestroy(uiId); }
void FragmentProgramChunk::onDestroy(UInt32 uiContainerId) { if(getGLId() > 0) Window::destroyGLObject(getGLId(), 1); Inherited::onDestroy(uiContainerId); }
void ShaderExecutableChunk::onDestroy(UInt32 uiId) { if(getGLId() > 0) Window::destroyGLObject(getGLId(), 1); Inherited::onDestroy(uiId); }
void ComputeShaderChunk::activate(DrawEnv *pEnv, UInt32 uiIdx) { Window *pWin = pEnv->getWindow(); UInt32 uiValRes = pWin->validateGLObject(getGLId(), pEnv, KeepProgActive); GLuint uiProgId = GLuint(pWin->getGLObjectId(getGLId())); if(uiProgId == 0) return; pEnv->setActiveShader(uiProgId); if(0x0000 == (uiValRes & ProgActive)) { OSGGETGLFUNCBYID_GL3_ES(glUseProgram, osgGlUseProgram, ShaderProgram::getFuncIdUseProgram(), pWin); osgGlUseProgram(uiProgId); } pEnv->incNumShaderChanges(); updateProceduralVariables(pEnv, ShaderProcVariable::SHDAll); }
void *GeoVectorBufferRefProperty::mapBuffer(GLenum eAccess, DrawEnv *pEnv) { void *returnValue = NULL; if((getUseVBO() == true) && (getGLId() != 0)) { Window *pWin = pEnv->getWindow(); OSGGETGLFUNCBYID( OSGglBindBufferARB, osgGlBindBufferARB, _funcBindBuffer, pWin); OSGGETGLFUNCBYID( OSGglMapBufferARB, osgGlMapBufferARB, _funcMapBuffer, pWin); osgGlBindBufferARB(GL_ARRAY_BUFFER_ARB, getGLId()); returnValue = osgGlMapBufferARB(GL_ARRAY_BUFFER_ARB, eAccess); osgGlBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } return returnValue; }
bool GeoVectorProperty::unmapBuffer(DrawEnv *pEnv) { bool returnValue = true; if((getUseVBO() == true) && (getGLId() != 0)) { Window *pWin = pEnv->getWindow(); osgSinkUnusedWarning(pWin); OSGGETGLFUNCBYID_GL3_ES( glBindBuffer, osgGlBindBuffer, _funcBindBuffer, pWin); OSGGETGLFUNCBYID_GL3 ( glUnmapBuffer, osgGlUnmapBuffer, _funcUnmapBuffer, pWin); osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, pWin->getGLObjectId(getGLId())); returnValue = (osgGlUnmapBuffer(GL_ARRAY_BUFFER_ARB) != 0); osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0); } return returnValue; }
void *GeoVectorProperty::mapBuffer(GLenum eAccess, DrawEnv *pEnv) { void *returnValue = NULL; if((getUseVBO() == true) && (getGLId() != 0)) { Window *pWin = pEnv->getWindow(); osgSinkUnusedWarning(pWin); OSGGETGLFUNCBYID_GL3_ES( glBindBuffer, osgGlBindBuffer, _funcBindBuffer, pWin); OSGGETGLFUNCBYID_GL3 ( glMapBuffer, osgGlMapBuffer, _funcMapBuffer, pWin); pWin->validateGLObject(getGLId(), pEnv); osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, pWin->getGLObjectId(getGLId())); returnValue = osgGlMapBuffer(GL_ARRAY_BUFFER_ARB, eAccess); osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0); } return returnValue; }
void GeoIntegralBufferRefProperty::changeFrom(DrawEnv *pEnv, StateChunk *old, UInt32 slot) { // change from me to me? // this assumes I haven't changed in the meantime. if(old == this) return; Window *win = pEnv->getWindow(); GeoIntegralProperty *o = dynamic_cast<GeoIntegralProperty*>(old); if(!win->hasExtension(_extVertexBufferObject)) return; OSGGETGLFUNCBYID( OSGglBindBufferARB, osgGlBindBufferARB, _funcBindBuffer, win); if(getGLId() != 0 && getUseVBO()) // Do we have a VBO? { osgGlBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, getGLId()); } else if(o != NULL && o->getGLId() != 0 && o->getUseVBO()) { osgGlBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); } }
bool GeoVectorBufferRefProperty::unmapBuffer(DrawEnv *pEnv) { bool returnValue = true; if((getUseVBO() == true) && (getGLId() != 0)) { Window *pWin = pEnv->getWindow(); OSGGETGLFUNCBYID( OSGglBindBufferARB, osgGlBindBufferARB, _funcBindBuffer, pWin); OSGGETGLFUNCBYID( OSGglUnmapBufferARB, osgGlUnmapBufferARB, _funcUnmapBuffer, pWin); osgGlBindBufferARB(GL_ARRAY_BUFFER_ARB, getGLId()); returnValue = osgGlUnmapBufferARB(GL_ARRAY_BUFFER_ARB); osgGlBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } return returnValue; }
void CubeTextureObjChunk::onDestroy(UInt32 uiContainerId) { if(getGLId() > 0) Window::destroyGLObject(getGLId(), 1); // skip TextureObjChunk::onDestroy TextureBaseChunk::onDestroy(uiContainerId); }
void GeoMultiPropertyData::onDestroy(UInt32 uiContainerId) { if(getGLId() > 0) { Window::destroyGLObject(getGLId(), 1); } Inherited::onDestroy(uiContainerId); }
std::string Shader::getSource() const { GLint sourceLength; glGetShaderiv( getGLId(), GL_SHADER_SOURCE_LENGTH, &sourceLength ); std::vector<char> source( sourceLength ); glGetShaderSource( getGLId(), sourceLength, nullptr, source.data() ); return( source.data() ); }
void GeoVectorBufferProperty::onDestroy(UInt32 uiContainerId) { if(getGLId() > 0) { Window::destroyGLObject(getGLId(), 1); } Inherited::onDestroy(uiContainerId); }
std::pair<GLenum,std::vector<char>> Program::getBinary() const { GLint binaryLength(0); glGetProgramiv( getGLId(), GL_PROGRAM_BINARY_LENGTH, &binaryLength ); GLenum binaryFormat(0); std::vector<char> binary(binaryLength); glGetProgramBinary( getGLId(), binaryLength, nullptr, &binaryFormat, binary.data() ); return( std::make_pair( binaryFormat, binary ) ); }
void ComputeShaderChunk::changeFrom(DrawEnv *pEnv, StateChunk *pOther, UInt32 uiIdx) { ComputeShaderChunk *pOld = dynamic_cast<ComputeShaderChunk *>(pOther); // pOther can be a ShaderExecutableChunk, since we share the StateClass id // with it if(pOld != NULL) { Window *pWin = pEnv->getWindow(); GLuint uiProgId = GLuint(pWin->getGLObjectId(getGLId())); UInt32 uiDep = ShaderProcVariable::SHDObject; if(uiProgId != pEnv->getActiveShader()) { UInt32 uiValRes = pWin->validateGLObject(getGLId(), pEnv, KeepProgActive); uiProgId = GLuint(pWin->getGLObjectId(getGLId())); if(uiProgId == 0) return; pEnv->setActiveShader(uiProgId); if(0x0000 == (uiValRes & ProgActive)) { OSGGETGLFUNCBYID_GL3_ES(glUseProgram, osgGlUseProgram, ShaderProgram::getFuncIdUseProgram(), pWin); osgGlUseProgram(uiProgId); } uiDep = ShaderProcVariable::SHDAll; pEnv->incNumShaderChanges(); } updateProceduralVariables(pEnv, uiDep); } else { pOther->deactivate(pEnv, uiIdx); activate (pEnv, uiIdx); pEnv->incNumShaderChanges(); } }
void ProgramChunk::changed(BitVector whichField, UInt32 origin) { Inherited::changed(whichField, origin); if(whichField & ProgramFieldMask) { Window::reinitializeGLObject(getGLId()); } if(whichField & ParamValuesFieldMask) { Window::refreshGLObject(getGLId()); } }
void RenderBuffer::bind(DrawEnv *pEnv, UInt32 index) { Window *pWindow = pEnv->getWindow(); pWindow->validateGLObject(getGLId(), pEnv); OSGGETGLFUNC( OSGglFramebufferRenderbufferProc, osgGlFramebufferRenderbufferProc, _uiFuncFramebufferRenderbuffer ); osgGlFramebufferRenderbufferProc(GL_FRAMEBUFFER_EXT, index, GL_RENDERBUFFER_EXT, pWindow->getGLObjectId(getGLId())); }
Program::Uniforms Program::getActiveBufferVariables( std::vector<GLuint> const & locationIndices ) { Program::Uniforms uniforms; GLint numActiveVariables; glGetProgramInterfaceiv( getGLId(), GL_BUFFER_VARIABLE, GL_ACTIVE_RESOURCES, &numActiveVariables ); for ( size_t idx = 0; idx < locationIndices.size(); ++idx ) { GLuint index = locationIndices[idx]; GLenum const properties[] = { GL_NAME_LENGTH // 0 , GL_BLOCK_INDEX // 1 , GL_TYPE // 2 , GL_ARRAY_SIZE // 3 , GL_OFFSET // 4 , GL_ARRAY_STRIDE // 5 , GL_MATRIX_STRIDE// 6 , GL_IS_ROW_MAJOR // 7 }; GLsizei const numProperties = sizeof dp::util::array(properties); GLint values[numProperties]; glGetProgramResourceiv( getGLId(), GL_BUFFER_VARIABLE, index, numProperties, properties, numProperties, NULL, values ); Uniform uniform; // get uniform name uniform.name.resize(values[0]); glGetProgramResourceName( getGLId(), GL_BUFFER_VARIABLE, index, GLsizei(uniform.name.size()), NULL, &uniform.name[0]); uniform.blockIndex = values[1]; uniform.uniformLocation = -1; uniform.type = values[2]; uniform.arraySize = values[3]; uniform.offset = values[4]; uniform.arrayStride = values[5]; uniform.matrixStride = values[6]; uniform.isRowMajor = (values[7] != 0); uniforms[uniform.name] = uniform; } return uniforms; }
void GeoIntegralBufferRefProperty::activate(DrawEnv *pEnv, UInt32 slot) { Window *win = pEnv->getWindow(); if(!win->hasExtension(_extVertexBufferObject)) return; if(getGLId() != 0 && getUseVBO()) // Do we have a VBO? { OSGGETGLFUNCBYID( OSGglBindBufferARB, osgGlBindBufferARB, _funcBindBuffer, win); osgGlBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, getGLId()); } }
void ShaderProgram::onDestroy(UInt32 uiId) { if(GlobalSystemState == OSG::Running) { _pProgIdPool->release(_uiProgId); if(getGLId() > 0) Window::destroyGLObject(getGLId(), 1); } else if(GlobalSystemState == OSG::Shutdown) { delete _pProgIdPool; _pProgIdPool = NULL; } Inherited::onDestroy(uiId); }
void RenderBuffer::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(0x0000 != (whichField & (WidthFieldMask | HeightFieldMask))) { Window::reinitializeGLObject(getGLId()); } }
void Renderbuffer::resize( int width, int height ) { if ( m_width != width || m_height != height ) { m_width = width; m_height = height; glBindRenderbuffer( GL_RENDERBUFFER_EXT, getGLId() ); (this->*m_resizeFunc)(); glBindRenderbuffer( GL_RENDERBUFFER_EXT, 0 ); } }
Renderbuffer::~Renderbuffer() { class CleanupTask : public ShareGroupTask { public: CleanupTask( GLuint id ) : m_id( id ) {} virtual void execute() { glDeleteRenderbuffers( 1, &m_id ); } private: GLuint m_id; }; if ( getGLId() && getShareGroup() ) { // make destructor exception safe try { getShareGroup()->executeTask( new CleanupTask( getGLId() ) ); } catch (...) {} } }
Program::Uniforms Program::getActiveUniforms() { GLint numActiveUniforms; glGetProgramInterfaceiv( getGLId(), GL_UNIFORM, GL_ACTIVE_RESOURCES, &numActiveUniforms ); std::vector<GLuint> indices; indices.resize(numActiveUniforms); for (GLint index = 0;index < numActiveUniforms;++index) { indices[index] = index; } return getActiveUniforms(indices); }
Program::Uniforms Program::getActiveBufferVariables() { GLint numActiveVariables; glGetProgramInterfaceiv( getGLId(), GL_BUFFER_VARIABLE, GL_ACTIVE_RESOURCES, &numActiveVariables ); std::vector<GLuint> indices; indices.resize(numActiveVariables); for (GLint index = 0;index < numActiveVariables;++index) { indices[index] = index; } return getActiveBufferVariables(indices); }
void ComputeShaderChunk::deactivate(DrawEnv *pEnv, UInt32 uiIdx) { if(pEnv->getWindow()->getGLObjectId(getGLId()) == 0) return; pEnv->setActiveShader(0); OSGGETGLFUNC_GL3_ES(glUseProgram, osgGlUseProgram, ShaderProgram::getFuncIdUseProgram()); osgGlUseProgram(0); }
Program::Uniforms Program::getActiveBufferVariables( std::vector<std::string> const & names ) { std::vector<GLuint> indices; indices.reserve(names.size()); for ( size_t idx = 0; idx < names.size(); ++idx ) { GLuint locationIndex = glGetProgramResourceIndex( getGLId(), GL_BUFFER_VARIABLE, names[idx].c_str() ); if ( locationIndex != GL_INVALID_INDEX ) { indices.push_back(GLuint(locationIndex)); } } return getActiveBufferVariables( indices ); }
Program::Uniforms Program::getActiveUniforms( std::vector<std::string> const & uniformNames ) { std::vector<GLuint> indices; indices.reserve(uniformNames.size()); for ( size_t idx = 0; idx < uniformNames.size(); ++idx ) { GLuint locationIndex = glGetProgramResourceIndex( getGLId(), GL_UNIFORM, uniformNames[idx].c_str() ); if ( locationIndex != GL_INVALID_INDEX ) { indices.push_back(GLuint(locationIndex)); } } return getActiveUniforms( indices ); }
Shader::~Shader( ) { if ( getGLId() ) { if ( getShareGroup() ) { DEFINE_PTR_TYPES( CleanupTask ); class CleanupTask : public ShareGroupTask { public: static CleanupTaskSharedPtr create( GLuint id ) { return( std::shared_ptr<CleanupTask>( new CleanupTask( id ) ) ); } virtual void execute() { glDeleteShader( m_id ); } protected: CleanupTask( GLuint id ) : m_id( id ) {} private: GLuint m_id; }; // make destructor exception safe try { getShareGroup()->executeTask( CleanupTask::create( getGLId() ) ); } catch (...) {} } else { glDeleteShader( getGLId() ); } } }
void ShaderExecutableChunk::deactivate(DrawEnv *pEnv, UInt32 uiIdx) { if(pEnv->getWindow()->getGLObjectId(getGLId()) == 0) return; OSGGETGLFUNC(OSGglUseProgramProc, osgGlUseProgram, ShaderProgram::getFuncIdUseProgram()); if(_sfPointSize.getValue() == true) { glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); } pEnv->setActiveShader(0); pEnv->subRequiredOGLFeature(HardwareContext::HasAttribAliasing); osgGlUseProgram (0); }