C++ (Cpp) glGenRenderbuffers Examples - HotExamples
文章推薦指數: 80 %
C++ (Cpp) glGenRenderbuffers - 6 examples found. These are the top rated real world C++ (Cpp) examples of glGenRenderbuffers extracted from open source ...
Togglenavigation
HotExamplesENENRUDEFRESPTITJPZH
C++PHPC#JavaGoC++PythonJSTS
SearchC++(Cpp)glGenRenderbuffersExamplesC++(Cpp)glGenRenderbuffers-6examplesfound.ThesearethetopratedrealworldC++(Cpp)examplesofglGenRenderbuffersextractedfromopensourceprojects.Youcanrateexamplestohelpusimprovethequalityofexamples.ProgrammingLanguage:C++(Cpp)Method/Function:glGenRenderbuffersExamplesathotexamples.com:6reportthisadRelatedLEDG_Off__kill_fasyncswitch_event_destroyrfkill_registeraml_write_reg32glutBitmapCharacterKConfigTcl_GetDoubleutil_unreference_framebuffer_stateTwistreportthisadRelatedinlangsZendda_File_Images(PHP)Google_SubscriptionSnippet(PHP)vitima(C#)UsersContext(C#)NewEchoResponse(Go)NewStepRemoveNode(Go)RegexpQuery(Java)StockBook(Java)render_traceback(Python)ConfigWindowController(Python)reportthisadExample#10ShowfileFile:
renderWaterTexture.c
Project:
xiaobai1984/OpenGLGLUSuintinitWaterTexture(GLUSfloatwaterPlaneLength)
{
GLfloatprojectionMatrixWaterTexture[16];
GLfloatmodelViewMatrixWaterTexture[16];
GLUSshapeplane;
GLUStextfilevertexSource;
GLUStextfilefragmentSource;
glusFileLoadText("../Example15/shader/WaterTexture.vert.glsl",&vertexSource);
glusFileLoadText("../Example15/shader/WaterTexture.frag.glsl",&fragmentSource);
glusProgramBuildFromSource(&g_programWaterTexture,(constGLUSchar**)&vertexSource.text,0,0,0,(constGLUSchar**)&fragmentSource.text);
glusFileDestroyText(&vertexSource);
glusFileDestroyText(&fragmentSource);
//
g_projectionMatrixWaterTextureLocation=glGetUniformLocation(g_programWaterTexture.program,"u_projectionMatrix");
g_modelViewMatrixWaterTextureLocation=glGetUniformLocation(g_programWaterTexture.program,"u_modelViewMatrix");
g_waterPlaneLengthWaterTextureLocation=glGetUniformLocation(g_programWaterTexture.program,"u_waterPlaneLength");
g_passedTimeWaterTextureLocation=glGetUniformLocation(g_programWaterTexture.program,"u_passedTime");
g_waveParametersWaterTextureLocation=glGetUniformLocation(g_programWaterTexture.program,"u_waveParameters");
g_waveDirectionsWaterTextureLocation=glGetUniformLocation(g_programWaterTexture.program,"u_waveDirections");
g_vertexWaterTextureLocation=glGetAttribLocation(g_programWaterTexture.program,"a_vertex");
g_texCoordWaterTextureLocation=glGetAttribLocation(g_programWaterTexture.program,"a_texCoord");
//
glGenTextures(1,&g_mirrorTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,g_mirrorTexture);
glTexImage2D(GL_TEXTURE_2D,0,GLUS_RGB,TEXTURE_SIZE,TEXTURE_SIZE,0,GLUS_RGB,GL_UNSIGNED_BYTE,0);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glBindTexture(GL_TEXTURE_2D,0);
//
glGenRenderbuffers(1,&g_depthMirrorTexture);
glBindRenderbuffer(GL_RENDERBUFFER,g_depthMirrorTexture);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,TEXTURE_SIZE,TEXTURE_SIZE);
glBindRenderbuffer(GL_RENDERBUFFER,0);
//
glGenFramebuffers(1,&g_fboWaterTexture);
glBindFramebuffer(GL_FRAMEBUFFER,g_fboWaterTexture);
//Attachthecolorbuffer...
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,g_mirrorTexture,0);
//...andthedepthbuffer,
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,g_depthMirrorTexture);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)
{
printf("GL_FRAMEBUFFER_COMPLETEerror0x%x",glCheckFramebufferStatus(GL_FRAMEBUFFER));
returnGLUS_FALSE;
}
glBindFramebuffer(GL_FRAMEBUFFER,0);
//
glBindVertexArray(0);
//
glusShapeCreatePlanef(&plane,TEXTURE_SIZE/2.0f);
g_numberIndicesWaterTexture=plane.numberIndices;
glGenBuffers(1,&g_verticesWaterTextureVBO);
glBindBuffer(GL_ARRAY_BUFFER,g_verticesWaterTextureVBO);
glBufferData(GL_ARRAY_BUFFER,plane.numberVertices*4*sizeof(GLfloat),(GLfloat*)plane.vertices,GL_STATIC_DRAW);
glGenBuffers(1,&g_texCoordsWaterTextureVBO);
glBindBuffer(GL_ARRAY_BUFFER,g_texCoordsWaterTextureVBO);
glBufferData(GL_ARRAY_BUFFER,plane.numberVertices*2*sizeof(GLfloat),(GLfloat*)plane.texCoords,GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);
glGenBuffers(1,&g_indicesWaterTextureVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,g_indicesWaterTextureVBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,plane.numberIndices*sizeof(GLuint),(GLuint*)plane.indices,GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
glusShapeDestroyf(&plane);
//
glUseProgram(g_programWaterTexture.program);
glusMatrix4x4LookAtf(modelViewMatrixWaterTexture,0.0f,0.0f,5.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glUniformMatrix4fv(g_modelViewMatrixWaterTextureLocation,1,GL_FALSE,modelViewMatrixWaterTexture);
glusMatrix4x4Orthof(projectionMatrixWaterTexture,-(GLfloat)TEXTURE_SIZE/2,(GLfloat)TEXTURE_SIZE/2,
-(GLfloat)TEXTURE_SIZE/2,(GLfloat)TEXTURE_SIZE/2,1.0f,100.0f);
glUniformMatrix4fv(g_projectionMatrixWaterTextureLocation,1,GL_FALSE,projectionMatrixWaterTexture);
glUniform1f(g_waterPlaneLengthWaterTextureLocation,waterPlaneLength);
//
glGenVertexArrays(1,&g_vaoWaterTexture);
glBindVertexArray(g_vaoWaterTexture);
glBindBuffer(GL_ARRAY_BUFFER,g_verticesWaterTextureVBO);
glVertexAttribPointer(g_vertexWaterTextureLocation,4,GL_FLOAT,GL_FALSE,0,0);
glEnableVertexAttribArray(g_vertexWaterTextureLocation);
glBindBuffer(GL_ARRAY_BUFFER,g_texCoordsWaterTextureVBO);
glVertexAttribPointer(g_texCoordWaterTextureLocation,2,GL_FLOAT,GL_FALSE,0,0);
glEnableVertexAttribArray(g_texCoordWaterTextureLocation);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,g_indicesWaterTextureVBO);
//
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
returng_mirrorTexture;
}Example#20ShowfileFile:
OculusManager.cpp
Project:
mathieu-h/AroundTheSpaceOculusManager&OculusManager::getOculusManager()
{
staticOculusManager*oculusManager=NULL;
if(oculusManager==NULL)
{
oculusManager=newOculusManager();
if(!ovr_Initialize()){
fprintf(stderr,"FailedtoinitializetheOculusSDK");
}
//=*OculusManager::getHmd();
g_Hmd=ovrHmd_Create(0);
if(!g_Hmd)
{
printf("NoOculusRiftdeviceattached,usingvirtualversion...\n");
g_Hmd=ovrHmd_CreateDebug(ovrHmd_DK2);
}
printf("initializedHMD:%s-%s\n",g_Hmd->Manufacturer,g_Hmd->ProductName);
if(!glfwInit())exit(EXIT_FAILURE);
if(l_MultiSampling)glfwWindowHint(GLFW_SAMPLES,4);elseglfwWindowHint(GLFW_SAMPLES,0);
booll_DirectMode=((g_Hmd->HmdCaps&ovrHmdCap_ExtendDesktop)==0);
GLFWmonitor*l_Monitor;
ovrSizeil_ClientSize;
if(l_DirectMode)
{
printf("Runningin\"Direct\"mode...\n");
l_Monitor=NULL;
l_ClientSize.w=g_Hmd->Resolution.w/2;//Somethingreasonable,smaller,butmaintainaspectratio...
l_ClientSize.h=g_Hmd->Resolution.h/2;//Somethingreasonable,smaller,butmaintainaspectratio...
}
else//ExtendedDesktopmode...
{
printf("Runningin\"ExtendedDesktop\"mode...\n");
intl_Count;
GLFWmonitor**l_Monitors=glfwGetMonitors(&l_Count);
switch(l_Count)
{
case0:
printf("Nomonitorsfound,exiting...\n");
exit(EXIT_FAILURE);
break;
case1:
printf("Twomonitorsexpected,foundonlyone,usingprimary...\n");
l_Monitor=glfwGetPrimaryMonitor();
break;
case2:
printf("Twomonitorsfound,usingsecondmonitor...\n");
l_Monitor=l_Monitors[1];
break;
default:
printf("Morethantwomonitorsfound,usingsecondmonitor...\n");
l_Monitor=l_Monitors[1];
}
l_ClientSize.w=g_Hmd->Resolution.w;//1920forDK2...
l_ClientSize.h=g_Hmd->Resolution.h;//1080forDK2...
}
l_Window=glfwCreateWindow(l_ClientSize.w,l_ClientSize.h,"GLFWOculusRiftTest",l_Monitor,NULL);
if(!l_Window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
#ifdefined(_WIN32)
if(l_DirectMode)
{
ovrBooll_AttachResult=ovrHmd_AttachToWindow(g_Hmd,glfwGetWin32Window(l_Window),NULL,NULL);
if(!l_AttachResult)
{
printf("Couldnotattachtowindow...");
exit(EXIT_FAILURE);
}
}
#endif
glfwMakeContextCurrent(l_Window);
glewExperimental=GL_TRUE;
GLenuml_GlewResult=glewInit();
if(l_GlewResult!=GLEW_OK)
{
printf("glewInit()error.\n");
exit(EXIT_FAILURE);
}
intl_Major=glfwGetWindowAttrib(l_Window,GLFW_CONTEXT_VERSION_MAJOR);
intl_Minor=glfwGetWindowAttrib(l_Window,GLFW_CONTEXT_VERSION_MINOR);
intl_Profile=glfwGetWindowAttrib(l_Window,GLFW_OPENGL_PROFILE);
printf("OpenGL:%d.%d",l_Major,l_Minor);
if(l_Major>=3)//ProfilesintroducedinOpenGL3.0...
{
if(l_Profile==GLFW_OPENGL_COMPAT_PROFILE)printf("GLFW_OPENGL_COMPAT_PROFILE\n");elseprintf("GLFW_OPENGL_CORE_PROFILE\n");
}
printf("Vendor:%s\n",(char*)glGetString(GL_VENDOR));
printf("Renderer:%s\n",(char*)glGetString(GL_RENDERER));
ovrSizeil_EyeTextureSizes[2];
l_EyeTextureSizes[ovrEye_Left]=ovrHmd_GetFovTextureSize(g_Hmd,ovrEye_Left,g_Hmd->MaxEyeFov[ovrEye_Left],1.0f);
l_EyeTextureSizes[ovrEye_Right]=ovrHmd_GetFovTextureSize(g_Hmd,ovrEye_Right,g_Hmd->MaxEyeFov[ovrEye_Right],1.0f);
//Combineforonetextureforbotheyes...
g_RenderTargetSize.w=l_EyeTextureSizes[ovrEye_Left].w+l_EyeTextureSizes[ovrEye_Right].w;
g_RenderTargetSize.h=(l_EyeTextureSizes[ovrEye_Left].h>l_EyeTextureSizes[ovrEye_Right].h?l_EyeTextureSizes[ovrEye_Left].h:l_EyeTextureSizes[ovrEye_Right].h);
//CreatetheFBObeingasingleoneforbotheyes(thisisopenfordebate)...
glGenFramebuffers(1,&l_FBOId);
glBindFramebuffer(GL_FRAMEBUFFER,l_FBOId);
//Thetexturewe'regoingtorenderto...
glGenTextures(1,&l_TextureId);
//"Bind"thenewlycreatedtexture:allfuturetexturefunctionswillmodifythistexture...
glBindTexture(GL_TEXTURE_2D,l_TextureId);
//GiveanemptyimagetoOpenGL(thelast"0")
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,g_RenderTargetSize.w,g_RenderTargetSize.h,0,GL_RGBA,GL_UNSIGNED_BYTE,0);
//Linearfiltering...
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
//CreateDepthBuffer...
glGenRenderbuffers(1,&l_DepthBufferId);
glBindRenderbuffer(GL_RENDERBUFFER,l_DepthBufferId);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,g_RenderTargetSize.w,g_RenderTargetSize.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,l_DepthBufferId);
//Setthetextureasourcolourattachment#0...
glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,l_TextureId,0);
//Setthelistofdrawbuffers...
GLenuml_GLDrawBuffers[1]={GL_COLOR_ATTACHMENT0};
glDrawBuffers(1,l_GLDrawBuffers);//"1"isthesizeofDrawBuffers
//CheckifeverythingisOK...
GLenuml_Check=glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
if(l_Check!=GL_FRAMEBUFFER_COMPLETE)
{
printf("ThereisaproblemwiththeFBO.\n");
exit(EXIT_FAILURE);
}
//Unbind...
glBindRenderbuffer(GL_RENDERBUFFER,0);
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
//Setuptexturesforeacheye...
//Lefteye...
g_EyeTextures[ovrEye_Left].Header.API=ovrRenderAPI_OpenGL;
g_EyeTextures[ovrEye_Left].Header.TextureSize=g_RenderTargetSize;
g_EyeTextures[ovrEye_Left].Header.RenderViewport.Pos.x=0;
g_EyeTextures[ovrEye_Left].Header.RenderViewport.Pos.y=0;
g_EyeTextures[ovrEye_Left].Header.RenderViewport.Size=l_EyeTextureSizes[ovrEye_Left];
((ovrGLTexture&)(g_EyeTextures[ovrEye_Left])).OGL.TexId=l_TextureId;
//Righteye(mostlythesameasleftbutwiththeviewportontherightsideofthetexture)...
g_EyeTextures[ovrEye_Right]=g_EyeTextures[ovrEye_Left];
g_EyeTextures[ovrEye_Right].Header.RenderViewport.Pos.x=(g_RenderTargetSize.w+1)/2;
g_EyeTextures[ovrEye_Right].Header.RenderViewport.Pos.y=0;
//OculusRifteyeconfigurations...
g_Cfg.OGL.Header.API=ovrRenderAPI_OpenGL;
g_Cfg.OGL.Header.RTSize.w=l_ClientSize.w;
g_Cfg.OGL.Header.RTSize.h=l_ClientSize.h;
g_Cfg.OGL.Header.Multisample=(l_MultiSampling?1:0);
#ifdefined(_WIN32)
g_Cfg.OGL.Window=glfwGetWin32Window(l_Window);
g_Cfg.OGL.DC=GetDC(g_Cfg.OGL.Window);
#elifdefined(__linux__)
l_Cfg.OGL.Win=glfwGetX11Window(l_Window);
l_Cfg.OGL.Disp=glfwGetX11Display();
#endif
//Enablecapabilities...
//ovrHmd_SetEnabledCaps(g_Hmd,ovrHmdCap_LowPersistence|ovrHmdCap_DynamicPrediction);
ovrBooll_ConfigureResult=ovrHmd_ConfigureRendering(g_Hmd,&g_Cfg.Config,g_DistortionCaps,g_Hmd->MaxEyeFov,g_EyeRenderDesc);
glUseProgram(0);//AvoidOpenGLstateleakinovrHmd_ConfigureRendering...
if(!l_ConfigureResult)
{
printf("Configurefailed.\n");
exit(EXIT_FAILURE);
}
//StartthesensorwhichprovidestheRift’sposeandmotion...
uint32_tl_SupportedSensorCaps=ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection|ovrTrackingCap_Position;
uint32_tl_RequiredTrackingCaps=0;
ovrBooll_TrackingResult=ovrHmd_ConfigureTracking(g_Hmd,l_SupportedSensorCaps,l_RequiredTrackingCaps);
if(!l_TrackingResult)
{
printf("Couldnotstarttracking...");
exit(EXIT_FAILURE);
}
//Projectionmatriciforeacheyewillnotchangeatruntime,wecansetthemhere...
g_ProjectionMatrici[ovrEye_Left]=ovrMatrix4f_Projection(g_EyeRenderDesc[ovrEye_Left].Fov,0.3f,100.0f,true);
g_ProjectionMatrici[ovrEye_Right]=ovrMatrix4f_Projection(g_EyeRenderDesc[ovrEye_Right].Fov,0.3f,100.0f,true);
//IPDoffsetvalueswillnotchangeatruntime,wecansetthemhere...
g_EyeOffsets[ovrEye_Left]=g_EyeRenderDesc[ovrEye_Left].HmdToEyeViewOffset;
g_EyeOffsets[ovrEye_Right]=g_EyeRenderDesc[ovrEye_Right].HmdToEyeViewOffset;
ovrHmd_RecenterPose(g_Hmd);
return*oculusManager;
}
}Example#30ShowfileFile:
CARenderImage.cpp
Project:
DreamCastleShanghai/dkomClientboolCARenderImage::initWithWidthAndHeight(intw,inth,CAImage::PixelFormateFormat,GLuintuDepthStencilFormat)
{
CCAssert(eFormat!=CAImage::PixelFormat_A8,"onlyRGBandRGBAformatsarevalidforarendertexture");
boolbRet=false;
unsignedchar*data=NULL;
do
{
glGetIntegerv(GL_FRAMEBUFFER_BINDING,&m_nOldFBO);
//texturesmustbepoweroftwosquared
unsignedintpowW=(unsignedint)(w+1)/2;
powW*=2;
unsignedintpowH=(unsignedint)(h+1)/2;
powH*=2;
data=(unsignedchar*)malloc((unsignedlong)(powW*powH*4));
CC_BREAK_IF(!data);
memset(data,0,(unsignedlong)(powW*powH*4));
m_ePixelFormat=eFormat;
m_uPixelsWide=powW;
m_uPixelsHigh=powH;
glPixelStorei(GL_UNPACK_ALIGNMENT,8);
glGenTextures(1,&m_uName);
ccGLBindTexture2D(m_uName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_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,m_uPixelsWide,m_uPixelsHigh,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
GLintoldRBO;
glGetIntegerv(GL_RENDERBUFFER_BINDING,&oldRBO);
//generateFBO
glGenFramebuffers(1,&m_uFBO);
glBindFramebuffer(GL_FRAMEBUFFER,m_uFBO);
//associateImagewithFBO
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_uName,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,"CouldnotattachImagetoframebuffer");
ccGLBindTexture2D(m_uName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
CAImageView*imageView=CAImageView::createWithFrame(DRect(0,0,m_uPixelsWide,m_uPixelsHigh));
ccBlendFunctBlendFunc={GL_ONE,GL_ONE_MINUS_SRC_ALPHA};
imageView->setBlendFunc(tBlendFunc);
this->addSubview(imageView);
this->setImageView(imageView);
glBindRenderbuffer(GL_RENDERBUFFER,oldRBO);
glBindFramebuffer(GL_FRAMEBUFFER,m_nOldFBO);
//Diabledbydefault.
m_bAutoDraw=false;
bRet=true;
}while(0);
CC_SAFE_FREE(data);
returnbRet;
}Example#40ShowfileFile:
fbo.cpp
Project:
BadyRaty/PPSSPP-CoreFBO*fbo_create(intwidth,intheight,intnum_color_textures,boolz_stencil,FBOColorDepthcolorDepth){
CheckGLExtensions();
#ifndefUSING_GLES2
if(!gl_extensions.FBO_ARB)
returnfbo_ext_create(width,height,num_color_textures,z_stencil,colorDepth);
#endif
FBO*fbo=newFBO();
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);
#ifdefUSING_GLES2
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);
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);
#endif
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);
returnfbo;
}Example#50ShowfileFile:
qglframebufferobject.cpp
Project:
maxxant/qtvoidQGLFramebufferObjectPrivate::init(QGLFramebufferObject*q,constQSize&sz,
QGLFramebufferObject::Attachmentattachment,
GLenumtexture_target,GLenuminternal_format,
GLintsamples,boolmipmap)
{
QGLContext*ctx=const_cast
延伸文章資訊
- 1glGenRenderbuffers - OpenGL 4 Reference Pages - Khronos ...
glGenRenderbuffers returns n renderbuffer object names in renderbuffers . There is no guarantee t...
- 2Java GLES20.glGenRenderbuffers方法代碼示例- 純淨天空
本文整理匯總了Java中android.opengl.GLES20.glGenRenderbuffers方法的典型用法代碼示例。如果您正苦於以下問題:Java GLES20.glGenRende...
- 3glgenrenderbuffers(3g) [centos man page]
glGenRenderbuffers returns n renderbuffer object names in renderbuffers. There is no guarantee th...
- 4创建一个帧缓冲 - LearnOpenGL-CN
GLuint rbo; glGenRenderbuffers(1, &rbo); glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbuffer...
- 5glGenRenderbuffers - generate renderbuffer object names
glGenRenderbuffers returns n renderbuffer object names in renderbuffers. There is no guarantee th...