예제 #1
0
PostProcess::PostProcess(int w, int h) {
    m_nScreenW = w;
    m_nScreenH = h;
    
    int u2 = 1;
    int v2 = 1;
    while(u2 < w) u2 *= 2;
    while(v2 < h) v2 *= 2;
    w = u2;
    h = v2;
    
    m_nTextureUniform = 0;
    m_nScaleUniform = 0;
    m_nMVPUniform = 0;
    m_nScreenSpaceVBO = 0;
    m_nBlitShader = 0;
    m_nFramebufferId = 0;
    m_nPositionAttrib = 0;
    m_nUvAttrib = 0;
    
    m_strInputUniform = "texture";
    m_strTypeUniform = "isDepth";
    m_strMvpUniform = "mvp";
    m_strClipPlanesUniform = "clip";
    m_strPositionAttribute = "position";
    m_StrUvAttribute = "uv";
    
    m_pInputTexture = 0;
    m_pOutputTexture = new Texture(w, h, Texture::RGBA_24);
    m_pShader = 0;
    CreateBlitShader();
    CreateFBO(w, h);
    CreateVBO();
}
예제 #2
0
//[-------------------------------------------------------]
//[ Private virtual PLRenderer::Surface functions         ]
//[-------------------------------------------------------]
bool SurfaceTextureBuffer::Init()
{
	// First, de-initialize the old stuff
	DeInit();

	// Can we use a nice frame buffer object?
	return CreateFBO();
}
예제 #3
0
void Initialize(int width, int height)
{
	printf("Version Pilote OpenGL : %s\n", glGetString(GL_VERSION));
	printf("Type de GPU : %s\n", glGetString(GL_RENDERER));
	printf("Fabricant : %s\n", glGetString(GL_VENDOR));
	printf("Version GLSL : %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
	int numExtensions;
	glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
	
	GLenum error = glewInit();
	if (error != GL_NO_ERROR) {
		// TODO
	}

	for (int index = 0; index < numExtensions; ++index)
	{
		printf("Extension[%d] : %s\n", index, glGetStringi(GL_EXTENSIONS, index));
	}
	
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	//glFrontFace(GL_CW);

	basicShader.LoadVertexShader("basic.vs");
	basicShader.LoadFragmentShader("basic.fs");
	basicShader.Create();

	textureShader.LoadVertexShader("texture.vs");
	textureShader.LoadFragmentShader("texture.fs");
	textureShader.Create();

	glGenBuffers(1, &cubeVBO);
	glGenBuffers(1, &cubeIBO);
	glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 8 * 3, g_cubeVertices, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cubeIBO);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * 6 * 2 * 3, g_cubeIndices, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	previousTime = glutGet(GLUT_ELAPSED_TIME);

	

	glGenVertexArrays(1, &cubeVAO);
	glBindVertexArray(cubeVAO);
	GLuint program = basicShader.GetProgram();
	glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
	GLint positionLocation = glGetAttribLocation(program, "a_position");
	glEnableVertexAttribArray(positionLocation);
	glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, 0);
	glBindVertexArray(0);

	CreateFBO(width, height);
}
예제 #4
0
ImposterManager::ImposterManager(Scene * _scene)
:	scene(_scene),
	sharedFBO(0)
{
	if(RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::IMPOSTERS_ENABLE))
	{
		CreateFBO();
	}
	RenderManager::Instance()->GetOptions()->AddObserver(this);
}
예제 #5
0
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occurred
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3EdgeDetection::InitView()
{
	// Store width and height of the viewport.
	m_i32TexWidth = PVRShellGet(prefWidth);
	m_i32TexHeight = PVRShellGet(prefHeight);

	/*	Get the current frame buffer object. As the program hasn't set it yet, this is the default buffer.
		On most platforms this just gives 0, but there are exceptions.	*/
	glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_i32OriginalFramebuffer);

	// Create string for error codes.
	CPVRTString ErrorStr;

	// Checks to see if the screen is rotated or not.
    bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Initialise Print3D
	if(m_Print3D.SetTextures(0,m_i32TexWidth,m_i32TexHeight,bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	// Load external textures and create internal ones.
	if(!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Load and compile the shaders & link programs
	if (!LoadShaders(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Creates and checks FBO creation
	if (!CreateFBO(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	SetupView(bRotate);

	return true;
}
void GBuffer::CreateBuffer() {
	GLuint width = glutGet(GLUT_WINDOW_WIDTH);
	GLuint height = glutGet(GLUT_WINDOW_HEIGHT);
	FBO = CreateFBO();
	positionTex = CreateRenderTexture(width, height, GL_RGBA32F, GL_FLOAT);
	normalTex = CreateRenderTexture(width, height, GL_RGBA16F, GL_FLOAT);
	albedoTex = CreateRenderTexture(width, height, GL_RGBA8, GL_UNSIGNED_BYTE);
	depthTex = CreateRenderTexture(width, height, GL_DEPTH_COMPONENT24, GL_UNSIGNED_BYTE);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, positionTex, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, normalTex, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, albedoTex, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTex, 0);
}
예제 #7
0
void TeapotRenderer::Init()
{
    //Settings
    glFrontFace( GL_CCW );

    //Load shader
    LoadShaders( &shader_param_, "Shaders/VS_ShaderPlain.vsh",
            "Shaders/ShaderPlain.fsh" );

    //Create Index buffer
    num_indices_ = sizeof(teapotIndices) / sizeof(teapotIndices[0]);
    glGenBuffers( 1, &ibo_ );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ibo_ );
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(teapotIndices), teapotIndices,
            GL_STATIC_DRAW );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );

    //Create VBO
    num_vertices_ = sizeof(teapotPositions) / sizeof(teapotPositions[0]) / 3;
    int32_t iStride = sizeof(TEAPOT_VERTEX);
    int32_t iIndex = 0;
    TEAPOT_VERTEX* p = new TEAPOT_VERTEX[num_vertices_];
    for( int32_t i = 0; i < num_vertices_; ++i )
    {
        p[i].pos[0] = teapotPositions[iIndex];
        p[i].pos[1] = teapotPositions[iIndex + 1];
        p[i].pos[2] = teapotPositions[iIndex + 2];

        p[i].normal[0] = teapotNormals[iIndex];
        p[i].normal[1] = teapotNormals[iIndex + 1];
        p[i].normal[2] = teapotNormals[iIndex + 2];
        iIndex += 3;
    }
    glGenBuffers( 1, &vbo_ );
    glBindBuffer( GL_ARRAY_BUFFER, vbo_ );
    glBufferData( GL_ARRAY_BUFFER, iStride * num_vertices_, p, GL_STATIC_DRAW );
    glBindBuffer( GL_ARRAY_BUFFER, 0 );

    delete[] p;

    UpdateViewport();
    mat_model_ = ndk_helper::Mat4::Translation( 0, 0, -15.f );

    ndk_helper::Mat4 mat = ndk_helper::Mat4::RotationX( M_PI / 3 );
    mat_model_ = mat * mat_model_;

    CreateFBO();
}
예제 #8
0
void ImposterManager::HandleEvent(Observable * observable)
{
	RenderOptions * renderOptions = dynamic_cast<RenderOptions*>(observable);
	if(renderOptions)
	{
		bool areImpostersEnabled = renderOptions->IsOptionEnabled(RenderOptions::IMPOSTERS_ENABLE);
		if(areImpostersEnabled)
		{
			CreateFBO();
		}
		else
		{
			ReleaseFBO();
		}
	}
}
예제 #9
0
void PostProcess::Resize(int w, int h) {
    m_nScreenW = w;
    m_nScreenH = h;
    
    int u2 = 1;
    int v2 = 1;
    while(u2 < w) u2 *= 2;
    while(v2 < h) v2 *= 2;
    w = u2;
    h = v2;
    
    DestroyFBO();
    if (m_pOutputTexture != 0)
        delete m_pOutputTexture;
    m_pOutputTexture = new Texture(w, h, Texture::RGBA_24);
    CreateFBO(w, h);
}
예제 #10
0
파일: vr.c 프로젝트: isuker/Quakespasm-Rift
qboolean VR_Enable()
{
	int i;
	if( ovr_Initialize(NULL) != ovrSuccess ) {
		Con_Printf("Failed to Initialize Oculus SDK");
		return false;
	}

	if( ovrHmd_Create(0, &hmd) != ovrSuccess ) {
		Con_Printf("Failed to get HMD");
		return false;
	}

	if( !InitOpenGLExtensions() ) {
		Con_Printf("Failed to initialize OpenGL extensions");
		return false;
	}

	ovrHmd_CreateMirrorTextureGL(hmd, GL_RGBA, glwidth, glheight, (ovrTexture**)&mirror_texture);
	glGenFramebuffersEXT(1, &mirror_fbo);
	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, mirror_fbo);
	glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mirror_texture->OGL.TexId, 0);
	glFramebufferRenderbufferEXT(GL_READ_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);

	for( i = 0; i < 2; i++ ) {
		ovrSizei size = ovrHmd_GetFovTextureSize(hmd, (ovrEyeType)i, hmd->DefaultEyeFov[i], 1);

		eyes[i].index = i;
		eyes[i].fbo = CreateFBO(size.w, size.h);
		eyes[i].render_desc = ovrHmd_GetRenderDesc(hmd, (ovrEyeType)i, hmd->DefaultEyeFov[i]);
		eyes[i].fov_x = (atan(hmd->DefaultEyeFov[i].LeftTan) + atan(hmd->DefaultEyeFov[i].RightTan)) / M_PI_DIV_180;
		eyes[i].fov_y = (atan(hmd->DefaultEyeFov[i].UpTan) + atan(hmd->DefaultEyeFov[i].DownTan)) / M_PI_DIV_180;
	}

	ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence|ovrHmdCap_DynamicPrediction);
	ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection|ovrTrackingCap_Position, 0);
	
	wglSwapIntervalEXT(0); // Disable V-Sync

	vr_initialized = true;
	return true;
}
예제 #11
0
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occured
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3ShadowMapping::InitView()
{
	CPVRTString ErrorStr;	    
    
	m_bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//	Load textures
	if (!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//	Load and compile the shaders & link programs
	if (!LoadPFX(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Map the individual effects to make it easier to address them
	for (unsigned int i=0; i < m_pPFXEffectParser->GetNumberEffects(); i++)
	{
		// Store the indices for the individual effects
		if (m_pPFXEffectParser->GetEffect(i).Name == c_RenderShadowMapEffectName)
			m_iEffectIndex[INDEX_RENDERSHADOW] = i;
		else if (m_pPFXEffectParser->GetEffect(i).Name == c_RenderSceneEffectName)
			m_iEffectIndex[INDEX_RENDERSCENE] = i;		
	}	

	if (!CreateFBO(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//	Initialize Print3D
	if (m_Print3D.SetTextures(0, PVRShellGet(prefWidth), PVRShellGet(prefHeight),m_bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialize Print3D\n");
		return false;
	}

	// Use a nice bright blue as clear colour
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	// Enable culling
	glEnable(GL_CULL_FACE);	

	// and depth testing
	glEnable(GL_DEPTH_TEST);

	return true;
}