C++ (Cpp) glFramebufferTexture2D Examples - HotExamples

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

C++ (Cpp) glFramebufferTexture2D - 30 examples found. These are the top rated real world C++ (Cpp) examples of glFramebufferTexture2D extracted from open ... Togglenavigation HotExamplesENENRUDEFRESPTITJPZH C++PHPC#JavaGoC++PythonJSTS SearchC++(Cpp)glFramebufferTexture2DExamplesC++(Cpp)glFramebufferTexture2D-30examplesfound.ThesearethetopratedrealworldC++(Cpp)examplesofglFramebufferTexture2Dextractedfromopensourceprojects.Youcanrateexamplestohelpusimprovethequalityofexamples.ProgrammingLanguage:C++(Cpp)Method/Function:glFramebufferTexture2DExamplesathotexamples.com:30reportthisadRelatedg_build_filenamelibusb_handle_events_timeoutglfwWaitEventsntp_syncedImageTCanvasCLAMPSReadBlobByteisTextBreakGetlinereportthisadRelatedinlangsK2StoreHelperOptions(PHP)CMbObject(PHP)HttpItem(C#)OAuth2Token(C#)PANIC_ON_ERR(Go)RatingSubjectAliasKey(Go)TachyonURI(Java)Analyzer(Java)create_psservice(Python)ShellJobExecutor(Python)reportthisadExample#10ShowfileFile: splat.c Project: nikarul/splatglintSplat_Prepare(SDL_Window*userWindow,intuserViewportWidth,intuserViewportHeight){ intwidth,height; window=userWindow; viewportWidth=userViewportWidth; viewportHeight=userViewportHeight; SDL_GetWindowSize(userWindow,&width,&height); SDL_GL_SetAttribute(SDL_GL_RED_SIZE,4); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,4); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,4); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,4); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); window_glcontext=SDL_GL_CreateContext(window); if(!window_glcontext){ Splat_SetError("OpenGLcontextcreationfailed.CheckglGetError()and/orSDL_GetError()formoreinformation."); Splat_Finish(); return-1; } //Ourshadingmodel--Flat glShadeModel(GL_FLAT); //Defaulttheclearcolortoblack. glClearColor(0.0f,0.0f,0.0f,1.0f); //Setupourviewport. glViewport(0,0,viewportWidth,viewportHeight); //Changetotheprojectionmatrixandsetupourorthoview glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,width,0,height); //Setupmodelviewfor2Dintegercoordinates glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.375f,height+0.375f,0.0f); glScalef(1.0f,-1.0f,0.001f);//MakethepositiveZ-axispoint"out"fromtheview(e.gimagesatdepth4willbehigherthanthoseatdepth0),andswaptheYaxis /*Deactivatethesystemcursor*/ SDL_ShowCursor(SDL_DISABLE); glDisable(GL_DITHER); /*Createtheframebufferforrenderingtotexture*/ glGenFramebuffers(1,&framebuffer); glBindFramebuffer(GL_FRAMEBUFFER,framebuffer); /*Setupthetexturetowhichwe'regoingtorender*/ glGenTextures(1,&frameTexture); glBindTexture(GL_TEXTURE_2D,frameTexture); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,viewportWidth,viewportHeight,0,GL_RGB,GL_UNSIGNED_BYTE,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); /*Configuretheframebuffertexture*/ glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,frameTexture,0); GLenumDrawBuffers[1]={GL_COLOR_ATTACHMENT0}; glDrawBuffers(1,DrawBuffers); GLenumerr=glGetError(); if(err!=GL_NO_ERROR){ Splat_SetError("OpenGLerroroccurredduringinitialization"); Splat_Finish(); return-1; } return0; }Example#20ShowfileFile: native.cpp Project: orochicgj/aipaivoidnativeRecord::init(){ _eglCreateImageKHR=(PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); _eglDestroyImageKHR=(PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); _glEGLImageTargetTexture2DOES=(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); if(_eglCreateImageKHR==NULL){ LOGD("_eglCreateImageKHRerror"); exit(1); } if(_eglDestroyImageKHR==NULL){ LOGD("_eglDestroyImageKHRerror"); exit(1); } if(_glEGLImageTargetTexture2DOES==NULL){ LOGD("_glEGLImageTargetTexture2DOESerror"); exit(1); } buffer=newGraphicBuffer(gWidth,gHeight, HAL_PIXEL_FORMAT_BGRA_8888, GraphicBuffer::USAGE_SW_READ_OFTEN| GraphicBuffer::USAGE_HW_TEXTURE); if((buffer->initCheck())!=NO_ERROR) exit(1); android_native_buffer_t*anb=buffer->getNativeBuffer(); constEGLintattrs[]= { EGL_IMAGE_PRESERVED_KHR,EGL_TRUE, EGL_NONE,EGL_NONE }; pEGLImage=_eglCreateImageKHR(eglGetCurrentDisplay(),EGL_NO_CONTEXT,EGL_NATIVE_BUFFER_ANDROID,(EGLClientBuffer)anb,attrs); if(EGL_SUCCESS!=eglGetError()){ LOGI("_eglCreateImageKHRfailed."); return; } glGenTextures(1,&iFBOTex); checkGlError("glGenTextures(1,&iFBOTex);"); glBindTexture(GL_TEXTURE_2D,iFBOTex); checkGlError("glBindTexture(GL_TEXTURE_2D,iFBOTex);"); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,GL_BGRA_EXT,gWidth,gHeight, 0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,NULL); if(GL_NO_ERROR!=glGetError()){ LOGI("glTexImage2Dfailed."); return; } glGenFramebuffers(1,&iFBO); checkGlError("glGenFramebuffers(1,&iFBO);"); glBindFramebuffer(GL_FRAMEBUFFER,iFBO); checkGlError("glBindFramebuffer(GL_FRAMEBUFFER,iFBO)"); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,iFBOTex,0); GLuintstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status!=GL_FRAMEBUFFER_COMPLETE){ LOGI("glCheckFramebufferStatus%d",status); } checkGlError("glFramebufferTexture2D"); _glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,pEGLImage); checkGlError("_glEGLImageTargetTexture2DOES"); glBindFramebuffer(GL_FRAMEBUFFER,0); checkGlError("glBindFramebuffer(GL_FRAMEBUFFER,0)"); pixels=(char*)malloc(720*1280*4); memset(pixels,0,720*1280*4); }Example#30ShowfileFile: transition_movit_mix.cpp Project: eddrog/mltstaticintget_image(mlt_framea_frame,uint8_t**image,mlt_image_format*format,int*width,int*height,intwritable) { interror=0; //Getthebframefromthestack mlt_frameb_frame=(mlt_frame)mlt_frame_pop_frame(a_frame); //Getthetransitionobject mlt_transitiontransition=(mlt_transition)mlt_frame_pop_service(a_frame); //Getthepropertiesofthetransition mlt_propertiesproperties=MLT_TRANSITION_PROPERTIES(transition); //Getthepropertiesoftheaframe mlt_propertiesa_props=MLT_FRAME_PROPERTIES(a_frame); //Getthemovitobjects mlt_serviceservice=MLT_TRANSITION_SERVICE(transition); mlt_service_lock(service); EffectChain*chain=GlslManager::get_chain(service); Effect*effect=(Effect*)mlt_properties_get_data(properties,"moviteffect",NULL); MltInput*a_input=GlslManager::get_input(service); MltInput*b_input=(MltInput*)mlt_properties_get_data(properties,"movitinputB",NULL); mlt_image_formatoutput_format=*format; if(!chain||!a_input){ mlt_service_unlock(service); return2; } //Getthetransitionparameters intreverse=mlt_properties_get_int(properties,"reverse"); doublemix=mlt_properties_get(properties,"mix")? mlt_properties_get_double(properties,"mix"): mlt_transition_get_progress(transition,a_frame); doubleinverse=1.0-mix; //Setthemovitparameters boolok=effect->set_float("strength_first",reverse?mix:inverse); ok|=effect->set_float("strength_second",reverse?inverse:mix); assert(ok); //Gettheframes'textures GLuint*texture_id[2]={0,0}; *format=mlt_image_glsl_texture; mlt_frame_get_image(a_frame,(uint8_t**)&texture_id[0],format,width,height,0); a_input->useFBOInput(chain,*texture_id[0]); *format=mlt_image_glsl_texture; mlt_frame_get_image(b_frame,(uint8_t**)&texture_id[1],format,width,height,0); b_input->useFBOInput(chain,*texture_id[1]); //Setresolutiontothatofthea_frame *width=mlt_properties_get_int(a_props,"width"); *height=mlt_properties_get_int(a_props,"height"); //SetuprenderingtoanFBO GlslManager*glsl=GlslManager::get_instance(); glsl_fbofbo=glsl->get_fbo(*width,*height); if(output_format==mlt_image_glsl_texture){ glsl_texturetexture=glsl->get_texture(*width,*height,GL_RGBA); glBindFramebuffer(GL_FRAMEBUFFER,fbo->fbo); check_error(); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texture->texture,0); check_error(); glBindFramebuffer(GL_FRAMEBUFFER,0); check_error(); GlslManager::render(service,chain,fbo->fbo,*width,*height); glFinish(); check_error(); glBindFramebuffer(GL_FRAMEBUFFER,0); check_error(); *image=(uint8_t*)&texture->texture; mlt_frame_set_image(a_frame,*image,0,NULL); mlt_properties_set_data(properties,"movit.convert",texture,0, (mlt_destructor)GlslManager::release_texture,NULL); *format=output_format; } else{ //UseaPBOtoholdthedatawereadbackwithglReadPixels() //(Intel/DRIgoesintoaslowpathifwedon'treadtoPBO) GLenumgl_format=(output_format==mlt_image_rgb24a||output_format==mlt_image_opengl)? GL_RGBA:GL_RGB; intimg_size=*width**height*(gl_format==GL_RGB?3:4); glsl_pbopbo=glsl->get_pbo(img_size); glsl_texturetexture=glsl->get_texture(*width,*height,gl_format); if(fbo&&pbo&&texture){ //SettheFBO glBindFramebuffer(GL_FRAMEBUFFER,fbo->fbo); check_error(); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texture->texture,0); check_error(); glBindFramebuffer(GL_FRAMEBUFFER,0); check_error(); GlslManager::render(service,chain,fbo->fbo,*width,*height); //ReadFBOintoPBO glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB,pbo->pbo); check_error(); glBufferData(GL_PIXEL_PACK_BUFFER_ARB,img_size,NULL,GL_STREAM_READ); check_error(); glReadPixels(0,0,*width,*height,gl_format,GL_UNSIGNED_BYTE,BUFFER_OFFSET(0)); check_error(); //CopyfromPBO uint8_t*buf=(uint8_t*)glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB,GL_READ_ONLY); check_error(); *format=gl_format==GL_RGBA?mlt_image_rgb24a:mlt_image_rgb24; *image=(uint8_t*)mlt_pool_alloc(img_size); mlt_frame_set_image(a_frame,*image,img_size,mlt_pool_release); memcpy(*image,buf,img_size); //ReleasePBOandFBO glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); check_error(); glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB,0); check_error(); glBindFramebuffer(GL_FRAMEBUFFER,0); check_error(); glBindTexture(GL_TEXTURE_2D,0); check_error(); GlslManager::release_texture(texture); } else{ error=1; } } if(fbo)GlslManager::release_fbo(fbo); mlt_service_unlock(service); returnerror; }Example#40ShowfileFile: llrendertarget.cpp Project: HizWylder/GISboolLLRenderTarget::addColorAttachment(U32color_fmt) { if(color_fmt==0) { returntrue; } U32offset=mTex.size(); if(offset>=4|| (offset>0&&(mFBO==0||!gGLManager.mHasDrawBuffers))) { llerrs<bindManual(mUsage,tex); stop_glerror(); { clear_glerror(); LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage),0,color_fmt,mResX,mResY,GL_RGBA,GL_UNSIGNED_BYTE,NULL); if(glGetError()!=GL_NO_ERROR) { llwarns<setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); stop_glerror(); } else {//don'tfilterdataattachments gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); stop_glerror(); } if(mUsage!=LLTexUnit::TT_RECT_TEXTURE) { gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_MIRROR); stop_glerror(); } else { //ATIdoesn'tsupportmirroredrepeatforrectangulartextures. gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); stop_glerror(); } if(mFBO) { stop_glerror(); glBindFramebuffer(GL_FRAMEBUFFER,mFBO); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0+offset, LLTexUnit::getInternalType(mUsage),tex,0); stop_glerror(); check_framebuffer_status(); glBindFramebuffer(GL_FRAMEBUFFER,0); } mTex.push_back(tex); if(gDebugGL) {//bindandunbindtovalidatetarget bindTarget(); flush(); } returntrue; }Example#50ShowfileFile: CCRenderTexture.cpp Project: 0x0c/cocos2d-xboolRenderTexture::initWithWidthAndHeight(intw,inth,Texture2D::PixelFormateFormat,GLuintuDepthStencilFormat) { CCASSERT(eFormat!=Texture2D::PixelFormat::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,&_oldFBO); //texturesmustbepoweroftwosquared unsignedintpowW=0; unsignedintpowH=0; if(Configuration::getInstance()->supportsNPOT()) { powW=w; powH=h; } else { powW=ccNextPOT(w); powH=ccNextPOT(h); } intdataLen=(int)(powW*powH*4); data=malloc(dataLen); CC_BREAK_IF(!data); memset(data,0,dataLen); _pixelFormat=eFormat; _texture=newTexture2D(); 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=newTexture2D(); 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(uDepthStencilFormat!=0) { //createandattachdepthbuffer glGenRenderbuffers(1,&_depthRenderBufffer); glBindRenderbuffer(GL_RENDERBUFFER,_depthRenderBufffer); glRenderbufferStorage(GL_RENDERBUFFER,uDepthStencilFormat,(GLsizei)powW,(GLsizei)powH); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,_depthRenderBufffer); //ifdepthformatistheonewithstencilpart,bindsamerenderbufferasstencilattachment if(uDepthStencilFormat==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->setScaleY(-1); _sprite->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED); glBindRenderbuffer(GL_RENDERBUFFER,oldRBO); glBindFramebuffer(GL_FRAMEBUFFER,_oldFBO); //Diabledbydefault. _autoDraw=false; //addspriteforbackwardcompatibility addChild(_sprite); bRet=true; }while(0); CC_SAFE_FREE(data); returnbRet; }Example#60ShowfileFile: CCRenderTexture.cpp Project: Ratel13/WarriorQuestvoidRenderTexture::onBegin() { // Director*director=Director::getInstance(); _oldProjMatrix=director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,_projectionMatrix); _oldTransMatrix=director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW,_transformMatrix); if(!_keepMatrix) { director->setProjection(director->getProjection()); #ifCC_TARGET_PLATFORM==CC_PLATFORM_WP8 Mat4modifiedProjection=director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); modifiedProjection=GLViewImpl::sharedOpenGLView()->getReverseOrientationMatrix()*modifiedProjection; director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,modifiedProjection); #endif constSize&texSize=_texture->getContentSizeInPixels(); //Calculatetheadjustmentratiosbasedontheoldandnewprojections Sizesize=director->getWinSizeInPixels(); floatwidthRatio=size.width/texSize.width; floatheightRatio=size.height/texSize.height; Mat4orthoMatrix; Mat4::createOrthographicOffCenter((float)-1.0/widthRatio,(float)1.0/widthRatio,(float)-1.0/heightRatio,(float)1.0/heightRatio,-1,1,&orthoMatrix); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,orthoMatrix); } else { #ifCC_TARGET_PLATFORM==CC_PLATFORM_WP8 Mat4modifiedProjection=director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); modifiedProjection=GLViewImpl::sharedOpenGLView()->getReverseOrientationMatrix()*modifiedProjection; director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,modifiedProjection); #endif } //calculateviewport { Rectviewport; viewport.size.width=_fullviewPort.size.width; viewport.size.height=_fullviewPort.size.height; floatviewPortRectWidthRatio=float(viewport.size.width)/_fullRect.size.width; floatviewPortRectHeightRatio=float(viewport.size.height)/_fullRect.size.height; viewport.origin.x=(_fullRect.origin.x-_rtTextureRect.origin.x)*viewPortRectWidthRatio; viewport.origin.y=(_fullRect.origin.y-_rtTextureRect.origin.y)*viewPortRectHeightRatio; //glViewport(_fullviewPort.origin.x,_fullviewPort.origin.y,(GLsizei)_fullviewPort.size.width,(GLsizei)_fullviewPort.size.height); glViewport(viewport.origin.x,viewport.origin.y,(GLsizei)viewport.size.width,(GLsizei)viewport.size.height); } //Adjusttheorthographicprojectionandviewport glGetIntegerv(GL_FRAMEBUFFER_BINDING,&_oldFBO); glBindFramebuffer(GL_FRAMEBUFFER,_FBO); //TODOmovethistoconfigration,sowedon'tcheckiteverytime /*CertainQualcommAndrenogpu'swillretaindatainmemoryafteraframebufferswitchwhichcorruptstherendertothetexture.Thesolutionistocleartheframebufferbeforerenderingtothetexture.However,callingglClearhastheunintendedresultofclearingthecurrenttexture.Createatemporarytexturetoovercomethis.AttheendofRenderTexture::begin(),switchtheattachedtexturetothesecondone,callglClear,andthenswitchbacktotheoriginaltexture.Thissolutionisunnecessaryforotherdevicesastheydon'thavethesameissuewithswitchingframebuffers. */ if(Configuration::getInstance()->checkForGLExtension("GL_QCOM")) { //--bindatemporarytexturesowecancleartherenderbufferwithoutlosingourtexture glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,_textureCopy->getName(),0); CHECK_GL_ERROR_DEBUG(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,_texture->getName(),0); } }Example#70ShowfileFile: Framebuffer.cpp Project: BenjaminCoquelle/OpenGL-Game-Engine boolFramebuffer::init(unsignedintwidth,unsignedintheight,unsignedintlayerNumber) { //todoclearallifallreadyinitilized _width=width; _height=height; _layerNumber=layerNumber; glGenFramebuffers(1,&_handle); glBindFramebuffer(GL_FRAMEBUFFER,_handle); _layers=newunsignedint[_layerNumber]; glGenTextures(_layerNumber,_layers); for(unsignedinti=0;i<_layernumber _layernames.push_back glbindtexture gltexparameteri glteximage2d glframebuffertexture2d glgenrenderbuffers glbindrenderbuffer glrenderbufferstorage glframebufferrenderbuffer if returnfalse glbindframebuffer floatss_quad_pos floatss_quad_st unsignedintindice _vbo.init _vbo.addattribute _vbo.setbuffer>(&ss_quad_pos)); _vbo.setBuffer(1,reinterpret_cast(&ss_quad_st)); returntrue; }Example#80ShowfileFile: PostTess.c Project: UIKit0/opengl-insightsstaticFboDescCreateSurfaces(GLsizeiwidth,GLsizeiheight,intnumComponents,intnumTargets) { FboDescsurface; glGenFramebuffers(1,&surface.FboHandle); glBindFramebuffer(GL_FRAMEBUFFER,surface.FboHandle); for(intattachment=0;attachment(props); Clear(); // generateframebuffer glGenFramebuffers(1,&m_fb); // createcolortexture if(m_color_texture) safe_delete(m_color_texture); m_color_texture=newTexture2D; m_color_texture->Create(m_properties.m_texture_width,m_properties.m_texture_height,ImageModule::IMAGE_FORMAT_RGBA8,0,false); // ifmultisample // generaterenderbuffers glGenRenderbuffers(1,&m_depth_rb); glGenRenderbuffers(1,&m_color_rb); // generateresolveframebuffer glGenFramebuffers(1,&m_resolve_fb); // tuneresolveframebuffer glBindFramebuffer(GL_FRAMEBUFFER,m_resolve_fb); // bindcolortexture glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_color_texture->GetCode(),0); Check(); // tunerenderframebuffer glBindFramebuffer(GL_FRAMEBUFFER,m_fb); // tunecolorrenderbuffer glBindRenderbuffer(GL_RENDERBUFFER,m_color_rb); intmax_samples; glGetIntegerv(GL_MAX_SAMPLES,&max_samples); // forcsaasomeextrastaffneeded //createaregularMSAAcolorbuffer glRenderbufferStorageMultisample(GL_RENDERBUFFER,max_samples,GL_RGBA8,m_color_texture->GetWidth(),m_color_texture->GetHeight()); //checkthenumberofsamples glGetRenderbufferParameteriv(GL_RENDERBUFFER,GL_RENDERBUFFER_SAMPLES,&max_samples); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,m_color_rb); Check(); // tunedepthrenderbuffer glBindRenderbuffer(GL_RENDERBUFFER,m_depth_rb); // forcsaaanothermethodshouldbeused // createaregularMSAAdepthbuffer glRenderbufferStorageMultisample(GL_RENDERBUFFER,max_samples,GL_DEPTH_COMPONENT24,m_color_texture->GetWidth(),m_color_texture->GetHeight()); // attachdepthbuffertoframebuffer glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,m_depth_rb); Check(); glBindFramebuffer(GL_FRAMEBUFFER,0); returntrue; }Example#100ShowfileFile: fb-completeness.c Project: dervishxgit/piglitstaticenumpiglit_result exec_test(structtest_info*info,intsample_count) { GLuintfb,tex,rb; GLintresult; structattachment_info*att; GLintmaxColorSamples,maxDepthSamples; glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES,&maxColorSamples); glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES,&maxDepthSamples); glGenFramebuffers(1,&fb); glBindFramebuffer(GL_FRAMEBUFFER,fb); printf("Testingfbocompletenessforconfig'%s'\n",info->name); for(att=info->attachments;att->target;att++){ intattachment_sample_count=att->multisample?sample_count:0; printf("Atttarget=%satt=%ssamples=%ddims=%d,%d,%dfixed=%d\n", piglit_get_gl_enum_name(att->target), piglit_get_gl_enum_name(att->attachment), attachment_sample_count, SURFACE_WIDTH,SURFACE_HEIGHT, att->target==GL_TEXTURE_2D_MULTISAMPLE_ARRAY?SURFACE_DEPTH:1, att->fixedsamplelocations); switch(att->target){ caseGL_TEXTURE_2D_MULTISAMPLE: caseGL_TEXTURE_2D_MULTISAMPLE_ARRAY: if(att->attachment==GL_DEPTH_ATTACHMENT&&sample_count>maxDepthSamples) returnPIGLIT_SKIP; if((att->attachment==GL_COLOR_ATTACHMENT0|| att->attachment==GL_COLOR_ATTACHMENT1)&&sample_count>maxColorSamples) returnPIGLIT_SKIP; } switch(att->target){ caseGL_TEXTURE_2D_MULTISAMPLE: glGenTextures(1,&tex); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE,tex); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, attachment_sample_count,choose_format(att), SURFACE_WIDTH,SURFACE_HEIGHT, att->fixedsamplelocations); if(!piglit_check_gl_error(GL_NO_ERROR)) returnPIGLIT_FAIL; glFramebufferTexture2D(GL_FRAMEBUFFER,att->attachment, att->target,tex,0); break; caseGL_TEXTURE_2D_MULTISAMPLE_ARRAY: glGenTextures(1,&tex); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY,tex); glTexImage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, attachment_sample_count,choose_format(att), SURFACE_WIDTH,SURFACE_HEIGHT,SURFACE_DEPTH, att->fixedsamplelocations); if(!piglit_check_gl_error(GL_NO_ERROR)) returnPIGLIT_FAIL; glFramebufferTextureLayer(GL_FRAMEBUFFER,att->attachment, tex,0,att->layer); break; caseGL_RENDERBUFFER: /*RENDERBUFFERhasfixedsamplelocationsimplicitly*/ assert(att->fixedsamplelocations); glGenRenderbuffers(1,&rb); glBindRenderbuffer(GL_RENDERBUFFER,rb); if(att->multisample){ glRenderbufferStorageMultisample(GL_RENDERBUFFER, attachment_sample_count,choose_format(att), SURFACE_WIDTH,SURFACE_HEIGHT); } else{ /*non-MSAArenderbuffer*/ glRenderbufferStorage(GL_RENDERBUFFER,choose_format(att), SURFACE_WIDTH,SURFACE_HEIGHT); } glFramebufferRenderbuffer(GL_FRAMEBUFFER, att->attachment,att->target,rb); if(!piglit_check_gl_error(GL_NO_ERROR)) returnPIGLIT_FAIL; break; default: assert(!"Unsupportedtarget"); } } result=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(result!=info->expected){ printf("glCheckFramebufferStatus:expected%s,got%s\n", piglit_get_gl_enum_name(info->expected), piglit_get_gl_enum_name(result)); returnPIGLIT_FAIL; } if(result==GL_FRAMEBUFFER_COMPLETE&&info->attachments->multisample) returncheck_sample_positions(sample_count); returnPIGLIT_PASS; }Example#110ShowfileFile: test-srgb-fbo.c Project: freedreno/freedreno/*Runthroughmultiplevariantstodetectmrtsettings */ voidtest_srgb_fbo(GLintifmt,GLenumfmt,GLenumtype) { GLintwidth,height; GLuintfbo,fbotex; GLenummrt_bufs[16]; GLfloatquad_color[]={1.0,0.0,0.0,1.0}; GLfloatvertices[]={ -0.45,-0.75,0.1, 0.45,-0.75,0.1, -0.45,0.75,0.1, 0.45,0.75,0.1}; EGLSurfacesurface; RD_START("srgb-fbo","fmt=%s(%x),ifmt=%s(%x),type=%s(%x)", formatname(fmt),fmt, formatname(ifmt),ifmt, typename(type),type); display=get_display(); /*getanappropriateEGLframebufferconfiguration*/ ECHK(eglChooseConfig(display,config_attribute_list,&config,1,&num_config)); DEBUG_MSG("num_config:%d",num_config); /*createanEGLrenderingcontext*/ ECHK(context=eglCreateContext(display,config,EGL_NO_CONTEXT,context_attribute_list)); surface=make_window(display,config,64,64); ECHK(eglQuerySurface(display,surface,EGL_WIDTH,&width)); ECHK(eglQuerySurface(display,surface,EGL_HEIGHT,&height)); DEBUG_MSG("Buffer:%dx%d",width,height); /*connectthecontexttothesurface*/ ECHK(eglMakeCurrent(display,surface,surface,context)); program=get_program(vertex_shader_source,fragment_shader_source); GCHK(glBindAttribLocation(program,0,"aPosition")); link_program(program); GCHK(glGenFramebuffers(1,&fbo)); GCHK(glGenTextures(1,&fbotex)); GCHK(glBindFramebuffer(GL_FRAMEBUFFER,fbo)); GCHK(glBindTexture(GL_TEXTURE_2D,fbotex)); GCHK(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)); GCHK(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)); GCHK(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE)); GCHK(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE)); GCHK(glTexImage2D(GL_TEXTURE_2D,0,ifmt,width,height,0,fmt,type,0)); GCHK(glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,fbotex,0)); DEBUG_MSG("status=%04x",glCheckFramebufferStatus(GL_FRAMEBUFFER)); GCHK(glBindFramebuffer(GL_FRAMEBUFFER,fbo)); GCHK(glDrawBuffers(1,(constGLenum[]){GL_COLOR_ATTACHMENT0}));Example#120Showfile/*!**************************************************************************** @Function InitView @Return bool trueifnoerroroccured @Description CodeinInitView()willbecalledbyPVRShellupon initializationorafterachangeintherenderingcontext. Usedtoinitializevariablesthataredependantontherendering context(e.g.textures,vertexbuffers,etc.) ******************************************************************************/ boolOGLES2RenderToTexture::InitView() { //Findthelargestsquarepoweroftwotexturethatfitsintotheviewport m_i32TexSize=1; intiSize=PVRT_MIN(PVRShellGet(prefWidth),PVRShellGet(prefHeight)); while(m_i32TexSize*2Update(); if(AndroidSurfaceTexture->nanoTimeStamp==LastSurfaceTexNanoTimeStamp) { return; } LastSurfaceTexNanoTimeStamp=AndroidSurfaceTexture->nanoTimeStamp; //don'tmessupUnitystate GLStateSave stateSave; //Ifwehaven'tallocatedourGLobjectsyet,doitnow. //Thisisn'tdoneatInit,becauseGLmaynotbecurrentthen. if(UnitSquare.vertexArrayObject==0) { LOG("AllocatingGLobjects"); UnitSquare=BuildTesselatedQuad(1,1); CopyMovieProgram=BuildProgram( "uniformhighpmat4Mvpm;\n" "attributevec4Position;\n" "attributevec2TexCoord;\n" "varyinghighpvec2oTexCoord;\n" "voidmain()\n" "{\n" "gl_Position=Position;\n" "oTexCoord=TexCoord;\n" "}\n" , "#extensionGL_OES_EGL_image_external:require\n" "uniformsamplerExternalOESTexture0;\n" "varyinghighpvec2oTexCoord;\n" "voidmain()\n" "{\n" " gl_FragColor=texture2D(Texture0,oTexCoord);\n" "}\n" ); } //IftheSurfaceTexturehaschangeddimensions,weneedto //reallocatethetextureandFBO. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_EXTERNAL_OES,AndroidSurfaceTexture->textureId); //FIXME:nowaytogettexturedimensionseveninES3.0??? int width=960; intheight=540; if(width!=TexIdWidth||height!=TexIdHeight) { LOG("Newsurfacesize:%ix%i",width,height); TexIdWidth=width; TexIdHeight=height; if(Fbo) { glDeleteFramebuffers(1,&Fbo); } glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,TexId); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, TexIdWidth,TexIdHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); 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_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glBindTexture(GL_TEXTURE_2D,0); glActiveTexture(GL_TEXTURE0); glGenFramebuffers(1,&Fbo); glBindFramebuffer(GL_FRAMEBUFFER,Fbo); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, TexId,0); glBindFramebuffer(GL_FRAMEBUFFER,0); } glBindFramebuffer(GL_FRAMEBUFFER,Fbo); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); glDisable(GL_STENCIL_TEST); glDisable(GL_CULL_FACE); glDisable(GL_BLEND); constGLenumfboAttachments[1]={GL_COLOR_ATTACHMENT0}; glInvalidateFramebuffer(GL_FRAMEBUFFER,1,fboAttachments); glViewport(0,0,TexIdWidth,TexIdHeight); glUseProgram(CopyMovieProgram.program); UnitSquare.Draw(); glUseProgram(0); glBindTexture(GL_TEXTURE_EXTERNAL_OES,0); glBindFramebuffer(GL_FRAMEBUFFER,0); glBindTexture(GL_TEXTURE_2D,TexId); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,0); }Example#160ShowfileFile: Mainold9.cpp Project: archer1357/Deferred-RendererboolsetupDeferred(intw,inth){ std::cout<getContentSizeInPixels(); //togettheimagesizetosave //ifthesavingimagedomainexceedsthebuffertexturedomain, //itshouldbecut intsavedBufferWidth=(int)s.width; intsavedBufferHeight=(int)s.height; GLubyte*buffer=nullptr; GLubyte*tempData=nullptr; Image*image=new(std::nothrow)Image(); do { CC_BREAK_IF(!(buffer=new(std::nothrow)GLubyte[savedBufferWidth*savedBufferHeight*4])); if(!(tempData=new(std::nothrow)GLubyte[savedBufferWidth*savedBufferHeight*4])) { delete[]buffer; buffer=nullptr; break; } glGetIntegerv(GL_FRAMEBUFFER_BINDING,&_oldFBO); glBindFramebuffer(GL_FRAMEBUFFER,_FBO); //TODOmovethistoconfigration,sowedon'tcheckiteverytime /*CertainQualcommAndrenogpu'swillretaindatainmemoryafteraframebufferswitchwhichcorruptstherendertothetexture.Thesolutionistocleartheframebufferbeforerenderingtothetexture.However,callingglClearhastheunintendedresultofclearingthecurrenttexture.Createatemporarytexturetoovercomethis.AttheendofRenderTexture::begin(),switchtheattachedtexturetothesecondone,callglClear,andthenswitchbacktotheoriginaltexture.Thissolutionisunnecessaryforotherdevicesastheydon'thavethesameissuewithswitchingframebuffers. */ if(Configuration::getInstance()->checkForGLExtension("GL_QCOM")) { //--bindatemporarytexturesowecancleartherenderbufferwithoutlosingourtexture glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,_textureCopy->getName(),0); CHECK_GL_ERROR_DEBUG(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,_texture->getName(),0); } glPixelStorei(GL_PACK_ALIGNMENT,1); glReadPixels(0,0,savedBufferWidth,savedBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE,tempData); glBindFramebuffer(GL_FRAMEBUFFER,_oldFBO); if(fliimage)//--flipisonlyrequiredwhensavingimagetofile { //togettheactualtexturedata //#640theimagereadfromrendertextureisdirty for(inti=0;iinitWithRawData(buffer,savedBufferWidth*savedBufferHeight*4,savedBufferWidth,savedBufferHeight,8); } else { image->initWithRawData(tempData,savedBufferWidth*savedBufferHeight*4,savedBufferWidth,savedBufferHeight,8); } }while(0); CC_SAFE_DELETE_ARRAY(buffer); CC_SAFE_DELETE_ARRAY(tempData); returnimage; }Example#180ShowfileFile: tr_fbo.c Project: belstgut/etlegacyvoidR_AttachFBOTextureDepth(inttexId) { glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,texId,0); }Example#190ShowfileFile: gl_render_texture.cpp Project: NolaDonato/GearVRfGLNonMultiviewRenderTexture::GLNonMultiviewRenderTexture(intwidth,intheight,intsample_count, intjcolor_format,intjdepth_format,boolresolve_depth, constTextureParameters*texture_parameters,intviewport[]):GLRenderTexture(width,height,sample_count,jcolor_format,jdepth_format, resolve_depth,texture_parameters,viewport){ GLRenderImage*colorbuffer=newGLRenderImage(width,height,jcolor_format,texture_parameters); GLenumdepth_format; setImage(colorbuffer); initialize(); getImage()->isReady(); switch(jdepth_format) { caseDepthFormat::DEPTH_24: depth_format=GL_DEPTH_COMPONENT24_OES; break; caseDepthFormat::DEPTH_24_STENCIL_8: depth_format=GL_DEPTH24_STENCIL8_OES; break; default: depth_format=GL_DEPTH_COMPONENT16; break; } if(sample_count<=1) { generateRenderTextureNoMultiSampling(jdepth_format,depth_format, width,height); } elseif(resolve_depth) { generateRenderTexture(sample_count,jdepth_format,depth_format, width,height,jcolor_format); } else { generateRenderTextureEXT(sample_count,jdepth_format, depth_format,width,height); } if(jdepth_format!=DepthFormat::DEPTH_0) { GLenumattachment=DepthFormat::DEPTH_24_STENCIL_8==jdepth_format?GL_DEPTH_STENCIL_ATTACHMENT:GL_DEPTH_ATTACHMENT; glFramebufferRenderbuffer(GL_FRAMEBUFFER,attachment,GL_RENDERBUFFER,renderTexture_gl_render_buffer_->id()); } glScissor(0,0,width,height); glViewport(0,0,width,height); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); if(resolve_depth&&sample_count>1) { deleterenderTexture_gl_resolve_buffer_; renderTexture_gl_resolve_buffer_=newGLFrameBuffer(); glBindFramebuffer(GL_FRAMEBUFFER,renderTexture_gl_resolve_buffer_->id()); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, colorbuffer->getTarget(),colorbuffer->getId(),0); GLenumstatus=glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status!=GL_FRAMEBUFFER_COMPLETE) { LOGE("resolveFBO%iisnotcomplete:0x%x", renderTexture_gl_resolve_buffer_->id(),status); } } glBindFramebuffer(GL_FRAMEBUFFER,0); checkGLError("GLNonMultiviewRenderTexture:"); }Example#200ShowfileFile: tr_fbo.c Project: belstgut/etlegacyvoidR_AttachFBOTexturePackedDepthStencil(inttexId) { glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,texId,0); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_TEXTURE_2D,texId,0); }Example#210ShowfilevoidQGLTextureGlyphCache::resizeTextureData(intwidth,intheight) { //###theQTextureGlyphCacheAPIneedstobereworkedtoallow //###resizeTextureDatatofail intoldWidth=m_width; intoldHeight=m_height; GLuintoldTexture=m_texture; createTextureData(width,height); glBindFramebuffer(GL_FRAMEBUFFER_EXT,m_fbo); GLuinttmp_texture; glGenTextures(1,&tmp_texture); glBindTexture(GL_TEXTURE_2D,tmp_texture); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,oldWidth,oldHeight,0, GL_RGBA,GL_UNSIGNED_BYTE,NULL); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D,0); glFramebufferTexture2D(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,tmp_texture,0); glActiveTexture(GL_TEXTURE0+QT_IMAGE_TEXTURE_UNIT); glBindTexture(GL_TEXTURE_2D,oldTexture); pex->transferMode(BrushDrawingMode); glDisable(GL_STENCIL_TEST); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glViewport(0,0,oldWidth,oldHeight); GLfloat*vertexCoordinateArray=pex->staticVertexCoordinateArray; vertexCoordinateArray[0]=-1.0f; vertexCoordinateArray[1]=-1.0f; vertexCoordinateArray[2]=1.0f; vertexCoordinateArray[3]=-1.0f; vertexCoordinateArray[4]=1.0f; vertexCoordinateArray[5]=1.0f; vertexCoordinateArray[6]=-1.0f; vertexCoordinateArray[7]=1.0f; GLfloat*textureCoordinateArray=pex->staticTextureCoordinateArray; textureCoordinateArray[0]=0.0f; textureCoordinateArray[1]=0.0f; textureCoordinateArray[2]=1.0f; textureCoordinateArray[3]=0.0f; textureCoordinateArray[4]=1.0f; textureCoordinateArray[5]=1.0f; textureCoordinateArray[6]=0.0f; textureCoordinateArray[7]=1.0f; pex->setVertexAttributePointer(QT_VERTEX_COORDS_ATTR,vertexCoordinateArray); pex->setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR,textureCoordinateArray); pex->shaderManager->useBlitProgram(); pex->shaderManager->blitProgram()->setUniformValue("imageTexture",QT_IMAGE_TEXTURE_UNIT); glDrawArrays(GL_TRIANGLE_FAN,0,4); glBindTexture(GL_TEXTURE_2D,m_texture); #ifdefQT_OPENGL_ES_2 QDataBufferbuffer(4*oldWidth*oldHeight); buffer.resize(4*oldWidth*oldHeight); glReadPixels(0,0,oldWidth,oldHeight,GL_RGBA,GL_UNSIGNED_BYTE,buffer.data()); //doanin-placeconversionfromGL_RGBAtoGL_ALPHA for(inti=0;id_ptr->current_fbo); glViewport(0,0,pex->width,pex->height); pex->updateClipScissorTest(); }Example#220ShowfileFile: TerrainQuadtree.cpp Project: fcvarela/spbvoidTerrainQuadtree::generateTextures(){ //prepareviewportandprojection //glDisable(GL_DEPTH_TEST); //donotsetuptheprojmorethanonce if(this->parent==NULL){ glViewport(0,0,this->textureSize,this->textureSize); glMatrixMode(GL_PROJECTION); glPolygonMode(GL_FRONT,GL_FILL); glLoadIdentity(); glOrtho(0.0,(double)this->textureSize,0.0,(double)this->textureSize,0.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(0.0,0.0,-1.0); generationScreenList=glGenLists(1); glNewList(generationScreenList,GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(0.0,0.0); glVertex3f(0.0,0.0,0.0); glTexCoord2f(1.0,0.0); glVertex3f(this->textureSize,0.0,0.0); glTexCoord2f(1.0,1.0); glVertex3f(this->textureSize,this->textureSize,0.0); glTexCoord2f(0.0,1.0); glVertex3f(0.0,this->textureSize,0.0); glEnd(); glEndList(); } //generatetopography glBindFramebuffer(GL_FRAMEBUFFER,this->framebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,this->topoTexture->id,0); this->positionTexture->bind(GL_TEXTURE0); this->generatorShader->bind(); glUniform1i(glGetUniformLocation(this->generatorShader->program,"positionTexture"),0); glCallList(generationScreenList); this->generatorShader->unbind(); //glBindFramebuffer(GL_FRAMEBUFFER,0); //generatenormals //glBindFramebuffer(GL_FRAMEBUFFER,this->framebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,this->normalTexture->id,0); this->topoTexture->bind(GL_TEXTURE1); this->generatorShaderN->bind(); glUniform1f(glGetUniformLocation(this->generatorShaderN->program,"size"),(float)this->textureSize); glUniform1f(glGetUniformLocation(this->generatorShaderN->program,"radius"),this->planet->radius); glUniform1i(glGetUniformLocation(this->generatorShaderN->program,"topoTexture"),1); glUniform1i(glGetUniformLocation(this->generatorShaderN->program,"positionTexture"),0); glCallList(generationScreenList); this->generatorShaderN->unbind(); //glBindFramebuffer(GL_FRAMEBUFFER,0); //generatecolors //glBindFramebuffer(GL_FRAMEBUFFER,this->framebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,this->colorTexture->id,0); this->generatorShaderC->bind(); glUniform1i(glGetUniformLocation(this->generatorShaderC->program,"topoTexture"),1); glCallList(generationScreenList); this->generatorShaderC->unbind(); //glBindFramebuffer(GL_FRAMEBUFFER,0); //glEnable(GL_DEPTH_TEST); this->ready=true; }Example#230ShowfileFile: WaterBall.cpp Project: HellicarAndLewis/SwntboolWaterBallDrawer::setup(intw,inth){ assert(w&&h); win_w=w; win_h=h; pm.ortho(0,w,h,0,0.0f,100.0f); //createbasicshader constchar*atts[]={"a_pos","a_size"}; constchar*frags[]={"out_normals","out_alpha"}; basic_prog.create(GL_VERTEX_SHADER,rx_to_data_path("shaders/waterdrop_basic.vert")); basic_prog.create(GL_FRAGMENT_SHADER,rx_to_data_path("shaders/waterdrop_basic.frag")); basic_prog.link(2,atts,2,frags); glUseProgram(basic_prog.id); glUniformMatrix4fv(glGetUniformLocation(basic_prog.id,"u_pm"),1,GL_FALSE,pm.ptr()); glUniform1i(glGetUniformLocation(basic_prog.id,"u_normals_tex"),0); glUniform1i(glGetUniformLocation(basic_prog.id,"u_alpha_tex"),1); //createwaterrendershader water_prog.create(GL_VERTEX_SHADER,rx_to_data_path("shaders/waterdrop_water.vert")); water_prog.create(GL_FRAGMENT_SHADER,rx_to_data_path("shaders/waterdrop_water.frag")); water_prog.link(); glUseProgram(water_prog.id); glUniform1i(glGetUniformLocation(water_prog.id,"u_normals_tex"),0); glUniform1i(glGetUniformLocation(water_prog.id,"u_alpha_tex"),1); glUniform1i(glGetUniformLocation(water_prog.id,"u_background_tex"),2); glGenVertexArrays(1,&water_vao); glGenVertexArrays(1,&basic_vao); glBindVertexArray(basic_vao); glGenBuffers(1,&basic_vbo); glBindBuffer(GL_ARRAY_BUFFER,basic_vbo); glEnableVertexAttribArray(0);//pos glEnableVertexAttribArray(1);//size glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,sizeof(WaterDrop),(GLvoid*)0); glVertexAttribPointer(1,1,GL_FLOAT,GL_FALSE,sizeof(WaterDrop),(GLvoid*)32); glVertexAttribDivisor(0,1); glVertexAttribDivisor(1,1); normals_tex=rx_create_texture(rx_to_data_path("images/waterdrop_normals.png")); alpha_tex=rx_create_texture(rx_to_data_path("images/waterdrop_alpha.png")); background_tex=rx_create_texture(rx_to_data_path("images/waterdrop_background.png")); glBindTexture(GL_TEXTURE_2D,background_tex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); //fbo glGenFramebuffers(1,&fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo); glGenTextures(1,&scene_normals_tex); glBindTexture(GL_TEXTURE_2D,scene_normals_tex); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,win_w,win_h,0,GL_RGBA,GL_UNSIGNED_BYTE,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,scene_normals_tex,0); glGenTextures(1,&scene_alpha_tex); glBindTexture(GL_TEXTURE_2D,scene_alpha_tex); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,win_w,win_h,0,GL_RGBA,GL_UNSIGNED_BYTE,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,scene_alpha_tex,0); if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE){ printf("Framebuffernotcomplete.\n"); returnfalse; } glBindFramebuffer(GL_FRAMEBUFFER,0); returntrue; }Example#240ShowfileFile: main.cpp Project: JoeyKanaly/OpenGL3-3intmain() { GLsizeimultiSamples=8; GLFWwindow*window=initWindow(); if(window==nullptr) { std::cout<>(t_now-t_start).count(); glm::mat4model; model=glm::rotate(model,time*glm::radians(180.f),glm::vec3(directionx,directiony,directionz)); glUniformMatrix4fv(uniModel,1,GL_FALSE,glm::value_ptr(model)); //Drawcube glDrawArrays(GL_TRIANGLES,0,36); glEnable(GL_STENCIL_TEST); //Drawfloor glStencilFunc(GL_ALWAYS,1,0xFF);//Setanystencilto1 glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE); glStencilMask(0xFF);//Writetostencilbuffer glDepthMask(GL_FALSE);//Don'twritetodepthbuffer glClear(GL_STENCIL_BUFFER_BIT);//Clearstencilbuffer(0bydefault) glDrawArrays(GL_TRIANGLES,36,6); //Drawcubereflection glStencilFunc(GL_EQUAL,1,0xFF);//Passtestifstencilvalueis1 glStencilMask(0x00);//Don'twriteanythingtostencilbuffer glDepthMask(GL_TRUE);//Writetodepthbuffer model=glm::scale(glm::translate(model,glm::vec3(0,0,-1)),glm::vec3(1,1,-1)); glUniformMatrix4fv(uniModel,1,GL_FALSE,glm::value_ptr(model)); glUniform3f(uniColor,0.3f,0.3f,0.3f); glDrawArrays(GL_TRIANGLES,0,36); glUniform3f(uniColor,1.0f,1.0f,1.0f); glDisable(GL_STENCIL_TEST); //Binddefaultframebufferanddrawcontentsofourframebuffer glBindFramebuffer(GL_FRAMEBUFFER,0); glBindVertexArray(vaoQuad); glDisable(GL_DEPTH_TEST); glUseProgram(screenShaderProgram); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,texColorBuffer); glDrawArrays(GL_TRIANGLES,0,6); //Swapbuffers SDL_GL_SwapWindow(window); } glDeleteRenderbuffers(1,&rboDepthStencil); glDeleteTextures(1,&texColorBuffer); glDeleteFramebuffers(1,&frameBuffer); glDeleteTextures(1,&texKitten); glDeleteTextures(1,&texPuppy); glDeleteProgram(screenShaderProgram); glDeleteShader(screenFragmentShader); glDeleteShader(screenVertexShader); glDeleteProgram(sceneShaderProgram); glDeleteShader(sceneFragmentShader); glDeleteShader(sceneVertexShader); glDeleteBuffers(1,&vboCube); glDeleteBuffers(1,&vboQuad); glDeleteVertexArrays(1,&vaoCube); glDeleteVertexArrays(1,&vaoQuad); SDL_GL_DeleteContext(context); SDL_Quit(); return0; }Example#270ShowfileFile: CubeTextureFBO.cpp Project: jkrmc12/Advanced-visualizationCubeTextureFBO::CubeTextureFBO(unsignedintsize,intformat,GLuinttargets,boolstoreDepth){ this->size=size; this->store_depths=storeDepth; constGLenumfaces[6]={GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z }; texture.resize(targets); //InitializeTexture glGenTextures(targets,&texture[0]); for(size_ti=0;isetPosition(_light_pos); } elseif(LT_DIRECTIONAL==m_type) { gml::vec3_t_light_pos=gml::extract3(gml::mul(worldview,gml::vec4_t(position,1.0))); gml::vec3_t_light_target=gml::extract3(gml::mul(worldview,gml::vec4_t(target,1.0))); gml::vec3_t_light_up=gml::extract3(gml::mul(worldview,gml::vec4_t(up,1.0))); m_cameras[0]->lookAt(_light_pos,_light_target,_light_up); } constShader::Shader*_pdptshdr=m_manager->getDepthShader(); if(LT_POINT==m_type) { for(unsignedshorti=0;i<6;++i){ glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,m_shadowmap,0); if(GL_FRAMEBUFFER_COMPLETE!=glCheckFramebufferStatus(GL_FRAMEBUFFER))return; glClear(GL_DEPTH_BUFFER_BIT); if(isGLError())return; if(_pdptshdr->getIsReady()){ _pdptshdr->bindGL(); if(isGLError())return; Shader::GLProgUniformsshaderUniforms; shaderUniforms.m_projection=m_cameras[i]->getProjection(); for(ObjectVec::const_iteratoritr=scene.begin();itr!=scene.end();++itr) { shaderUniforms.m_modelView=gml::mul(m_cameras[i]->getWorldView(), gml::mul(worldview,(*itr)->getObjectToWorld())); shaderUniforms.m_normalTrans=gml::transpose(gml::inverse(shaderUniforms.m_modelView)); if(!_pdptshdr->setUniforms(shaderUniforms,false)||isGLError())return; (*itr)->rasterize(); if(isGLError())return; } _pdptshdr->unbindGL(); glFinish(); } } } elseif(LT_DIRECTIONAL==m_type) { glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,m_shadowmap,0); if(GL_FRAMEBUFFER_COMPLETE!=glCheckFramebufferStatus(GL_FRAMEBUFFER))return; glClear(GL_DEPTH_BUFFER_BIT); if(isGLError())return; if(_pdptshdr->getIsReady()){ _pdptshdr->bindGL(); if(isGLError())return; Shader::GLProgUniformsshaderUniforms; shaderUniforms.m_projection=m_cameras[0]->getProjection(); for(ObjectVec::const_iteratoritr=scene.begin();itr!=scene.end();++itr) { shaderUniforms.m_modelView=gml::mul(m_cameras[0]->getWorldView(), gml::mul(worldview,(*itr)->getObjectToWorld())); shaderUniforms.m_normalTrans=gml::transpose(gml::inverse(shaderUniforms.m_modelView)); if(!_pdptshdr->setUniforms(shaderUniforms,false)||isGLError())return; (*itr)->rasterize(); if(isGLError())return; } _pdptshdr->unbindGL(); glFinish(); } } glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); }Example#290ShowfileFile: main.c Project: farosis/gfxvoidInitGLES(void) { GLintlinked; GLuintvertexShader; GLuintfragmentShader; assert((vertexShader=LoadShader("vert.glsl",GL_VERTEX_SHADER))!=0); assert((fragmentShader=LoadShader("frag.glsl",GL_FRAGMENT_SHADER))!=0); assert((program=glCreateProgram())!=0); glAttachShader(program,vertexShader); glAttachShader(program,fragmentShader); glLinkProgram(program); glGetProgramiv(program,GL_LINK_STATUS,&linked); if(!linked){ GLintinfoLen=0; glGetProgramiv(program,GL_INFO_LOG_LENGTH,&infoLen); if(infoLen>1){ char*infoLog=malloc(infoLen); glGetProgramInfoLog(program,infoLen,NULL,infoLog); fprintf(stderr,"Errorlinkingprogram:\n%s\n",infoLog); free(infoLog); } glDeleteProgram(program); exit(1); } //* GLuintfbid; glGenFramebuffers(1,&fbid); glBindFramebuffer(GL_FRAMEBUFFER,fbid); GLuinttexid; glGenTextures(1,&texid); glBindTexture(GL_TEXTURE_2D,texid); glPixelStorei(GL_UNPACK_ALIGNMENT,1); #ifdef_OGLES_30_ glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA32F,TARGET_SIZE,TARGET_SIZE,0,GL_RGBA,GL_FLOAT,NULL); #endif #ifdef_OGLES_20_ glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TARGET_SIZE,TARGET_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); #endif 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,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texid,0); GLuintrbid; glGenRenderbuffers(1,&rbid); glBindRenderbuffer(GL_RENDERBUFFER,rbid); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,TARGET_SIZE,TARGET_SIZE); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,rbid); CheckFrameBufferStatus(); //*/ glClearColor(0,0,0,0); glViewport(0,0,TARGET_SIZE,TARGET_SIZE); glEnable(GL_DEPTH_TEST); glUseProgram(program); }Example#300ShowfileFile: ContextSwitchRenderer.cpp Project: Cryptic-lollipop/ctsvoidContextSwitchRenderer::drawWorkload(){ SCOPED_TRACE(); if(mWorkload>8){ return;//Thistestdoesnotsupporthigherworkloads. } //Setthebackgroundclearcolortoblack. glClearColor(0.0f,0.0f,0.0f,0.0f); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); //Nocullingofbackfaces glDisable(GL_CULL_FACE); //Nodepthtesting glDisable(GL_DEPTH_TEST); EGLSyncKHRfence=eglCreateSyncKHR(mEglDisplay,EGL_SYNC_FENCE_KHR,NULL); constintTOTAL_NUM_CONTEXTS=NUM_WORKER_CONTEXTS+1; constfloatTRANSLATION=0.9f-(TOTAL_NUM_CONTEXTS*0.2f); for(inti=0;i



請為這篇文章評分?