void RenderDevice::updateLightDepth( LightState& state ) { #if 0 const LightPtr& light = state.light; assert( light->getLightType() == LightType::Directional ); Texture* shadowDepthTexture; if( !shadowDepthBuffer ) { shadowDepthBuffer = createRenderBuffer( Settings(512, 512) ); } if( shadowTextures.find(light) == shadowTextures.end() ) { shadowDepthTexture = shadowDepthBuffer->createRenderTexture(); shadowTextures[light] = shadowDepthTexture; } else { shadowDepthTexture = shadowTextures[light]; } CameraPtr lightCamera( new Camera(*camera) ); TransformPtr lightTransform( new Transform(*state.transform.get()) ); EntityPtr lightCameraEntity( new Entity("ShadowCamera") ); lightCameraEntity->addTransform(); /*Component( lightTransform );*/ lightCameraEntity->addComponent( lightCamera ); RenderView* lightView = new View(lightCamera, shadowDepthBuffer); if( !shadowDepthBuffer->check() ) return; // TODO: turn off color writes (glColorMask?) lightView->update(); shadowDepthBuffer->unbind(); Matrix4x4 bias; bias.identity(); bias.m11 = 0.5f; bias.m22 = 0.5f; bias.m33 = 0.5f; bias.tx = 0.5f; bias.ty = 0.5f; bias.tz = 0.5f; const Frustum& frustum = lightCamera->getFrustum(); const Matrix4x4& matProjection = frustum.projectionMatrix; state.projection = lightCamera->getViewMatrix() * matProjection * bias; #endif }
int FBO::attach() { buffers_[eDepth]= createRenderBuffer(); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size_[eWidth], size_[eHeight]); if (isTexture_) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffers_[eColor], 0); } else { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, buffers_[eColor]); } glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, buffers_[eDepth]); if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { std::cout<<"failed to make complete framebuffer object:"<<std::endl<<glCheckFramebufferStatus(GL_FRAMEBUFFER); return 0; } GetGLError(); return name_; }
void Fluids::createBuffers() { int tex_fmt = GL_R32F; int tex_int_fmt = GL_RED; frambuffer_ = createFrameBuffer(); //velocity_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA); density_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); CHECK_GL_ERROR(); velocity_accum_u_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); CHECK_GL_ERROR(); velocity_accum_v_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); velocity_accum_ut_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); velocity_accum_vt_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); velocity_accum_u0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); // 7 velocity_accum_v0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); // 8 velocity_accum_u0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); velocity_accum_v0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); //velocity_accum_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA ); //velocity_accum2_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA ); density_accum0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); density_accum0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); density_accum_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); density_accum_t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); //tex_fmt = GL_RGBA32F; //tex_int_fmt = GL_RGBA; p_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); p_prev_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); printf("density_accum: 1: %d 2: %d\n", density_accum0_, density_accum_); depth_ = createRenderBuffer(128, 128); }
bool RenderDevice::init() { bool failed = false; char *vendor = (char *)glGetString( GL_VENDOR ); char *renderer = (char *)glGetString( GL_RENDERER ); char *version = (char *)glGetString( GL_VERSION ); Modules::log().writeInfo( "Initializing GL2 backend using OpenGL driver '%s' by '%s' on '%s'", version, vendor, renderer ); // Init extensions if( !initOpenGLExtensions() ) { Modules::log().writeError( "Could not find all required OpenGL function entry points" ); failed = true; } // Check that OpenGL 2.0 is available if( glExt::majorVersion * 10 + glExt::minorVersion < 20 ) { Modules::log().writeError( "OpenGL 2.0 not available" ); failed = true; } // Check that required extensions are supported if( !glExt::EXT_framebuffer_object ) { Modules::log().writeError( "Extension EXT_framebuffer_object not supported" ); failed = true; } if( !glExt::EXT_texture_filter_anisotropic ) { Modules::log().writeError( "Extension EXT_texture_filter_anisotropic not supported" ); failed = true; } if( !glExt::EXT_texture_compression_s3tc ) { Modules::log().writeError( "Extension EXT_texture_compression_s3tc not supported" ); failed = true; } if( !glExt::EXT_texture_sRGB ) { Modules::log().writeError( "Extension EXT_texture_sRGB not supported" ); failed = true; } if( failed ) { Modules::log().writeError( "Failed to init renderer backend, debug info following" ); char *exts = (char *)glGetString( GL_EXTENSIONS ); Modules::log().writeInfo( "Supported extensions: '%s'", exts ); return false; } // Get capabilities _caps.texFloat = glExt::ARB_texture_float ? 1 : 0; _caps.texNPOT = glExt::ARB_texture_non_power_of_two ? 1 : 0; _caps.rtMultisampling = glExt::EXT_framebuffer_multisample ? 1 : 0; // Find supported depth format (some old ATI cards only support 16 bit depth for FBOs) _depthFormat = GL_DEPTH_COMPONENT24; uint32 testBuf = createRenderBuffer( 32, 32, TextureFormats::BGRA8, true, 1, 0 ); if( testBuf == 0 ) { _depthFormat = GL_DEPTH_COMPONENT16; Modules::log().writeWarning( "Render target depth precision limited to 16 bit" ); } else destroyRenderBuffer( testBuf ); initStates(); resetStates(); return true; }
int FBO::initToFramebuffer() { isTexture_=false; name_=createFrameBuffer(); return buffers_[eColor]= createRenderBuffer(); }
bool setupGraphics(int w, int h) { printGLString("Version", GL_VERSION); printGLString("Vendor", GL_VENDOR); printGLString("Renderer", GL_RENDERER); printGLString("Extensions", GL_EXTENSIONS); LOGI("setupGraphics(%d, %d)", w, h); gProgram = createProgram(gVertexShader, gFragmentShader); if (!gProgram) { LOGE("Could not create program."); return false; } gvPositionHandle = glGetAttribLocation(gProgram, "vPosition"); gShaderTexCoord = glGetAttribLocation ( gProgram, "a_texCoord" ); gvpMatrix = glGetUniformLocation( gProgram, "u_TransMatrix" ); gShaderImgTexture = glGetUniformLocation( gProgram, "s_ImgTexture" ); makeCheckImages(); glGenTextures( 1, &texName ); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 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, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glUseProgram(gProgram); glEnableVertexAttribArray(gvPositionHandle); glEnableVertexAttribArray( gShaderTexCoord ); glUniform1i ( gShaderImgTexture, 0 ); gWidthd2 = w / 2; gHeightd2 = h / 2; esMatrixLoadIdentity( &gOrthographic ); //esOrtho(&gOrthographic, 0, mWidth, -mHeight, 0, 5.0f, -5.0f ); esOrtho(&gOrthographic, -gWidthd2, gWidthd2, -gHeightd2, gHeightd2, 5.0f, -5.0f ); ESMatrix modelview; esMatrixLoadIdentity( &gMatrix ); esMatrixLoadIdentity( &modelview ); esMatrixMultiply( &gMatrix, &modelview, &gOrthographic ); glViewport(0, 0, w, h); glUniformMatrix4fv( gvpMatrix, 1, GL_FALSE, (GLfloat *)&gMatrix ); //glGenBuffers( 1, &guVbo ); //glBindBuffer( GL_ARRAY_BUFFER, guVbo ); //glBufferData( GL_ARRAY_BUFFER, 5 * 6 * sizeof( GLfloat), gTriangleVertices, GL_STREAM_DRAW ); glActiveTexture ( GL_TEXTURE0 ); glBindTexture ( GL_TEXTURE_2D, texName ); createRenderBuffer(); //ESMatrix matrixTrans; //ESMatrix modelview; //esMatrixLoadIdentity( &modelview ); //esTranslate( &modelview, -fx, fy, 0.0 ); //esMatrixMultiply( &matrixTrans, &modelview, &gOrthographic ); glUniformMatrix4fv( gvpMatrix, 1, GL_FALSE, (GLfloat *)&gOrthographic ); return true; }