C++ (Cpp) glFramebufferRenderbuffer Examples - HotExamples

文章推薦指數: 80 %
投票人數:10人

C++ (Cpp) glFramebufferRenderbuffer - 30 examples found. These are the top rated real world C++ (Cpp) examples of glFramebufferRenderbuffer extracted from ... Togglenavigation HotExamplesENENRUDEFRESPTITJPZH C++PHPC#JavaGoC++PythonJSTS SearchC++(Cpp)glFramebufferRenderbufferExamplesC++(Cpp)glFramebufferRenderbuffer-30examplesfound.ThesearethetopratedrealworldC++(Cpp)examplesofglFramebufferRenderbufferextractedfromopensourceprojects.Youcanrateexamplestohelpusimprovethequalityofexamples.ProgrammingLanguage:C++(Cpp)Method/Function:glFramebufferRenderbufferExamplesathotexamples.com:30reportthisadRelatedassert_int_equalNextTokenjiddata_blob_free__wt_calloc_defDbgPrintprintArraystrcat_sdo_loggcry_sexp_releasereportthisadRelatedinlangscleanblog_categorized_blog(PHP)dialog_buttondef(PHP)Playlist(C#)WebSocketClient(C#)ge_p3_0(Go)session_write_data(Go)AnonymousFunctionDescriptor(Java)Destination(Java)makeService(Python)logDebug(Python)Example#10ShowfileFile: ibex.cpp Project: heropunch/cyberdeck//--------------------------------------------------------------------------- //Function:prep_framebuffers //Design:BelongstoOpenGLcomponent //Purpose: //Updated:Sep10,2012 //--------------------------------------------------------------------------- voidprep_framebuffers() { if(!GL_ARB_framebuffer_object|| !glewGetExtension("GL_ARB_framebuffer_object")){ std::cerr<lightPositions; lightPositions.push_back(glm::vec3(0.0f,0.0f,49.5f));//backlight lightPositions.push_back(glm::vec3(-1.4f,-1.9f,9.0f)); lightPositions.push_back(glm::vec3(0.0f,-1.8f,4.0f)); lightPositions.push_back(glm::vec3(0.8f,-1.7f,6.0f)); //colors std::vector<:vec3>lightColors; lightColors.push_back(glm::vec3(200.0f,200.0f,200.0f)); lightColors.push_back(glm::vec3(0.1f,0.0f,0.0f)); lightColors.push_back(glm::vec3(0.0f,0.0f,0.2f)); lightColors.push_back(glm::vec3(0.0f,0.1f,0.0f)); //shaderconfiguration //-------------------- shader.use(); shader.setInt("diffuseTexture",0); hdrShader.use(); hdrShader.setInt("hdrBuffer",0); //renderloop //----------- while(!glfwWindowShouldClose(window)) { //per-frametimelogic //-------------------- floatcurrentFrame=glfwGetTime(); deltaTime=currentFrame-lastFrame; lastFrame=currentFrame; //input //----- processInput(window); //render //------ glClearColor(0.1f,0.1f,0.1f,1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //1.rendersceneintofloatingpointframebuffer //----------------------------------------------- glBindFramebuffer(GL_FRAMEBUFFER,hdrFBO); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glm::mat4projection=glm::perspective(camera.Zoom,(GLfloat)SCR_WIDTH/(GLfloat)SCR_HEIGHT,0.1f,100.0f); glm::mat4view=camera.GetViewMatrix(); shader.use(); shader.setMat4("projection",projection); shader.setMat4("view",view); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,woodTexture); //setlightinguniforms for(unsignedinti=0;i(&Context::Instance().RenderFactoryInstance().RenderEngineInstance()); if(glloader_GLES_VERSION_3_0()&&((sample_count_>1)&&!IsCompressedFormat(format_)&&(glloader_GLES_EXT_texture_rg()||(4==NumComponents(format_))))) { GLuintfbo_src,fbo_dst; re.GetFBOForBlit(fbo_src,fbo_dst); GLuintold_fbo=re.BindFramebuffer(); glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo_src); if(array_size_>1) { glFramebufferTextureLayer(GL_READ_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,texture_,src_level,src_array_index); } else { if(sample_count_<=1) { glFramebufferTexture2D(GL_READ_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,target_type_,texture_,src_level); } else { glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,texture_); } } glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fbo_dst); if(target.ArraySize()>1) { glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,texture_,dst_level,dst_array_index*6+dst_face-CF_Positive_X); } else { glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_POSITIVE_X+dst_face,checked_cast(&target)->GLTexture(),dst_level); } glBlitFramebuffer(src_x_offset,src_y_offset,src_x_offset+src_width,src_y_offset+src_height, dst_x_offset,dst_y_offset,dst_x_offset+dst_width,dst_y_offset+dst_height, GL_COLOR_BUFFER_BIT,((src_width==dst_width)&&(src_height==dst_height))?GL_NEAREST:GL_LINEAR); re.BindFramebuffer(old_fbo,true); } else { if((src_width==dst_width)&&(src_height==dst_height)&&(format_==target.Format())) { if(IsCompressedFormat(format_)) { BOOST_ASSERT((0==(src_x_offset&0x3))&&(0==(src_y_offset&0x3))); BOOST_ASSERT((0==(dst_x_offset&0x3))&&(0==(dst_y_offset&0x3))); BOOST_ASSERT((0==(src_width&0x3))&&(0==(src_height&0x3))); BOOST_ASSERT((0==(dst_width&0x3))&&(0==(dst_height&0x3))); Texture::Mappermapper_src(*this,src_array_index,src_level,TMA_Read_Only,src_x_offset,src_y_offset,src_width,src_height); Texture::Mappermapper_dst(target,dst_array_index,dst_face,dst_level,TMA_Write_Only,dst_x_offset,dst_y_offset,dst_width,dst_height); uint32_tconstblock_size=NumFormatBytes(format_)*4; uint8_tconst*s=mapper_src.Pointer(); uint8_t*d=mapper_dst.Pointer(); for(uint32_ty=0;y(); uint8_t*d=mapper_dst.Pointer(); for(uint32_ty=0;yResizeTextureCube(target,dst_array_index,dst_face,dst_level,dst_x_offset,dst_y_offset,dst_width,dst_height, src_array_index,CF_Positive_X,src_level,src_x_offset,src_y_offset,src_width,src_height,true); } } }Example#70ShowfileFile: main.cpp Project: Johnm95/GP2CourseWorkvoidcreateFramebuffer() { glActiveTexture(GL_TEXTURE0); glGenTextures(1,&FBOTexture); glBindTexture(GL_TEXTURE_2D,FBOTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,FRAME_BUFFER_WIDTH,FRAME_BUFFER_HEIGHT,0,GL_RGBA, GL_UNSIGNED_BYTE,NULL); glGenRenderbuffers(1,&FBODepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER,FBODepthBuffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT32,FRAME_BUFFER_WIDTH,FRAME_BUFFER_HEIGHT); glBindRenderbuffer(GL_RENDERBUFFER,0); glGenFramebuffers(1,&frameBufferObject); glBindFramebuffer(GL_FRAMEBUFFER,frameBufferObject); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,FBOTexture,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,FBODepthBuffer); GLenumstatus; if((status=glCheckFramebufferStatus(GL_FRAMEBUFFER))!=GL_FRAMEBUFFER_COMPLETE){ cout<native_fbo=false; fbo->width=width; fbo->height=height; fbo->colorDepth=colorDepth; //Colortextureissameeverywhere glGenFramebuffers(1,&fbo->handle); glGenTextures(1,&fbo->color_texture); //Createthesurfaces. glBindTexture(GL_TEXTURE_2D,fbo->color_texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //TODO:Wecouldopttoonlycreate16-bitrendertargetsonslowdevices.Forlater. switch(colorDepth){ caseFBO_8888: glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); break; caseFBO_4444: glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_SHORT_4_4_4_4,NULL); break; caseFBO_5551: glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_SHORT_5_5_5_1,NULL); break; caseFBO_565: glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,NULL); break; } glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); if(gl_extensions.IsGLES){ if(gl_extensions.OES_packed_depth_stencil){ ILOG("Creating%ix%iFBOusingDEPTH24_STENCIL8",width,height); //Standardmethod fbo->stencil_buffer=0; fbo->z_buffer=0; //24-bitZ,8-bitstencilcombined glGenRenderbuffers(1,&fbo->z_stencil_buffer); glBindRenderbuffer(GL_RENDERBUFFER,fbo->z_stencil_buffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8_OES,width,height); //Binditalltogether glBindFramebuffer(GL_FRAMEBUFFER,fbo->handle); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,fbo->color_texture,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,fbo->z_stencil_buffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,fbo->z_stencil_buffer); }else{ ILOG("Creating%ix%iFBOusingseparatestencil",width,height); //TEGRA fbo->z_stencil_buffer=0; //16/24-bitZ,separate8-bitstencil glGenRenderbuffers(1,&fbo->z_buffer); glBindRenderbuffer(GL_RENDERBUFFER,fbo->z_buffer); //Don'tforgettomakesurefbo_standard_z_depth()matches. glRenderbufferStorage(GL_RENDERBUFFER,gl_extensions.OES_depth24?GL_DEPTH_COMPONENT24:GL_DEPTH_COMPONENT16,width,height); //8-bitstencilbuffer glGenRenderbuffers(1,&fbo->stencil_buffer); glBindRenderbuffer(GL_RENDERBUFFER,fbo->stencil_buffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_STENCIL_INDEX8,width,height); //Binditalltogether glBindFramebuffer(GL_FRAMEBUFFER,fbo->handle); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,fbo->color_texture,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,fbo->z_buffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,fbo->stencil_buffer); } }else{ fbo->stencil_buffer=0; fbo->z_buffer=0; //24-bitZ,8-bitstencil glGenRenderbuffers(1,&fbo->z_stencil_buffer); glBindRenderbuffer(GL_RENDERBUFFER,fbo->z_stencil_buffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8,width,height); //Binditalltogether glBindFramebuffer(GL_FRAMEBUFFER,fbo->handle); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,fbo->color_texture,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,fbo->z_stencil_buffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,fbo->z_stencil_buffer); } GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); switch(status){ caseGL_FRAMEBUFFER_COMPLETE: //ILOG("Framebufferverifiedcomplete."); break; caseGL_FRAMEBUFFER_UNSUPPORTED: ELOG("GL_FRAMEBUFFER_UNSUPPORTED"); break; caseGL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: ELOG("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); break; default: FLOG("Otherframebuffererror:%i",status); break; } //Unbindstatewedon'tneed glBindRenderbuffer(GL_RENDERBUFFER,0); glBindTexture(GL_TEXTURE_2D,0); currentDrawHandle_=fbo->handle; currentReadHandle_=fbo->handle; returnfbo; }Example#90ShowfileFile: CCRenderTexture.cpp Project: osmely/CocosJuiceboolRenderTexture::initWithWidthAndHeight(intw,inth,Texture2D::PixelFormatformat,GLuintdepthStencilFormat) { CCASSERT(format!=Texture2D::PixelFormat::A8,"onlyRGBandRGBAformatsarevalidforarendertexture"); boolret=false; void*data=nullptr; do { _fullRect=_rtTextureRect=Rect(0,0,w,h); //Sizesize=Director::getInstance()->getWinSizeInPixels(); //_fullviewPort=Rect(0,0,size.width,size.height); w=(int)(w*CC_CONTENT_SCALE_FACTOR()); h=(int)(h*CC_CONTENT_SCALE_FACTOR()); _fullviewPort=Rect(0,0,w,h); glGetIntegerv(GL_FRAMEBUFFER_BINDING,&_oldFBO); //texturesmustbepoweroftwosquared intpowW=0; intpowH=0; if(Configuration::getInstance()->supportsNPOT()) { powW=w; powH=h; } else { powW=ccNextPOT(w); powH=ccNextPOT(h); } autodataLen=powW*powH*4; data=malloc(dataLen); CC_BREAK_IF(!data); memset(data,0,dataLen); _pixelFormat=format; _texture=new(std::nothrow)Texture2D(); if(_texture) { _texture->initWithData(data,dataLen,(Texture2D::PixelFormat)_pixelFormat,powW,powH,Size((float)w,(float)h)); } else { break; } GLintoldRBO; glGetIntegerv(GL_RENDERBUFFER_BINDING,&oldRBO); if(Configuration::getInstance()->checkForGLExtension("GL_QCOM")) { _textureCopy=new(std::nothrow)Texture2D(); if(_textureCopy) { _textureCopy->initWithData(data,dataLen,(Texture2D::PixelFormat)_pixelFormat,powW,powH,Size((float)w,(float)h)); } else { break; } } //generateFBO glGenFramebuffers(1,&_FBO); glBindFramebuffer(GL_FRAMEBUFFER,_FBO); //associatetexturewithFBO glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,_texture->getName(),0); if(depthStencilFormat!=0) { //createandattachdepthbuffer glGenRenderbuffers(1,&_depthRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER,_depthRenderBufffer); glRenderbufferStorage(GL_RENDERBUFFER,depthStencilFormat,(GLsizei)powW,(GLsizei)powH); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,_depthRenderBufffer); //ifdepthformatistheonewithstencilpart,bindsamerenderbufferasstencilattachment if(depthStencilFormat==GL_DEPTH24_STENCIL8) { glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,_depthRenderBufffer); } } //checkifitworked(probablyworthdoing:)) CCASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE,"Couldnotattachtexturetoframebuffer"); _texture->setAliasTexParameters(); //retained setSprite(Sprite::createWithTexture(_texture)); _texture->release(); _sprite->setFlippedY(true); _sprite->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED); glBindRenderbuffer(GL_RENDERBUFFER,oldRBO); glBindFramebuffer(GL_FRAMEBUFFER,_oldFBO); //Diabledbydefault. _autoDraw=false; //addspriteforbackwardcompatibility addChild(_sprite); ret=true; }while(0); CC_SAFE_FREE(data); returnret; }Example#100ShowfileFile: OgreGLES2FrameBufferObject.cpp Project: zester/MezzaninevoidGLES2FrameBufferObject::initialise() { //Releasedepthandstencil,iftheywerebound mManager->releaseRenderBuffer(mDepth); mManager->releaseRenderBuffer(mStencil); mManager->releaseRenderBuffer(mMultisampleColourBuffer); ///Firstbuffermustbebound if(!mColour[0].buffer) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attachment0musthavesurfaceattached", "GLES2FrameBufferObject::initialise"); } //Ifwe'redoingmultisampling,thenweneedanotherFBOwhichcontainsa //renderbufferwhichissetuptomultisample,andwe'llblitittothefinal //FBOafterwardstoperformthemultisampleresolve.Inthatcase,the //mMultisampleFBisboundduringrenderingandistheonewithadepth/stencil ushortmaxSupportedMRTs=Root::getSingleton().getRenderSystem()->getCapabilities()->getNumMultiRenderTargets(); ///Storebasicstats size_twidth=mColour[0].buffer->getWidth(); size_theight=mColour[0].buffer->getHeight(); GLuintformat=mColour[0].buffer->getGLFormat(); //Bindsimplebuffertoaddcolourattachments glBindFramebuffer(GL_FRAMEBUFFER,mFB); GL_CHECK_ERROR; ///Bindallattachmentpointstoframebuffer for(size_tx=0;xgetWidth()!=width||mColour[x].buffer->getHeight()!=height) { StringStreamss; ss<getWidth()<getHeight(); ss<getGLFormat()!=format) { StringStreamss; ss<bindToFramebuffer(GL_COLOR_ATTACHMENT0+x,mColour[x].zoffset); } else { //Detach glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+x,GL_RENDERBUFFER,0); GL_CHECK_ERROR; } } //Nowdealwithdepth/stencil if(mMultisampleFB) { //Bindmultisamplebuffer glBindFramebuffer(GL_FRAMEBUFFER,mMultisampleFB); GL_CHECK_ERROR; //CreateAArenderbuffer(colour) //note,thiscanbesharedtoobecauseweblitittothefinalFBO //rightaftertherenderisfinished mMultisampleColourBuffer=mManager->requestRenderBuffer(format,width,height,mNumSamples); //Attachit,becausewewon'tbeattachingbelowandnon-multisamplehas //actuallybeenattachedtootherFBO mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0, mMultisampleColourBuffer.zoffset); //depth&stencilwillbedealtwithbelow } GL_CHECK_ERROR; ///Depthbufferisnothandledhereanymore. ///SeeGLES2FrameBufferObject::attachDepthBuffer()&RenderSystem::setDepthBufferFor() GLenumbufs[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; for(size_tx=0;xgetConfiguration().apiVer.api==NvGLAPI::GL) ?"#version430\n":"#version310es\n"; CHECK_GL_ERROR(); { int32_tlen; //InitializeParticlesRenderProgram NvScopedShaderPrefixswitched(shaderPrefix); std::stringrenderPartVS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderPartVS.glsl"); std::stringrenderPartGS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderPartGS.glsl"); mParticlesRenderProg=newNvGLSLProgram; NvGLSLProgram::ShaderSourceItemsourcesP[2]; sourcesP[0].type=GL_VERTEX_SHADER; sourcesP[0].src=renderPartVS.c_str(); sourcesP[1].type=GL_FRAGMENT_SHADER; sourcesP[1].src=NvAssetLoaderRead("shaders/renderPartFS.glsl",len); mParticlesRenderProg->setSourceFromStrings(sourcesP,2); NvAssetLoaderFree((char*)sourcesP[1].src); //InitializeSurfaceRenderProgram std::stringrenderSurfVS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderSurfVS.glsl"); std::stringrenderSurfGS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderSurfGS.glsl"); std::stringrenderSurfFS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderSurfFS.glsl"); mSurfaceRenderProg=newNvGLSLProgram; NvGLSLProgram::ShaderSourceItemsourcesS[3]; sourcesS[0].type=GL_VERTEX_SHADER; sourcesS[0].src=renderSurfVS.c_str(); sourcesS[1].type=GL_GEOMETRY_SHADER_EXT; sourcesS[1].src=renderSurfGS.c_str(); sourcesS[2].type=GL_FRAGMENT_SHADER; sourcesS[2].src=renderSurfFS.c_str(); mSurfaceRenderProg->setSourceFromStrings(sourcesS,3); std::stringquadVS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderQuadVS.glsl"); std::stringquadFS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/renderQuadFS.glsl"); mQuadProg=newNvGLSLProgram; NvGLSLProgram::ShaderSourceItemsourcesQ[2]; sourcesQ[0].type=GL_VERTEX_SHADER; sourcesQ[0].src=quadVS.c_str(); sourcesQ[1].type=GL_FRAGMENT_SHADER; sourcesQ[1].src=quadFS.c_str(); mQuadProg->setSourceFromStrings(sourcesQ,2); std::stringblurVS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/blurVS.glsl"); std::stringblurFS=loadShaderSourceWithUniformTag("shaders/uniforms.h","shaders/blurFS.glsl"); mBlurProg=newNvGLSLProgram; NvGLSLProgram::ShaderSourceItemsourcesB[2]; sourcesB[0].type=GL_VERTEX_SHADER; sourcesB[0].src=blurVS.c_str(); sourcesB[1].type=GL_FRAGMENT_SHADER; sourcesB[1].src=blurFS.c_str(); mBlurProg->setSourceFromStrings(sourcesB,2); } CHECK_GL_ERROR(); //Setupcubemapforskybox mSkyBoxTexID=NvImageGL::UploadTextureFromDDSFile("textures/sky_cube.dds"); glBindTexture(GL_TEXTURE_CUBE_MAP,mSkyBoxTexID); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glBindTexture(GL_TEXTURE_CUBE_MAP,0); CHECK_GL_ERROR(); //Initializeskyboxforscreenquad mScreenQuadPos=newShaderBuffer<:vec4f>(4); vec4f*pos=mScreenQuadPos->map(); pos[0]=vec4f(-1.0f,-1.0f,-1.0f,1.0f); pos[1]=vec4f(1.0f,-1.0f,-1.0f,1.0f); pos[2]=vec4f(-1.0f,1.0f,-1.0f,1.0f); pos[3]=vec4f(1.0f,1.0f,-1.0f,1.0f); mScreenQuadPos->unmap(); //createuboandinitializeitwiththestructuredata glGenBuffers(1,&mUBO); glBindBuffer(GL_UNIFORM_BUFFER,mUBO); glBufferData(GL_UNIFORM_BUFFER,sizeof(ShaderParams),&mShaderParams,GL_STREAM_DRAW); CHECK_GL_ERROR(); //createsimplesingle-vertexVBO floatvtx_data[]={0.0f,0.0f,0.0f,1.0f}; glGenBuffers(1,&mVBO); glBindBuffer(GL_ARRAY_BUFFER,mVBO); glBufferData(GL_ARRAY_BUFFER,sizeof(vtx_data),vtx_data,GL_STATIC_DRAW); CHECK_GL_ERROR(); //Fornow,scalebacktheparticlecountonmobile. //int32_tparticleCount=isMobilePlatform()?(mNumParticles>>2):mNumParticles; int32_tparticleCount=mNumParticles; mParticles=newParticleSystem(particleCount,shaderPrefix); CHECK_GL_ERROR(); intcx,cy,cz; glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT,0,&cx); glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT,1,&cy); glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT,2,&cz); LOGI("Maxcomputeworkgroupcount=%d,%d,%d\n",cx,cy,cz); intsx,sy,sz; glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE,0,&sx); glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE,1,&sy); glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE,2,&sz); LOGI("Maxcomputeworkgroupsize=%d,%d,%d\n",sx,sy,sz); CHECK_GL_ERROR(); //Setclockwisewinding glFrontFace(GL_CW); //Texture constintscreen_width=getAppContext()->width(); constintscreen_height=getAppContext()->height(); //Framebufferforfinalscene glGenTextures(gbuffer_size,gbuffer_tex); glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); for(inti=0;i(&p_pRenderBuffer); //Gettheformat Texture::ePixelFormatformat=pOpenGLRenderbuffer->GetPixelFormat(); //Gettherightattachmenttype. GLenumattachment=g_OpenGLFrambufferAttachments[format]; //Incementtheattachmentdependingonthetype if(attachment==GL_COLOR_ATTACHMENT0) { //FIXTHISERRORCHECK! if(m_ColorAttachmentCount>15) { bitLogGraErr("Attachedtoomanycolorattachments."); returnfalse; } //Incrementtheattachmentandthecolorattachmentcounter attachment+=m_ColorAttachmentCount; m_ColorAttachmentCount++; } elseif(attachment==GL_DEPTH_ATTACHMENT||attachment==GL_DEPTH_STENCIL_ATTACHMENT) { if(m_DepthAttached) { bitLogGraErr("Attachedtoomanydepth/stencilattachments."); returnfalse; } //Incrementthedepthattachmentcounter m_DepthAttached=true; } //Generatetheframebufferobjectifnecessary if(m_FramebufferObject==0) { glGenFramebuffers(1,&m_FramebufferObject); } //Bindtheframebuffer glBindFramebuffer(GL_FRAMEBUFFER,m_FramebufferObject); //Attachtherenderbuffer glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,attachment,GL_RENDERBUFFER_EXT,pOpenGLRenderbuffer->GetId()); //Checktheframebufferstatus! GLenumFramebufferStatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(FramebufferStatus!=GL_FRAMEBUFFER_COMPLETE) { glBindFramebuffer(GL_FRAMEBUFFER,0); bitLogGraErr("Framebuffererror."); returnfalse; } //Unbindtheframebuffer glBindFramebuffer(GL_FRAMEBUFFER,0); //Succeeded returntrue; }Example#160ShowfileFile: CCRenderTexture.cpp Project: cheerayhuang/cocos2d-xboolCCRenderTexture::initWithWidthAndHeight(intw,inth,CCTexture2DPixelFormateFormat,GLuintuDepthStencilFormat) { CCAssert(eFormat!=kCCTexture2DPixelFormat_A8,"onlyRGBandRGBAformatsarevalidforarendertexture"); boolbRet=false; void*data=NULL; do { w=(int)(w*CC_CONTENT_SCALE_FACTOR()); h=(int)(h*CC_CONTENT_SCALE_FACTOR()); glGetIntegerv(GL_FRAMEBUFFER_BINDING,&m_nOldFBO); //texturesmustbepoweroftwosquared unsignedintpowW=0; unsignedintpowH=0; if(CCConfiguration::sharedConfiguration()->supportsNPOT()) { powW=w; powH=h; } else { powW=ccNextPOT(w); powH=ccNextPOT(h); } data=malloc((int)(powW*powH*4)); CC_BREAK_IF(!data); memset(data,0,(int)(powW*powH*4)); m_ePixelFormat=eFormat; m_pTexture=newCCTexture2D(); if(m_pTexture) { m_pTexture->initWithData(data,(CCTexture2DPixelFormat)m_ePixelFormat,powW,powH,CCSizeMake((float)w,(float)h)); } else { break; } GLintoldRBO; glGetIntegerv(GL_RENDERBUFFER_BINDING,&oldRBO); if(CCConfiguration::sharedConfiguration()->checkForGLExtension("GL_QCOM")) { m_pTextureCopy=newCCTexture2D(); if(m_pTextureCopy) { m_pTextureCopy->initWithData(data,(CCTexture2DPixelFormat)m_ePixelFormat,powW,powH,CCSizeMake((float)w,(float)h)); } else { break; } } //generateFBO glGenFramebuffers(1,&m_uFBO); glBindFramebuffer(GL_FRAMEBUFFER,m_uFBO); //associatetexturewithFBO glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_pTexture->getName(),0); if(uDepthStencilFormat!=0) { //createandattachdepthbuffer glGenRenderbuffers(1,&m_uDepthRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER,m_uDepthRenderBufffer); glRenderbufferStorage(GL_RENDERBUFFER,uDepthStencilFormat,(GLsizei)powW,(GLsizei)powH); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,m_uDepthRenderBufffer); //ifdepthformatistheonewithstencilpart,bindsamerenderbufferasstencilattachment if(uDepthStencilFormat==GL_DEPTH24_STENCIL8) { glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,m_uDepthRenderBufffer); } } //checkifitworked(probablyworthdoing:)) CCAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE,"Couldnotattachtexturetoframebuffer"); m_pTexture->setAliasTexParameters(); //retained setSprite(CCSprite::createWithTexture(m_pTexture)); m_pTexture->release(); m_pSprite->setScaleY(-1); ccBlendFunctBlendFunc={GL_ONE,GL_ONE_MINUS_SRC_ALPHA}; m_pSprite->setBlendFunc(tBlendFunc); glBindRenderbuffer(GL_RENDERBUFFER,oldRBO); glBindFramebuffer(GL_FRAMEBUFFER,m_nOldFBO); //Diabledbydefault. m_bAutoDraw=false; //addspriteforbackwardcompatibility addChild(m_pSprite); bRet=true; }while(0); CC_SAFE_FREE(data); returnbRet; }Example#170ShowfileFile: formats.c Project: Jul13t/piglitstaticenumpiglit_result run_multisample_test(structtexture_format*src_format, structtexture_format*dst_format) { boolpass=true; intfbo_width,fbo_height; GLuintfbo,rb,src_tex,dst_tex,res_tex; staticconstGLfloatverts[]={ 0.0,0.0, 0.0,1.0, 1.0,1.0, 1.0,1.0, 1.0,0.0, 0.0,0.0 }; /*Uploadthesource,destination,andexpectedresult*/ src_tex=piglit_multisample_texture(GL_TEXTURE_2D_MULTISAMPLE,0, src_format->internal_format, TEX_SIZE,TEX_SIZE,1,samples, src_format->format, src_format->data_type,src_data); dst_tex=piglit_multisample_texture(GL_TEXTURE_2D_MULTISAMPLE,0, dst_format->internal_format, TEX_SIZE,TEX_SIZE,1,samples, dst_format->format, dst_format->data_type,dst_data); res_tex=piglit_multisample_texture(GL_TEXTURE_2D_MULTISAMPLE,0, dst_format->internal_format, TEX_SIZE,TEX_SIZE,1,samples, dst_format->format, dst_format->data_type,res_data); pass&=piglit_check_gl_error(GL_NO_ERROR); /*Ifanyofthesearezero,buttherewasnoerror,thenitmust *notberenderable,sowejustskipwithoutevenreportingthe *subtest. */ if((src_tex==0||dst_tex==0||res_tex==0)&&pass) returnPIGLIT_SKIP; glCopyImageSubData(src_tex,GL_TEXTURE_2D_MULTISAMPLE,0, TEX_SIZE/4,TEX_SIZE/4,0, dst_tex,GL_TEXTURE_2D_MULTISAMPLE,0, TEX_SIZE/4,TEX_SIZE/4,0, TEX_SIZE/2,TEX_SIZE/2,1); pass&=piglit_check_gl_error(GL_NO_ERROR); glCopyImageSubData(dst_tex,GL_TEXTURE_2D_MULTISAMPLE,0, 0,TEX_SIZE/2,0, dst_tex,GL_TEXTURE_2D_MULTISAMPLE,0, TEX_SIZE/2,0,0, TEX_SIZE/2,TEX_SIZE/2,1); pass&=piglit_check_gl_error(GL_NO_ERROR); if(piglit_automatic){ fbo_width=TEX_SIZE; fbo_height=TEX_SIZE; glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA, fbo_width,fbo_height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,rb); }else{ fbo_width=piglit_width; fbo_height=piglit_height; glBindFramebuffer(GL_FRAMEBUFFER,piglit_winsys_fbo); } pass&=piglit_check_gl_error(GL_NO_ERROR); glViewport(0,0,fbo_width,fbo_height); glClearColor(1.0f,0.0f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); /*Nowweuseacomparisonshadertochecktoseeifthe *destinationmatchestheexpectedresult. */ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,dst_tex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,res_tex); load_compare_program(dst_format); pass&=piglit_check_gl_error(GL_NO_ERROR); glEnableVertexAttribArray(0); glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,verts); glDrawArrays(GL_TRIANGLES,0,6); glDisableVertexAttribArray(0); pass&=piglit_check_gl_error(GL_NO_ERROR); /*Ifthedestinationtexturematchestheexpectedresult,we *shouldgetgreen.Ifnot,wegetredandthistestfails. */ pass&=piglit_probe_rect_rgb(0,0,fbo_width,fbo_height,green); glDeleteTextures(1,&src_tex); glDeleteTextures(1,&dst_tex); glDeleteTextures(1,&res_tex); if(!piglit_automatic) piglit_present_results(); returnpass?PIGLIT_PASS:PIGLIT_FAIL; }Example#180ShowfileFile: OgreGLES2FrameBufferObject.cpp Project: yiliu1203/OGREvoidGLES2FrameBufferObject::initialise() { GLES2RenderSystem*rs=getGLES2RenderSystem(); assert(mContext==rs->_getCurrentContext()); //Releasedepthandstencil,iftheywerebound mManager->releaseRenderBuffer(mDepth); mManager->releaseRenderBuffer(mStencil); mManager->releaseRenderBuffer(mMultisampleColourBuffer); //Firstbuffermustbebound if(!mColour[0].buffer) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attachment0musthavesurfaceattached", "GLES2FrameBufferObject::initialise"); } //Ifwe'redoingmultisampling,thenweneedanotherFBOwhichcontainsa //renderbufferwhichissetuptomultisample,andwe'llblitittothefinal //FBOafterwardstoperformthemultisampleresolve.Inthatcase,the //mMultisampleFBisboundduringrenderingandistheonewithadepth/stencil //Storebasicstats uint32width=mColour[0].buffer->getWidth(); uint32height=mColour[0].buffer->getHeight(); GLuintformat=mColour[0].buffer->getGLFormat(); ushortmaxSupportedMRTs=rs->getCapabilities()->getNumMultiRenderTargets(); //Bindsimplebuffertoaddcolourattachments OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER,mFB)); boolisDepth=PixelUtil::isDepth(getFormat()); //Bindallattachmentpointstoframebuffer for(unsignedintx=0;xgetWidth()!=width||mColour[x].buffer->getHeight()!=height) { StringStreamss; ss<getWidth()<getHeight(); ss<getGLFormat()!=format) { StringStreamss; ss<bindToFramebuffer( isDepth?GL_DEPTH_ATTACHMENT:(GL_COLOR_ATTACHMENT0+x),mColour[x].zoffset); } else { //Detach OGRE_CHECK_GL_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER,static_cast(GL_COLOR_ATTACHMENT0+x),GL_RENDERBUFFER,0)); } } //Nowdealwithdepth/stencil if(mMultisampleFB) { //Bindmultisamplebuffer OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER,mMultisampleFB)); //CreateAArenderbuffer(colour) //note,thiscanbesharedtoobecauseweblitittothefinalFBO //rightaftertherenderisfinished mMultisampleColourBuffer=mManager->requestRenderBuffer(format,width,height,mNumSamples); //Attachit,becausewewon'tbeattachingbelowandnon-multisamplehas //actuallybeenattachedtootherFBO mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0, mMultisampleColourBuffer.zoffset); //depth&stencilwillbedealtwithbelow } //Depthbufferisnothandledhereanymore. //SeeGLES2FrameBufferObject::attachDepthBuffer()&RenderSystem::setDepthBufferFor() if(rs->hasMinGLVersion(3,0)&&OGRE_PLATFORM!=OGRE_PLATFORM_EMSCRIPTEN)//EDonEmscripten { GLenumbufs[OGRE_MAX_MULTIPLE_RENDER_TARGETS]; GLsizein=0; for(unsignedintx=0;xmFBO); glBindFramebuffer(GL_FRAMEBUFFER,pFBOInfo->mFBO); //colorbufferforfbo glGenRenderbuffers(1,&pFBOInfo->mColorRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,pFBOInfo->mColorRenderBuffer); #ifdefined(WIN32)||defined(MACOS) glRenderbufferStorage(GL_RENDERBUFFER,GL_RGB8,iWidth,iHeight); #else glRenderbufferStorage(GL_RENDERBUFFER,GL_RGB8_OES,iWidth,iHeight); #endif//WIN32 glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,pFBOInfo->mColorRenderBuffer); //depthbufferforthefbo glGenRenderbuffers(1,&pFBOInfo->mDepthRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,pFBOInfo->mDepthRenderBuffer); #ifdefined(WIN32)||defined(MACOS) glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24,iWidth,iHeight); #else glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24_OES,iWidth,iHeight); #endif//WIN32 glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,pFBOInfo->mDepthRenderBuffer); //texture glGenTextures(1,&pFBOInfo->mTexture); glBindTexture(GL_TEXTURE_2D,pFBOInfo->mTexture); GLuintiGLFilterType=GL_NEAREST; if(iTextureFilter==FILTER_BILINEAR) { iGLFilterType=GL_LINEAR; } elseif(iTextureFilter==FILTER_NEAREST) { iGLFilterType=GL_NEAREST; } //attribute glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,iGLFilterType); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,iGLFilterType); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iWidth, iHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pFBOInfo->mTexture, 0); glBindFramebuffer(GL_FRAMEBUFFER,0); }Example#210ShowfileFile: RenderDepthToTextureES2.cpp Project: jason-amju/amjulibboolInit(intw,inth) { //Createaframebufferobject  glGenFramebuffers(1,fboId);  glBindFramebuffer(GL_FRAMEBUFFER,*fboId);  //Createarenderbuffer  glGenRenderbuffers(1,renderBuffer);  glBindRenderbuffer(GL_RENDERBUFFER,*renderBuffer);    //Createatextureforstoringthedepth  glGenTextures(1,depthTextureId);  glBindTexture(GL_TEXTURE_2D,*depthTextureId);  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);  //Removeartifactontheedgesoftheshadowmap  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);  Debug("glGetError()0=0x%x",glGetError());  if(m_hasDepthTextureExtension)  {    //We'lluseadepthtexturetostorethedepthsintheshadowmap    glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,width,height,0,           GL_DEPTH_COMPONENT,GL_UNSIGNED_INT,NULL);    //AttachthedepthtexturetoFBOdepthattachmentpoint    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,                GL_TEXTURE_2D,*depthTextureId,0);  }  else  {    //We'lluseaRGBAtextureintowhichwepackthedepthinfo    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,           GL_RGBA,GL_UNSIGNED_BYTE,NULL);    //AttachtheRGBAtexturetoFBOcolorattachmentpoint    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,                GL_TEXTURE_2D,*depthTextureId,0);    //Allocate16-bitdepthbuffer    glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,width,height);    //Attachtherenderbufferasdepthbuffer-willbeignored    glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,                 GL_RENDERBUFFER,*renderBuffer);  }  //checkFBOstatus  GLenumfboStatus=glCheckFramebufferStatus(GL_FRAMEBUFFER);  if(fboStatus!=GL_FRAMEBUFFER_COMPLETE)  {    Debug("FBOnotcomplete:0x%x",fboStatus);    returnfalse;  }  //Gobacktousingthedefaultframebuffer  glBindFramebuffer(GL_FRAMEBUFFER,DefaultFramebufferId);  returntrue; }Example#220ShowfileFile: webgl.cpp Project: cebu4u/TrickplayboolContext::try_create_fbo(GLsizeiwidth,GLsizeiheight,intflags) { tplog2("CREATINGFRAMEBUFFER"); GLuint fbo; GLuintSet rb; boolh_depth=false; boolh_stencil=false; glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,texture_target,texture,0); if(flags&FBO_TRY_DEPTH_STENCIL) { tplog2("CREATINGDEPTH/STENCILRENDERBUFFERS"); GLuintdepth_stencil_rb; glGenRenderbuffers(1,&depth_stencil_rb); glBindRenderbuffer(GL_RENDERBUFFER,depth_stencil_rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_STENCIL,width,height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,depth_stencil_rb); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth_stencil_rb); rb.insert(depth_stencil_rb); h_depth=true; h_stencil=true; } if(flags&FBO_TRY_DEPTH) { tplog2("CREATINGDEPTHRENDERBUFFER"); GLuintdepth_rb; glGenRenderbuffers(1,&depth_rb); glBindRenderbuffer(GL_RENDERBUFFER,depth_rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,width,height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth_rb); rb.insert(depth_rb); h_depth=true; } if(flags&FBO_TRY_STENCIL) { tplog2("CREATINGSTENCILRENDERBUFFER"); GLuintstencil_rb; glGenRenderbuffers(1,&stencil_rb); glBindRenderbuffer(GL_RENDERBUFFER,stencil_rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_STENCIL_INDEX8,width,height); glBindRenderbuffer(GL_RENDERBUFFER,0); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,stencil_rb); rb.insert(stencil_rb); h_stencil=true; } if(GL_FRAMEBUFFER_COMPLETE!=glCheckFramebufferStatus(GL_FRAMEBUFFER)) { glBindFramebuffer(GL_FRAMEBUFFER,0); tplog2("DESTROYINGFRAMEBUFFER%u",fbo); glDeleteFramebuffers(1,&fbo); for(GLuintSet::const_iteratorit=rb.begin();it!=rb.end();++it) { tplog2("DESTROYINGRENDERBUFFER%u",*it); glDeleteRenderbuffers(1,&*it); } tplog2("*FRAMEBUFFERISNOTCOMPLETE"); returnfalse; } tplog2("*FRAMEBUFFERISCOMPLETE"); framebuffer=fbo; renderbuffers.insert(rb.begin(),rb.end()); have_depth=h_depth; have_stencil=h_stencil; returntrue; }Example#230ShowfileFile: renderer.hpp Project: BJLinc/df-twbtvoidrenderer_cool::draw(intvertex_count) { staticboolinitial_resize=false; if(!initial_resize) { if(enabler->fullscreen) resize(size_x,size_y); else resize((size_x/init->font.small_font_dispx)*init->font.small_font_dispx,(size_y/init->font.small_font_dispy)*init->font.small_font_dispy); //resize(gps->dimx*init->font.small_font_dispx,gps->dimy*init->font.small_font_dispy); reshape_gl(); initial_resize=true; } staticdf::viewscreen*prevws=NULL; df::viewscreen*ws=Gui::getCurViewscreen(); is_main_scr=df::viewscreen_dwarfmodest::_identity.is_direct_instance(ws)||df::viewscreen_dungeonmodest::_identity.is_direct_instance(ws); if(ws!=prevws) { gps->force_full_display_count=1; prevws=ws; /*if(is_main_scr) { for(intx=1;xdimx-gmenu_w-1;x++) { for(inty=1;ydimy-1;y++) { constinttile1=x*gps->dimy+y; for(inti=0;i<6;i++) *(fg+tile*4*i+3)=0; } } }*/ } display_new(is_main_scr); #ifdefWIN32 //Wecan'tdothisinplugin_init()becauseOpenGLcontextisn'tinitializedbythattime staticboolglew_init=false; if(!glew_init) { GLenumerr=glewInit(); if(err!=GLEW_OK) *out2<dimx; old_dimy=gps->dimy; old_winx=*df::global::window_x; old_winy=*df::global::window_y; grid_resize(world->map.x_count+36,world->map.y_count+2); *df::global::window_x=0; *df::global::window_y=0; gps->force_full_display_count=1; } domapshot--; } GLuintframebuffer,renderbuffer; GLenumstatus; if(domapshot==5) { //Setthewidthandheightappropriatelyforyourimage GLuintimageWidth=gps->dimx*dispx, imageHeight=gps->dimy*dispy; //SetupaFBOwithonerenderbufferattachment glGenFramebuffers(1,&framebuffer); glBindFramebuffer(GL_FRAMEBUFFER,framebuffer); glGenRenderbuffers(1,&renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,renderbuffer); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA8,imageWidth,imageHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,renderbuffer); glViewport(0,0,gps->dimx*dispx,gps->dimy*dispy); /*glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,gps->dimx,gps->dimy,0,-1,1);*/ } if(is_main_scr) { boolskip=false; if(df::viewscreen_dungeonmodest::_identity.is_direct_instance(ws)) { intm=df::global::ui_advmode->menu; booltmode=advmode_needs_map(m); skip=!tmode; } if(!skip) { ///// glViewport(goff_x,goff_y_gl,gdimx*gdispx,gdimy*gdispy); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,gdimx,gdimy,0,-1,1); //glTranslatef(1,-1,0); //glScissor(off_x+(float)size_x/gps->dimx,off_y+(float)size_y/gps->dimy,gsize_x,gsize_y); //glEnable(GL_SCISSOR_TEST); //glClearColor(1,0,0,1); //glClear(GL_COLOR_BUFFER_BIT); if(multi_rendered&&fogdensity>0) { glEnable(GL_FOG); glFogfv(GL_FOG_COLOR,fogcolor); glFogf(GL_FOG_DENSITY,fogdensity); glFogi(GL_FOG_COORD_SRC,GL_FOG_COORD); glEnableClientState(GL_FOG_COORD_ARRAY); glFogCoordPointer(GL_FLOAT,0,fogcoord); } glVertexPointer(2,GL_FLOAT,0,gvertexes); //Renderbackgroundcolors glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_BLEND); glColorPointer(4,GL_FLOAT,0,gbg); glDrawArrays(GL_TRIANGLES,0,gdimx*gdimy*6); //Renderforeground glEnable(GL_TEXTURE_2D); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glTexCoordPointer(2,GL_FLOAT,0,gtex); glColorPointer(4,GL_FLOAT,0,gfg); glDrawArrays(GL_TRIANGLES,0,gdimx*gdimy*6); if(multi_rendered) { glDisableClientState(GL_FOG_COORD_ARRAY); glDisable(GL_FOG); } //Prepareandrendershadows if(multi_rendered) { intelemcnt=0; //TODO:don'tdothisifviewnotmovedandtileswithshadowsnotchanged { gl_texpos*txt=(gl_texpos*)enabler->textures.gl_texpos; intx1=std::min(gdimx,world->map.x_count-gwindow_x); inty1=std::min(gdimy,world->map.y_count-gwindow_y); for(inttile=0;tile0&&(depth[((xx-1)*gdimy+yy)])0&&(depth[((xx)*gdimy+yy-1)])0&&yy0&&yy>0&&(depth[((xx-1)*gdimy+yy-1)])0&&(depth[((xx+1)*gdimy+yy-1)])map.x_count*dispx; inth=world->map.y_count*dispy; unsignedchar*data=(unsignedchar*)malloc(w*h*3); glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_PACK_ROW_LENGTH,0); glReadPixels(dispx,dispy,w,h,GL_BGR,GL_UNSIGNED_BYTE,data); #pragmapack(push,1) typedefstruct_TgaHeader { unsignedcharIDLength;/*00hSizeofImageIDfield*/ unsignedcharColorMapType;/*01hColormaptype*/ unsignedcharImageType;/*02hImagetypecode*/ unsignedshortCMapStart;/*03hColormaporigin*/ unsignedshortCMapLength;/*05hColormaplength*/ unsignedcharCMapDepth;/*07hDepthofcolormapentries*/ unsignedshortXOffset;/*08hXoriginofimage*/ unsignedshortYOffset;/*0AhYoriginofimage*/ unsignedshortWidth;/*0ChWidthofimage*/ unsignedshortHeight;/*0EhHeightofimage*/ unsignedcharPixelDepth;/*10hImagepixelsize*/ unsignedcharImageDescriptor;/*11hImagedescriptorbyte*/ }TGAHEAD; #pragmapop TGAHEADhdr; memset(&hdr,0,sizeof(hdr)); hdr.ImageType=2; hdr.Width=w; hdr.Height=h; hdr.PixelDepth=24; *out2<force_full_display_count=1; domapshot=0; } }Example#240ShowfileFile: read-after-clear.c Project: BNieuwenhuizen/piglitvoid piglit_init(intargc,char**argv) { GLuintvs,fs_paint_red,fs_sample; GLenumfb_status; /*Parseparams*/ if(argc!=3) print_usage_and_exit(argv[0]); if(strcmp(argv[1],"sample")==0) subtest=SUBTEST_SAMPLE; elseif(strcmp(argv[1],"read_pixels")==0) subtest=SUBTEST_READ_PIXELS; elseif(strcmp(argv[1],"blit")==0) subtest=SUBTEST_BLIT; elseif(strcmp(argv[1],"copy")==0) subtest=SUBTEST_COPY; else print_usage_and_exit(argv[0]); if(strcmp(argv[2],"rb")==0) use_texture=false; elseif(strcmp(argv[2],"tex")==0) use_texture=true; else print_usage_and_exit(argv[0]); /*Detectparameterconflicts*/ if(subtest==SUBTEST_SAMPLE&&!use_texture){ printf("Subtest'sample'requiresbuffer_type'tex'.\n"); piglit_report_result(PIGLIT_FAIL); } /*Requirements*/ piglit_require_gl_version(11); piglit_require_GLSL_version(110); piglit_require_extension("GL_ARB_framebuffer_object"); /*Compileshaders*/ vs=piglit_compile_shader_text(GL_VERTEX_SHADER,vs_text); fs_paint_red=piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text_paint_red); prog_paint_red=piglit_link_simple_program(vs,fs_paint_red); if(!prog_paint_red) piglit_report_result(PIGLIT_FAIL); fs_sample=piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text_sample); prog_sample=piglit_link_simple_program(vs,fs_sample); if(!prog_sample) piglit_report_result(PIGLIT_FAIL); if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /*Setupframebuffer*/ glGenFramebuffers(1,&fb); glBindFramebuffer(GL_FRAMEBUFFER,fb); if(use_texture){ tex1=allocate_texture(); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,tex1,0/*level*/); }else{ GLuintrb; glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA, TEX_WIDTH,TEX_HEIGHT); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,rb); } if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); fb_status=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(fb_status!=GL_FRAMEBUFFER_COMPLETE){ printf("Framebufferstatus:%s\n", piglit_get_gl_enum_name(fb_status)); piglit_report_result(PIGLIT_FAIL); } /*Setupsecondtexture(usedby"copy"testonly)*/ if(subtest==SUBTEST_COPY) tex2=allocate_texture(); if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); }Example#250ShowfileFile: SolBufferObjects.cpp Project: gwthomas/sol-frameworkvoidFramebuffer::attachDepthBuffer(constRenderbuffer&rb) { bind(); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,rb.getHandle()); _depth=true; }Example#260ShowfileFile: learngl.cpp Project: Reshurum/learnglintmain(){ //InitializeGLFWandsetsomehintsthatwillcreateanOpenGL3.3context //usingcoreprofile. glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3); glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); //Createafixed800x600windowthatisnotresizable. GLFWwindow*window=glfwCreateWindow(kWindowWidth,kWindowHeight,"LearnGL",nullptr,nullptr); if(window==nullptr){ std::cerr<limitTime){ fovTime=limitTime; } //Updatetheperspectivetoaccountforchangesinfov. camera.fov=easeOutQuart(fovTime,startFov,(startFov-targetFov)*-1,limitTime); camera.update(); //BindtheVAOandshader. glBindVertexArray(VAO); shader.use(); //Passtheviewandprojectionmatricesfromthecamera. GLuintviewMatrix=glGetUniformLocation(shader.program,"view"); glUniformMatrix4fv(viewMatrix,1,GL_FALSE,glm::value_ptr(camera.view)); GLuintprojectionMatrix=glGetUniformLocation(shader.program,"projection"); glUniformMatrix4fv(projectionMatrix,1,GL_FALSE,glm::value_ptr(camera.projection)); //Generatelightcolors. glm::vec3lightColor(1.0f,1.0f,1.0f); //Directionallight glUniform3f(glGetUniformLocation(shader.program,"dirLight.direction"),-0.2f,-1.0f,-0.3f); glUniform3f(glGetUniformLocation(shader.program,"dirLight.ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"dirLight.diffuse"),0.4f,0.4f,0.4f); glUniform3f(glGetUniformLocation(shader.program,"dirLight.specular"),0.5f,0.5f,0.5f); //Pointlight1 glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].position"),pointLightPositions[0].x,pointLightPositions[0].y,pointLightPositions[0].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].diffuse"),1.0f,0.0f,0.0f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[0].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[0].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[0].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[0].quadratic"),0.032); //Pointlight2 glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].position"),pointLightPositions[1].x,pointLightPositions[1].y,pointLightPositions[1].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].diffuse"),0.0f,1.0f,0.0f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[1].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[1].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[1].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[1].quadratic"),0.032); //Pointlight3 glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].position"),pointLightPositions[2].x,pointLightPositions[2].y,pointLightPositions[2].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].diffuse"),0.0f,0.0f,1.0f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[2].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[2].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[2].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[2].quadratic"),0.032); //Pointlight4 glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].position"),pointLightPositions[3].x,pointLightPositions[3].y,pointLightPositions[3].z); glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].ambient"),0.05f,0.05f,0.05f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].diffuse"),0.8f,0.8f,0.8f); glUniform3f(glGetUniformLocation(shader.program,"pointLights[3].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[3].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"pointLights[3].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"pointLights[3].quadratic"),0.032); //Sportlight1 glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].position"),camera.position.x,camera.position.y,camera.position.z); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].direction"),camera.front.x,camera.front.y,camera.front.z); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].ambient"),0.0f,0.0f,0.0f); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].diffuse"),1.0f,1.0f,1.0f); glUniform3f(glGetUniformLocation(shader.program,"spotLights[0].specular"),1.0f,1.0f,1.0f); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].constant"),1.0f); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].linear"),0.09); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].quadratic"),0.032); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].cutoff"),glm::cos(glm::radians(12.5f))); glUniform1f(glGetUniformLocation(shader.program,"spotLights[0].outerCutoff"),glm::cos(glm::radians(15.5f))); //Passmaterialvalues. GLuintmaterialShininess=glGetUniformLocation(shader.program,"material.shininess"); GLuintmaterialDiffuse=glGetUniformLocation(shader.program,"material.diffuse"); GLuintmaterialSpecular=glGetUniformLocation(shader.program,"material.specular"); GLuintmaterialEmission=glGetUniformLocation(shader.program,"material.emission"); glUniform1f(materialShininess,64.0f); glUniform1i(materialDiffuse,0); glUniform1i(materialSpecular,1); glUniform1i(materialEmission,2); //Miscvalues. GLuintviewPos=glGetUniformLocation(shader.program,"viewPos"); glUniform3f(viewPos,camera.position.x,camera.position.y,camera.position.z); GLuinttime=glGetUniformLocation(shader.program,"time"); glUniform1f(time,glfwGetTime()); //Bindthetextures. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,containerTexture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,containerSpecular); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D,containerEmission); //Drawmultiplecontainers! GLuintmodelMatrix=glGetUniformLocation(shader.program,"model"); GLuintnormalMatrix=glGetUniformLocation(shader.program,"normalMatrix"); for(GLuinti=0;i<10;i++){ //Applyworldtransformations. model=glm::mat4(); model=glm::translate(model,cubePositions[i]); model=glm::rotate(model,i*20.0f,glm::vec3(1.0f,0.3f,0.5f)); glUniformMatrix4fv(modelMatrix,1,GL_FALSE,glm::value_ptr(model)); //CalculatethenormalmatrixontheCPU(keepthemnormalsperpendicular). normal=glm::mat3(glm::transpose(glm::inverse(model))); glUniformMatrix3fv(normalMatrix,1,GL_FALSE,glm::value_ptr(normal)); //Drawthecontainer. glDrawArrays(GL_TRIANGLES,0,36); } glBindVertexArray(0); //BindtheVAOandshader. glBindVertexArray(lightVAO); lampShader.use(); //Passtheviewandprojectionmatricesfromthecamera. viewMatrix=glGetUniformLocation(lampShader.program,"view"); glUniformMatrix4fv(viewMatrix,1,GL_FALSE,glm::value_ptr(camera.view)); projectionMatrix=glGetUniformLocation(lampShader.program,"projection"); glUniformMatrix4fv(projectionMatrix,1,GL_FALSE,glm::value_ptr(camera.projection)); for(GLuinti=0;i<4;i++){ //Applyworldtransformations. model=glm::mat4(); model=glm::translate(model,pointLightPositions[i]); model=glm::scale(model,glm::vec3(0.2f)); modelMatrix=glGetUniformLocation(lampShader.program,"model"); glUniformMatrix4fv(modelMatrix,1,GL_FALSE,glm::value_ptr(model)); //Drawthelamp. glDrawArrays(GL_TRIANGLES,0,36); } glBindVertexArray(0); //Drawsomethingwiththegeometryshaderprogram. //glDisable(GL_DEPTH_TEST); //gsShader.use(); //glBindVertexArray(pointsVAO); //glDrawArrays(GL_POINTS,0,4); //glBindVertexArray(0); //glEnable(GL_DEPTH_TEST); //Unbindtheoffscreenframebuffercontainingtheunprocessedframe. glBindFramebuffer(GL_FRAMEBUFFER,0); glClearColor(1.0f,1.0f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); postShader.use(); glBindVertexArray(frameVAO); //Sendthetexturesamplertotheshader. GLuintframeTexture=glGetUniformLocation(postShader.program,"frameTexture"); time=glGetUniformLocation(postShader.program,"time"); glUniform1i(frameTexture,0); glUniform1f(time,glfwGetTime()); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,frameColorBuffer); //Renderthecolorbufferintheframebuffertothequadwithpostshader. glDrawArrays(GL_TRIANGLES,0,6); glBindVertexArray(0); //Swapbuffersusedfordoublebuffering. glfwSwapBuffers(window); } //Destroytheoffscreenframebuffer. glBindFramebuffer(GL_FRAMEBUFFER,0); glDeleteFramebuffers(1,&FBO); //ProperlydeallocatetheVBOandVAO. glDeleteVertexArrays(1,&VAO); glDeleteBuffers(1,&VBO); //TerminateGLFWandcleananyresourcesbeforeexiting. glfwTerminate(); return0; }Example#270ShowfileFile: texture.cpp Project: ProPuke/openb3d.modvoidTexture::CameraToTex(Camera*cam,intframe){ GLenumtarget; Global::camera_in_use=cam; if(flags&128){ target=GL_TEXTURE_CUBE_MAP; }else{ target=GL_TEXTURE_2D; } glBindTexture(target,texture); if(framebuffer==0){ framebuffer=newunsignedint[1]; glGenFramebuffers(1,&framebuffer[0]); glGenRenderbuffers(1,&framebuffer[1]); if(flags&128){ for(inti=0;i<6;i++){ switch(i){ case0: glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); break; case1: glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); break; case2: glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); break; case3: glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); break; case4: glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); break; case5: glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); break; } } }else{ glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,0); } } glBindFramebuffer(GL_FRAMEBUFFER,framebuffer[0]); if(flags&128){ switch(cube_face){ case0: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,texture,0); break; case1: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_POSITIVE_Z,texture,0); break; case2: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_POSITIVE_X,texture,0); break; case3: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,texture,0); break; case4: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,texture,0); break; case5: glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,texture,0); break; } }else{ glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texture,0); } //Depthbuffer glBindRenderbuffer(GL_RENDERBUFFER,framebuffer[1]); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_STENCIL,width,height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,framebuffer[1]); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,framebuffer[1]); cam->Render(); if(Global::Shadows_enabled==true) ShadowObject::Update(cam); //glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,0); glBindTexture(target,texture);// glGenerateMipmap(target); glBindFramebuffer(GL_FRAMEBUFFER,0); glBindRenderbuffer(GL_RENDERBUFFER,0); }Example#280ShowfileFile: FrameBufferObject.cpp Project: slicedpan/GLUtilsFrameBufferObject::FrameBufferObject(intwidth,intheight,intdepthBufferBitDepth,intstencilBufferBitDepth,GLenumtextureFormat,GLenumtextureType,std::stringname) :width(width), height(height), textureFormat(textureFormat), textureType(textureType), texNum(0), nextIndex(0), Height(height), Width(width), Bound(bound) { if(!glGenFramebuffers) throw; bound=false; setDrawBuffers=false; if(name=="") { charbuf[64]; sprintf(buf,"unnamed%d",++nextIndex); this->name=buf; } else { this->name=name; } glGenFramebuffers(1,&glID); glBindFramebuffer(GL_FRAMEBUFFER,glID); if(depthBufferBitDepth||stencilBufferBitDepth) { GLenumformat=0; if(depthBufferBitDepth&&stencilBufferBitDepth) { if(depthBufferBitDepth==32&&stencilBufferBitDepth==8) format=GL_DEPTH32F_STENCIL8; else format=GL_DEPTH24_STENCIL8; GLuintid; glGenRenderbuffers(1,&id); renderBuffers.push_back(id); glBindRenderbuffer(GL_RENDERBUFFER,id); glRenderbufferStorage(GL_RENDERBUFFER,format,width,height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,id); } elseif(stencilBufferBitDepth==0) { if(depthBufferBitDepth==16) format=GL_DEPTH_COMPONENT16; elseif(depthBufferBitDepth==24) format=GL_DEPTH_COMPONENT24; else format=GL_DEPTH_COMPONENT32F; GLuintid; glGenRenderbuffers(1,&id); renderBuffers.push_back(id); glBindRenderbuffer(GL_RENDERBUFFER,id); glRenderbufferStorage(GL_RENDERBUFFER,format,width,height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,id); } } glBindFramebuffer(GL_FRAMEBUFFER,0); }Example#290ShowfileFile: fbo-missing-attachment-blit.c Project: janesma/piglitbool do_blit_test(booluse_es2,boolfrom_missing_to_complete) { GLuintrb[3]; GLuintfb[2]; GLenumstatus; GLenumerr; constunsignedsrc=from_missing_to_complete?0:1; constunsigneddst=1-src; constchar*constnames[]={ "bufferwithmissingattachment", "completebuffer" }; boolpass=true; printf("Testingblitfrom%sto%s...\n",names[src],names[dst]); /*Createadepth-onlyFBOandadepth/colorFBO. */ glGenRenderbuffers(ARRAY_SIZE(rb),rb); glBindRenderbuffer(GL_RENDERBUFFER,rb[0]); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24, piglit_width,piglit_height); glBindRenderbuffer(GL_RENDERBUFFER,rb[1]); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24, piglit_width,piglit_height); glBindRenderbuffer(GL_RENDERBUFFER,rb[2]); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA, piglit_width,piglit_height); glGenFramebuffers(ARRAY_SIZE(fb),fb); glBindFramebuffer(GL_FRAMEBUFFER,fb[0]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,rb[0]); if(!use_es2){ glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); } glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fb[1]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,rb[1]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,rb[2]); err=glGetError(); if(err!=0){ fprintf(stderr,"UnexpectedGLerrorstate0x%04x\n",err); returnfalse; } /*Checkcompletenessofthesourcesurface. */ glBindFramebuffer(GL_READ_FRAMEBUFFER,fb[src]); status=glCheckFramebufferStatus(GL_READ_FRAMEBUFFER); if(status!=GL_FRAMEBUFFER_COMPLETE){ fprintf(stderr,"ReadFBOerroneouslyincomplete:0x%04x\n", status); returnfalse; } /*Inthesourcesurface,clearthedepthbufferanddrawasingle *rectanglewithaconstantdepthvalue.Thedepthtestsettinghere *iscorrect. */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fb[src]); glClearDepth(0.0); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); piglit_draw_rect_z(0.5,-0.5,-0.5,1.0,1.0); /*Checkcompletenessofthedestinationsurface. */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fb[dst]); status=glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if(status!=GL_FRAMEBUFFER_COMPLETE){ fprintf(stderr,"DrawFBOerroneouslyincomplete:0x%04x\n", status); returnfalse; } glBlitFramebuffer(0,0,piglit_width,piglit_height, 0,0,piglit_width,piglit_height, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, GL_NEAREST); err=glGetError(); if(err!=0){ fprintf(stderr,"UnexpectedGLerrorstate0x%04x\n",err); returnfalse; } /*Probedepthvaluesfromthedestinationbuffertomakesurethe *depthpartoftheblitactuallyhappened. */ glBindFramebuffer(GL_READ_FRAMEBUFFER,fb[dst]); pass=piglit_probe_rect_depth(0.25*piglit_width, 0.25*piglit_height, 0.4*piglit_width, 0.4*piglit_height, 0.75); pass=piglit_probe_rect_depth(0, 0, piglit_width, 0.2*piglit_height, 0.0) &&pass; glBindFramebuffer(GL_READ_FRAMEBUFFER,piglit_winsys_fbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER,piglit_winsys_fbo); glDeleteFramebuffers(ARRAY_SIZE(fb),fb); glDeleteRenderbuffers(ARRAY_SIZE(rb),rb); returnpass; }Example#300ShowfilevoidQKmsBufferManager::setupBuffersForMode(constdrmModeModeInfo&mode,intnumBuffers) { eglMakeCurrent(m_screen->device()->eglDisplay(),EGL_NO_SURFACE,EGL_NO_SURFACE,m_screen->device()->eglContext()); m_screen->bindFramebuffer(); if(m_frameBufferObject){ clearBuffers(); }else{ //SetupFramebufferObject glGenFramebuffers(1,&m_frameBufferObject); glBindFramebuffer(GL_FRAMEBUFFER,m_frameBufferObject); } //SetupsharedDepth/Stencilbuffer glGenRenderbuffers(1,&m_depthAndStencilBufferObject); glBindRenderbuffer(GL_RENDERBUFFER,m_depthAndStencilBufferObject); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8_OES, mode.hdisplay,mode.vdisplay); //Setup"numBuffer"manyrenderingtargets for(inti=0;irenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,buffer->renderBuffer); buffer->graphicsBufferObject=gbm_bo_create(m_screen->device()->gbmDevice(), mode.hdisplay,mode.vdisplay, GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT|GBM_BO_USE_RENDERING); buffer->eglImage=eglCreateImageKHR(m_screen->device()->eglDisplay(),0,EGL_NATIVE_PIXMAP_KHR, buffer->graphicsBufferObject,0); glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,buffer->eglImage); quint32stride=gbm_bo_get_pitch(buffer->graphicsBufferObject); quint32handle=gbm_bo_get_handle(buffer->graphicsBufferObject).u32; intstatus=drmModeAddFB(m_screen->device()->fd(),mode.hdisplay,mode.vdisplay, 32,32,stride,handle,&buffer->framebufferId); //Todo:IFthisreturnstrue,thenthisisonelessbufferthatweuse //Notsofatal,butnothandledatthemoment. if(status) qFatal("failedtoaddframebuffer"); m_framebuffers.append(buffer); } //AttachtheDepthandStencilbuffer glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthAndStencilBufferObject); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthAndStencilBufferObject); //AttachrenderbufferasColorAttachment. glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, this->renderTargetBuffer()); }reportthisadxx



請為這篇文章評分?