Beispiel #1
0
void Initialize()
{
    RenderContext& rc = GlobalRenderContext;

    glswInit();
    glswSetPath("../", ".glsl");
    glswAddDirectiveToken("GL3", "#version 130");

    rc.VertexBuffer = CreateVertexBuffer();
    rc.IndexBuffer = CreateIndexBuffer();
    
#if defined(__APPLE__)
    rc.ToonHandle = BuildProgram("Toon.Vertex.GL2", "Toon.Fragment.GL2");
#else
    rc.ToonHandle = BuildProgram("Toon.Vertex.GL3", "Toon.Fragment.GL3");
#endif
    
    rc.ToonUniforms.Projection = glGetUniformLocation(rc.ToonHandle, "Projection");
    rc.ToonUniforms.Modelview = glGetUniformLocation(rc.ToonHandle, "Modelview");
    rc.ToonUniforms.NormalMatrix = glGetUniformLocation(rc.ToonHandle, "NormalMatrix");
    rc.ToonUniforms.LightPosition = glGetUniformLocation(rc.ToonHandle, "LightPosition");
    rc.ToonUniforms.AmbientMaterial = glGetUniformLocation(rc.ToonHandle, "AmbientMaterial");
    rc.ToonUniforms.DiffuseMaterial = glGetUniformLocation(rc.ToonHandle, "DiffuseMaterial");
    rc.ToonUniforms.SpecularMaterial = glGetUniformLocation(rc.ToonHandle, "SpecularMaterial");
    rc.ToonUniforms.Shininess = glGetUniformLocation(rc.ToonHandle, "Shininess");

    glEnable(GL_DEPTH_TEST);

    const float S = 0.46f;
    const float H = S * ViewportHeight / ViewportWidth;
    rc.Projection = mat4::Frustum(-S, S, -H, H, 4, 10);
}
void EyePostRender::Init()
{
	LOG( "EyePostRender::Init()" );

	// grid of lines for drawing to eye buffer
	CalibrationLines = BuildCalibrationLines( 24, false );

	// thin border around the outside
	VignetteSquare = BuildVignette( 128.0f / 1024.0f, 128.0f / 1024.0f );

	UntexturedMvpProgram = BuildProgram(
		"uniform mat4 Mvpm;\n"
		"attribute vec4 Position;\n"
		"uniform mediump vec4 UniformColor;\n"
		"varying  lowp vec4 oColor;\n"
		"void main()\n"
		"{\n"
			"   gl_Position = Mvpm * Position;\n"
			"   oColor = UniformColor;\n"
		"}\n"
	,
		"varying lowp vec4	oColor;\n"
		"void main()\n"
		"{\n"
		"	gl_FragColor = oColor;\n"
		"}\n"
	);

	UntexturedScreenSpaceProgram = BuildProgram( identityVertexShaderSource, untexturedFragmentShaderSource );
}
Beispiel #3
0
ModelGlPrograms OvrSceneView::GetDefaultGLPrograms()
{
	ModelGlPrograms programs;

	if ( !LoadedPrograms )
	{
		ProgVertexColor				= BuildProgram( VertexColorVertexShaderSrc, VertexColorFragmentShaderSrc );
		ProgSingleTexture			= BuildProgram( SingleTextureVertexShaderSrc, SingleTextureFragmentShaderSrc );
		ProgLightMapped				= BuildProgram( LightMappedVertexShaderSrc, LightMappedFragmentShaderSrc );
		ProgReflectionMapped		= BuildProgram( ReflectionMappedVertexShaderSrc, ReflectionMappedFragmentShaderSrc );
		ProgSkinnedVertexColor		= BuildProgram( VertexColorSkinned1VertexShaderSrc, VertexColorFragmentShaderSrc );
		ProgSkinnedSingleTexture	= BuildProgram( SingleTextureSkinned1VertexShaderSrc, SingleTextureFragmentShaderSrc );
		ProgSkinnedLightMapped		= BuildProgram( LightMappedSkinned1VertexShaderSrc, LightMappedFragmentShaderSrc );
		ProgSkinnedReflectionMapped	= BuildProgram( ReflectionMappedSkinned1VertexShaderSrc, ReflectionMappedFragmentShaderSrc );
		LoadedPrograms = true;
	}

	programs.ProgVertexColor				= & ProgVertexColor;
	programs.ProgSingleTexture				= & ProgSingleTexture;
	programs.ProgLightMapped				= & ProgLightMapped;
	programs.ProgReflectionMapped			= & ProgReflectionMapped;
	programs.ProgSkinnedVertexColor			= & ProgSkinnedVertexColor;
	programs.ProgSkinnedSingleTexture		= & ProgSkinnedSingleTexture;
	programs.ProgSkinnedLightMapped			= & ProgSkinnedLightMapped;
	programs.ProgSkinnedReflectionMapped	= & ProgSkinnedReflectionMapped;

	return programs;
}
Beispiel #4
0
Renderer5::Renderer5(int width, int height): RenderingEngine(width, height)
{
    glViewport(0, 0, width, height);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    
    m_rotator = new Rotator(m_surfaceSize);
    
    m_program = BuildProgram(SphereMapVertexShader, SphereMapFragmentShader);
    glUseProgram(m_program);
    
    m_attribPosition = glGetAttribLocation(m_program, "Position");
    m_attribNormal = glGetAttribLocation(m_program, "Normal");
    
    m_uniformProjection = glGetUniformLocation(m_program, "Projection");
    m_uniformModelview = glGetUniformLocation(m_program, "Modelview");
    m_uniformNormalMatrix = glGetUniformLocation(m_program, "NormalMatrix");
    m_uniformEyePosition = glGetUniformLocation(m_program, "EyePosition");
    
    // Create surface
//    m_surface = new Cone(5.0f, 1.8f);
    m_surface = new Sphere(2.0f);
//    m_surface = new Torus(1.8f, 0.5f);
//    m_surface = new TrefoilKnot(3.0f);
//    m_surface = new MobiusStrip(1.5f);
//    m_surface = new KleinBottle(0.3f);
    
    vector<float> vertices;
    m_surface->GenerateVertices(vertices, VertexFlagsNormals);
    
    vector<unsigned short> indices;
    m_surface->GenerateTriangleIndices(indices);
    m_indexCount = indices.size();
    
    // Generate vertex buffer
    glGenBuffers(1, &m_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), &vertices[0], GL_STATIC_DRAW);
    
    // Generate index buffer
    glGenBuffers(1, &m_indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * indices.size(), &indices[0], GL_STATIC_DRAW);
    
    // Set frustum
    GLfloat h = 4 * height / width;
    mat4 projection = mat4::Frustum(-2.0f, 2.0f, -h / 2.0f, h / 2.0f, 4.0f, 10.0f);
    glUniformMatrix4fv(m_uniformProjection, 1, GL_FALSE, projection.Pointer());
    
    // Generate texture
    glGenTextures(1, &m_texture);
    glBindTexture(GL_TEXTURE_2D, m_texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    
    SetPngPOTTexture("sphere_map.png");
    
    glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
    glGenerateMipmap(GL_TEXTURE_2D);
}
Beispiel #5
0
    void LoadEffect() {
        RenderContext& rc = GlobalRenderContext;

        glswInit();
        glswSetPath("../demo/", ".glsl");
        glswAddDirectiveToken("GL3", "#version 150");

        const char* vsKey = "PixelLighting.Vertex.GL3";
        const char* fsKey = "PixelLighting.Fragment.GL3";

        rc.EffectHandle = BuildProgram(vsKey, fsKey);
        rc.EffectUniforms.Projection = glGetUniformLocation(rc.EffectHandle, "Projection");
        rc.EffectUniforms.Modelview = glGetUniformLocation(rc.EffectHandle, "Modelview");
        rc.EffectUniforms.NormalMatrix = glGetUniformLocation(rc.EffectHandle, "NormalMatrix");
        rc.Theta = 0;

        glUseProgram(rc.EffectHandle);

        GLuint LightPosition = glGetUniformLocation(rc.EffectHandle, "LightPosition");
        GLuint AmbientMaterial = glGetUniformLocation(rc.EffectHandle, "AmbientMaterial");
        GLuint DiffuseMaterial = glGetUniformLocation(rc.EffectHandle, "DiffuseMaterial");
        GLuint SpecularMaterial = glGetUniformLocation(rc.EffectHandle, "SpecularMaterial");
        GLuint Shininess = glGetUniformLocation(rc.EffectHandle, "Shininess");

        glUniform3f(DiffuseMaterial, 0.75, 0.75, 0.5);
        glUniform3f(AmbientMaterial, 0.04f, 0.04f, 0.04f);
        glUniform3f(SpecularMaterial, 0.5, 0.5, 0.5);
        glUniform1f(Shininess, 50);
        glUniform3f(LightPosition, 0.25, 0.25, 1);
    }
Beispiel #6
0
static
void
hs_dummy_kernel_create(cl_context context, cl_device_id device_id)
{
  cl_int err;

  char   const * strings[]        = { HS_DUMMY_KERNEL_PROGRAM         };
  size_t const   strings_sizeof[] = { sizeof(HS_DUMMY_KERNEL_PROGRAM) };

  cl_program program = clCreateProgramWithSource(context,
                                                 1,
                                                 strings,
                                                 strings_sizeof,
                                                 &err); cl_ok(err);
  cl(BuildProgram(program,
                  1,
                  &device_id,
                  NULL,
                  NULL,
                  NULL));

  hs_dummy_kernel = clCreateKernel(program,"hs_dummy_kernel",&err); cl_ok(err);

  cl(ReleaseProgram(program));
}
void RenderingEngine2::Initialize(int width, int height)
{
    // Create the framebuffer object and attach the color buffer.
#ifdef __APPLE__
    glGenFramebuffers(1, &m_framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER,
                              m_renderbuffer);
#endif

#ifndef ANDROID_NDK
    m_framebuffer = (GLuint)0;
#endif

    glViewport(0, 0, width, height);

    //    m_simpleProgram = BuildProgram(gVertexShader, gFragmentShader);
    m_simpleProgram = BuildProgram(SimpleVertexShader, SimpleFragmentShader);

    glUseProgram(m_simpleProgram);

    // Initialize the projection matrix.
    ApplyOrtho(2, 3);

    // Initialize rotation animation state.
    OnRotate(DeviceOrientationPortrait);
    m_currentAngle = m_desiredAngle;
}
Beispiel #8
0
//==============================
// OvrGazeCursorLocal::
void OvrGazeCursorLocal::Init()
{
	LOG( "OvrGazeCursorLocal::Init" );
	ASSERT_WITH_TAG( Initialized == false, "GazeCursor" );

	if ( Initialized )
	{
		LOG( "OvrGazeCursorLocal::Init - already initialized!" );
		return;
	}

	CreateCursorGeometry();
	TimerGeometry = BuildTesselatedQuad( 1, 1 );

	int w = 0;
	int h = 0;
	char const * const cursorStateNames[ CURSOR_STATE_MAX ] =
	{
		//"res/raw/color_ramp_test.tga",
		//"res/raw/color_ramp_test.tga",

		//"res/raw/gaze_cursor_dot.tga",
		//"res/raw/gaze_cursor_dot_hi.tga"
		
		//"res/raw/gaze_cursor_cross.tga",
		//"res/raw/gaze_cursor_cross_hi.tga"
		
		"res/raw/gaze_cursor_cross.tga",
		"res/raw/gaze_cursor_cross.tga",	// for now, hilight is the same because the graphic needs work
		"res/raw/gaze_cursor_cross.tga",
		"res/raw/gaze_cursor_hand.tga"
	};

	for ( int i = 0; i < CURSOR_STATE_MAX; ++i )
	{
		CursorTextureHandle[i] = LoadTextureFromApplicationPackage( cursorStateNames[i], TextureFlags_t(), w, h );
	}

	TimerTextureHandle = LoadTextureFromApplicationPackage( "res/raw/gaze_cursor_timer.tga", TextureFlags_t(), w, h );

	ColorTableHandle = LoadTextureFromApplicationPackage( "res/raw/color_ramp_timer.tga", TextureFlags_t(), w, h );

	CursorProgram = BuildProgram( GazeCursorVertexSrc, GazeCursorFragmentSrc );
	TimerProgram = BuildProgram( GazeCursorTimerVertexSrc, GazeCursorColorTableFragmentSrc );//GazeCursorFragmentSrc );

	Initialized = true;
}
void ShaderDemo::Initialize()
{
	SetTitle("ShaderDemo");
	BuildProgram();
	glGenVertexArrays(1, &vertexArray);
	glBindVertexArray(vertexArray);
	glPointSize(40.0f);
}
Beispiel #10
0
void Renderer14::PrepareProgram()
{
    m_program = BuildProgram(NormalMapGeneratorVertexShader, NormalMapGeneratorFragmentShader);
    glUseProgram(m_program);

    m_attribNormal = glGetAttribLocation(m_program, "a_normal");
    m_attribTangent = glGetAttribLocation(m_program, "a_tangent");
    m_attribTexCoord = glGetAttribLocation(m_program, "a_texCoord");

    m_uniformProjection = glGetUniformLocation(m_program, "u_projection");
}
Beispiel #11
0
void Renderer6::PrepareBoneProgram()
{
    m_boneProgram = BuildProgram(BoneVertexShader, BoneFragmentShader);
    glUseProgram(m_boneProgram);
    
    m_attribBonePosition = glGetAttribLocation(m_boneProgram, "Position");
    m_attribBoneSourceColor = glGetAttribLocation(m_boneProgram, "SourceColor");
    
    m_uniformBoneProjection = glGetUniformLocation(m_boneProgram, "Projection");
    m_uniformBoneModelview = glGetUniformLocation(m_boneProgram, "Modelview");
}
Beispiel #12
0
Renderer10::Renderer10(int width, int height): RenderingEngine(width, height)
{
    m_program = BuildProgram(BlendingVertexShader, BlendingFragmentShader);
    glUseProgram(m_program);
    
    glViewport(0, 0, width, height);
    
    m_attribPosition = glGetAttribLocation(m_program, "a_position");
    m_attribColor = glGetAttribLocation(m_program, "a_color");
    m_uniformModelview = glGetUniformLocation(m_program, "u_modelview");
}
static WarpProg	BuildWarpProg( const char * vertex, const char * fragment )
{
	WarpProg wp;

	wp.Prog = BuildProgram( vertex, fragment );
	wp.Texm3 = glGetUniformLocation( wp.Prog.program, "Texm3" );
	wp.Texm4 = glGetUniformLocation( wp.Prog.program, "Texm4" );
	wp.TexClamp = glGetUniformLocation( wp.Prog.program, "TexClamp" );
	wp.RotateScale = glGetUniformLocation( wp.Prog.program, "RotateScale" );

	return wp;
}
Beispiel #14
0
void Renderer6::PrepareSkinProgram()
{
    m_skinProgram = BuildProgram(VertexSkinningVertexShader, VertexSkinningFragmentShader);
    glUseProgram(m_skinProgram);
    
    m_attribSkinPosition = glGetAttribLocation(m_skinProgram, "a_position");
    m_attribSkinSourceColor = glGetAttribLocation(m_skinProgram, "a_color");
    m_attribSkinBoneWeights = glGetAttribLocation(m_skinProgram, "a_boneWeights");
    m_attribSkinBoneIndices = glGetAttribLocation(m_skinProgram, "a_boneIndices");
    
    m_uniformSkinProjection = glGetUniformLocation(m_skinProgram, "u_projection");
    m_uniformSkinModelview = glGetUniformLocation(m_skinProgram, "u_modelview");
}
Beispiel #15
0
//OpenGLES2 handlers : init , final , update , render , touch-input
void on_GLES2_Init(int view_w,int view_h)
{
#ifdef IOS
    glGenRenderbuffers(1,&renderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER,renderbuffer);
    glGenFramebuffers(1,&framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER,framebuffer);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER,renderbuffer);
#endif

    simpleProgram=BuildProgram(SimpleVertexShader,SimpleFragmentShader);
    glUseProgram(simpleProgram);
}
Beispiel #16
0
void OCL_Program::Init( std::string sourcePath )
{
	std::ifstream file( sourcePath );
	if( !file.is_open() )
	{
		std::cout << "Could not open file \'"<< sourcePath <<"\'\n";
	}
	else
	{
		std::string source((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
		m_source = source.c_str();
		m_sourceLength = source.length();
		BuildProgram();
	}
}
Beispiel #17
0
void Renderer2::PrepareRoomProgram()
{
    m_roomProgram = BuildProgram(SpotLightVertexShader, SpotLightFragmentShader);
    glUseProgram(m_roomProgram);
    
    m_attribRoomPosition = glGetAttribLocation(m_roomProgram, "Position");
    m_attribRoomSourceColor = glGetAttribLocation(m_roomProgram, "SourceColor");
    m_attribRoomNormal = glGetAttribLocation(m_roomProgram, "Normal");
    
    m_uniformRoomProjection = glGetUniformLocation(m_roomProgram, "Projection");
    m_uniformRoomModelview = glGetUniformLocation(m_roomProgram, "Modelview");
    m_uniformRoomNormalMatrix = glGetUniformLocation(m_roomProgram, "NormalMatrix");
    m_uniformRoomLightPosition = glGetUniformLocation(m_roomProgram, "LightPosition");
    m_uniformRoomAmbientLight = glGetUniformLocation(m_roomProgram, "AmbientLight");
}
Beispiel #18
0
//==================================
// VRMenuMgrLocal::Init
//
// Initialize the VRMenu system
void VRMenuMgrLocal::Init()
{
	LOG( "VRMenuMgrLocal::Init" );
	if ( Initialized )
	{
        return;
	}

	// diffuse only
	if ( GUIProgramDiffuseOnly.vertexShader == 0 || GUIProgramDiffuseOnly.fragmentShader == 0 )
	{
		GUIProgramDiffuseOnly = BuildProgram( GUIDiffuseOnlyVertexShaderSrc, GUIDiffuseOnlyFragmentShaderSrc );
	}
	// diffuse + additive
	if ( GUIProgramDiffusePlusAdditive.vertexShader == 0 || GUIProgramDiffusePlusAdditive.fragmentShader == 0 )
	{
		GUIProgramDiffusePlusAdditive = BuildProgram( GUITwoTextureColorModulatedShaderSrc, GUIDiffusePlusAdditiveFragmentShaderSrc );
	}
	// diffuse + diffuse
	if ( GUIProgramDiffuseComposite.vertexShader == 0 || GUIProgramDiffuseComposite.fragmentShader == 0 )
	{
		GUIProgramDiffuseComposite = BuildProgram( GUITwoTextureColorModulatedShaderSrc, GUIDiffuseCompositeFragmentShaderSrc );
	}
	// diffuse color ramped
	if ( GUIProgramDiffuseColorRamp.vertexShader == 0 || GUIProgramDiffuseColorRamp.fragmentShader == 0 )
	{
		GUIProgramDiffuseColorRamp = BuildProgram( GUIDiffuseOnlyVertexShaderSrc, GUIColorRampFragmentSrc );
	}
	// diffuse, color ramp, and a specific target for the color ramp
	if ( GUIProgramDiffuseColorRampTarget.vertexShader == 0 || GUIProgramDiffuseColorRampTarget.fragmentShader == 0 )
	{
		GUIProgramDiffuseColorRampTarget = BuildProgram( GUIDiffuseColorRampTargetVertexShaderSrc, GUIColorRampTargetFragmentSrc );
	}

	Initialized = true;
}
Beispiel #19
0
void Renderer2::PrepareSurfaceProgram()
{
    m_program = BuildProgram(LightVertexShader, LightFragmentShader);
    glUseProgram(m_program);
    
    m_attribPosition = glGetAttribLocation(m_program, "Position");
    m_attribSourceColor = glGetAttribLocation(m_program, "SourceColor");
    m_attribNormal = glGetAttribLocation(m_program, "Normal");
    m_attribLightDirection = glGetAttribLocation(m_program, "LightDirection");
    
    m_uniformProjection = glGetUniformLocation(m_program, "Projection");
    m_uniformModelview = glGetUniformLocation(m_program, "Modelview");
    m_uniformNormalMatrix = glGetUniformLocation(m_program, "NormalMatrix");
    m_uniformAmbientLight = glGetUniformLocation(m_program, "AmbientLight");
    m_uniformSpecularLight = glGetUniformLocation(m_program, "SpecularLight");
    m_uniformShininess = glGetUniformLocation(m_program, "Shininess");
}
Beispiel #20
0
Renderer7::Renderer7(int width, int height): RenderingEngine(width, height)
{
    glViewport(0, 0, width, height);
    
    m_program = BuildProgram(MultitextureVertexShader, MultitextureFragmentShader);
    glUseProgram(m_program);
    
    m_attribPosition = glGetAttribLocation(m_program, "a_position");
    m_attribTexCoord = glGetAttribLocation(m_program, "a_texCoord");
    
    m_uniformProjection = glGetUniformLocation(m_program, "u_projection");
    m_uniformModelview = glGetUniformLocation(m_program, "u_modelview");
    m_uniformBaseSampler = glGetUniformLocation(m_program, "u_baseSampler");
    m_uniformLightSampler = glGetUniformLocation(m_program, "u_lightSampler");
    
    // Generate back texture
    glActiveTexture(GL_TEXTURE0);
    
    glGenTextures(1, &m_backTexture);
    glBindTexture(GL_TEXTURE_2D, m_backTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    SetPngPOTTexture("tile_floor.png");
    
    glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
    glGenerateMipmap(GL_TEXTURE_2D);
    
    glUniform1i(m_uniformBaseSampler, 0);
    
    // Generate light texture
    glActiveTexture(GL_TEXTURE1);
    
    glGenTextures(1, &m_lightTexture);
    glBindTexture(GL_TEXTURE_2D, m_lightTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    SetPngPOTTexture("lightmap.png");
    
    glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
    glGenerateMipmap(GL_TEXTURE_2D);
    
    glUniform1i(m_uniformLightSampler, 1);
}
Beispiel #21
0
void mila::meanshift::parallel::MeanShift::Initialize() {
  const auto platforms = clpp::Platform::get();
  platform_ = platforms.at(platform_id_);

  const auto devices = platform_.getAllDevices();
  device_ = devices.at(device_id_);

  context_ = clpp::Context(device_);
  queue_ = clpp::Queue(context_, device_, CL_QUEUE_PROFILING_ENABLE);

  const auto source_file_name = "mean_shift.cl";
  const auto kernel_name = std::string("MeanShift");
  auto source_file = mila::utils::ReadFile(source_file_name);
  auto program = clpp::Program(context_, source_file);

  BuildProgram(program, device_);
  kernel_ = clpp::Kernel(program, kernel_name.c_str());
}
Beispiel #22
0
void VrScene::LoadScene( const char * path )
{
	LOG( "VrScene::LoadScene %s", path );

#if defined( INTENT_TEST_MODEL )
	const char * scenePath = "Oculus/tuscany.ovrscene";
#else
	const char * scenePath = ( path[0] != '\0' ) ? path : "Oculus/tuscany.ovrscene";
#endif
	if ( !GetFullPath( SearchPaths, scenePath, SceneFile ) )
	{
		LOG( "VrScene::NewIntent SearchPaths failed to find %s", scenePath );
	}

	MaterialParms materialParms;
	materialParms.UseSrgbTextureFormats = ( app->GetVrParms().colorFormat == COLOR_8888_sRGB );
	LOG( "VrScene::LoadScene loading %s", SceneFile.ToCStr() );
	Scene.LoadWorldModel( SceneFile, materialParms );
	ModelLoaded = true; 
	LOG( "VrScene::LoadScene model is loaded" );
	Scene.YawOffset = -M_PI / 2;

#if defined( INTENT_TEST_MODEL )
	// load a test model
	const char * testModelPath = intent;
	if ( testModelPath != NULL && testModelPath[0] != '\0' )
	{
		// Create the render programs we are going to use
		GlProgram ProgSingleTexture = BuildProgram( SingleTextureVertexShaderSrc,
				SingleTextureFragmentShaderSrc );

		ModelGlPrograms programs( &ProgSingleTexture );

		TestObject.SetModelFile( LoadModelFile( testModelPath, programs, materialParms ) );
		Scene.AddModel( &TestObject );
	}
#endif

	// When launched by an intent, we may be viewing a partial
	// scene for debugging, so always clear the screen to grey
	// before drawing, instead of letting partial renders show through.
	forceScreenClear = ( path[0] != '\0' );
}
Beispiel #23
0
//==============================
// BitmapFontLocal::Load
bool BitmapFontLocal::Load( char const * languagePackageName, char const * fontInfoFileName )
{
	OvrApkFile languagePackageFile( ovr_OpenOtherApplicationPackage( languagePackageName ) );
	if ( !FontInfo.Load( languagePackageFile, fontInfoFileName ) )
	{
		return false;
	}

	// strip any path from the image file name path and prepend the path from the .fnt file -- i.e. always
	// require them to be loaded from the same directory.
	String baseName = FontInfo.ImageFileName.GetFilename();
	LOG( "fontInfoFileName = %s", fontInfoFileName );
	LOG( "image baseName = %s", baseName.ToCStr() );
	
	char imagePath[512];
	StripFileName( fontInfoFileName, imagePath, sizeof( imagePath ) );
	LOG( "imagePath = %s", imagePath );
	
	char imageFileName[512];
	StripPath( fontInfoFileName, imageFileName, sizeof( imageFileName ) );
	LOG( "imageFileName = %s", imageFileName );
	
	AppendPath( imagePath, sizeof( imagePath ), baseName.ToCStr() );
	if ( !LoadImage( languagePackageFile, imagePath ) )
	{
		return false;
	}

    // create the shaders for font rendering if not already created
    if ( FontProgram.vertexShader == 0 || FontProgram.fragmentShader == 0 )
    {
        FontProgram = BuildProgram( FontSingleTextureVertexShaderSrc, SDFFontFragmentShaderSrc );//SingleTextureFragmentShaderSrc );
    }

	return true;
}
Beispiel #24
0
//==============================
// OvrDebugLinesLocal::Init
void OvrDebugLinesLocal::Init()
{
	if ( Initialized )
	{
// JDC: multi-activity test		DROID_ASSERT( !Initialized, "DebugLines" );
		return;
	}

	// this is only freed by the OS when the program exits
	if ( LineProgram.vertexShader == 0 || LineProgram.fragmentShader == 0 )
	{
		LineProgram = BuildProgram( DebugLineVertexSrc, DebugLineFragmentSrc );
	}

	const int MAX_VERTS = MAX_DEBUG_LINES * 2;
	Vertices = new LineVertex_t[ MAX_VERTS ];
	
	// the indices will never change once we've set them up, we just won't necessarily
	// use all of the index buffer to render.
	const int MAX_INDICES = MAX_DEBUG_LINES * 2;
	LineIndex_t * indices = new LineIndex_t[ MAX_INDICES ];

	for ( int i = 0; i < MAX_INDICES; ++i )
	{
		indices[i] = i;
	}

	InitVBO( DepthGeo, Vertices, MAX_VERTS, indices, MAX_INDICES );
	InitVBO( NonDepthGeo, Vertices, MAX_VERTS, indices, MAX_INDICES );

	glBindVertexArrayOES_( 0 );

	delete [] indices;	// never needs to change so we don't keep it around

	Initialized = true;
}
void RenderingEngine::Initialize()
{
    const unsigned int* faces[] = { Face0, Face1, Face2, Face3, Face4, Face5 };

    // Load the background texture:
    glGenTextures(1, &m_textures.Metal);
    glBindTexture(GL_TEXTURE_2D, m_textures.Metal);
    {
        PVRTextureHeader* header = (PVRTextureHeader*) Metal;
        GLsizei w = header->Width;
        GLsizei h = header->Height;
        const unsigned int* texels = Metal + header->HeaderSize / 4;
        GLenum format = GL_RGB;
        GLenum type = GL_UNSIGNED_SHORT_5_6_5;
        glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, format, type, texels);
    }
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);

    // Load the cubemap texture:
    PVRTextureHeader* header = (PVRTextureHeader*) faces[0];
    const unsigned int* faceData[] = {
        faces[0] + header->HeaderSize / 4,
        faces[1] + header->HeaderSize / 4,
        faces[2] + header->HeaderSize / 4,
        faces[3] + header->HeaderSize / 4,
        faces[4] + header->HeaderSize / 4,
        faces[5] + header->HeaderSize / 4 };

    m_textures.Cubemap = CreateCubemap((void**) faceData, header->Width, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);

    // Create some geometry:
    m_kleinBottle = CreateDrawable(KleinBottle(0.2), VertexFlagsNormals);
    //m_kleinBottle = CreateDrawable(Sphere(1), VertexFlagsNormals);
    m_quad = CreateDrawable(Quad(6, 9), VertexFlagsTexCoords);
    
    // Extract width and height from the color buffer:
    ivec2 screenSize;
    glGetRenderbufferParameteriv(GL_RENDERBUFFER,
                                 GL_RENDERBUFFER_WIDTH, &screenSize.x);
    glGetRenderbufferParameteriv(GL_RENDERBUFFER,
                                 GL_RENDERBUFFER_HEIGHT, &screenSize.y);
    
    // Create the depth buffer:
    glGenRenderbuffers(1, &m_renderbuffers.Depth);
    glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffers.Depth);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
                             screenSize.x, screenSize.y);
    
    // Create the on-screen FBO:
    glGenFramebuffers(1, &m_framebuffers.Screen);
    glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffers.Screen);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER, m_renderbuffers.Color);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, m_renderbuffers.Depth);
    glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffers.Color);
    
    // Create the GLSL programs:
    BuildProgram(SimpleVertexShader, SimpleFragmentShader, m_simple);
    BuildProgram(CubemapVertexShader, CubemapFragmentShader, m_cubemap);
    
    // Set up various GL state:
    glViewport(0, 0, screenSize.x, screenSize.y);
    glEnable(GL_DEPTH_TEST);

    // Set up the transforms:
    const float NearPlane = 5, FarPlane = 50;
    const float Scale = 0.004;
    const float HalfWidth = Scale * screenSize.x / 2;
    const float HalfHeight = Scale * screenSize.y / 2;
    
    mat4 projection = mat4::Frustum(-HalfWidth, HalfWidth, -HalfHeight, HalfHeight,
                                    NearPlane, FarPlane);

    glUseProgram(m_cubemap.Program);
    glUniformMatrix4fv(m_cubemap.Uniforms.Projection, 1, 0, projection.Pointer());
    
    glUseProgram(m_simple.Program);
    glUniformMatrix4fv(m_simple.Uniforms.Projection, 1, 0, projection.Pointer());
}
 void RenderingEngine::Initialize(const vector<ISurface*>& surfaces)
 {
     vector<ISurface*>::const_iterator surface;
     for (surface = surfaces.begin(); surface != surfaces.end(); ++surface) {
         
         // Create the VBO for the vertices.
         vector<float> vertices;
         (*surface)->GenerateVertices(vertices, VertexFlagsNormals|VertexFlagsTexCoords);
         GLuint vertexBuffer;
         glGenBuffers(1, &vertexBuffer);
         glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
         glBufferData(GL_ARRAY_BUFFER,
                      vertices.size() * sizeof(vertices[0]),
                      &vertices[0],
                      GL_STATIC_DRAW);
         
         // Create a new VBO for the indices if needed.
         int indexCount = (*surface)->GetTriangleIndexCount();
         GLuint indexBuffer;
         if (!m_drawables.empty() && indexCount == m_drawables[0].IndexCount) {
             indexBuffer = m_drawables[0].IndexBuffer;
         } else {
             vector<GLushort> indices(indexCount);
             (*surface)->GenerateTriangleIndices(indices);
             glGenBuffers(1, &indexBuffer);
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
             glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                          indexCount * sizeof(GLushort),
                          &indices[0],
                          GL_STATIC_DRAW);
         }
         int lineIndexCount = (*surface)->GetLineIndexCount();
         GLuint lineIndexBuffer;
         vector<GLushort> lineIndices(lineIndexCount);
         (*surface)->GenerateLineIndices(lineIndices);
         glGenBuffers(1, &lineIndexBuffer);
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, lineIndexBuffer);
         glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                      lineIndexCount * sizeof(GLushort),
                      &lineIndices[0],
                      GL_STATIC_DRAW);
         
         Drawable drawable = { vertexBuffer, indexBuffer , indexCount};
         m_drawables.push_back(drawable);
     }
     
     // Extract width and height.
     int width, height;
     glGetRenderbufferParameteriv(GL_RENDERBUFFER,
                                  GL_RENDERBUFFER_WIDTH, &width);
     glGetRenderbufferParameteriv(GL_RENDERBUFFER,
                                  GL_RENDERBUFFER_HEIGHT, &height);
     
     // Create a depth buffer that has the same size as the color buffer.
     glGenRenderbuffers(1, &m_depthRenderbuffer);
     glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderbuffer);
     glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
     
     // Create the framebuffer object.
     GLuint framebuffer;
     glGenFramebuffers(1, &framebuffer);
     glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                               GL_RENDERBUFFER, m_colorRenderbuffer);
     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                               GL_RENDERBUFFER, m_depthRenderbuffer);
     glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer);
     
     // Create the GLSL program.
     GLuint program = BuildProgram(SimpleVertexShader, SimpleFragmentShader);
     glUseProgram(program);
     
     // Extract the handles to attributes and uniforms.
     m_attributes.Position = glGetAttribLocation(program, "Position");
     m_attributes.Normal = glGetAttribLocation(program, "Normal");
     m_attributes.Diffuse = glGetAttribLocation(program, "DiffuseMaterial");
     m_attributes.TextureCoord = glGetAttribLocation(program, "TextureCoord");
     m_uniforms.Projection = glGetUniformLocation(program, "Projection");
     m_uniforms.Modelview = glGetUniformLocation(program, "Modelview");
     m_uniforms.NormalMatrix = glGetUniformLocation(program, "NormalMatrix");
     m_uniforms.LightPosition = glGetUniformLocation(program, "LightPosition");
     m_uniforms.AmbientMaterial = glGetUniformLocation(program, "AmbientMaterial");
     m_uniforms.SpecularMaterial = glGetUniformLocation(program, "SpecularMaterial");
     m_uniforms.Shininess = glGetUniformLocation(program, "Shininess"); 
     
     // Set up some default material parameters.
     glUniform3f(m_uniforms.AmbientMaterial, 0.04f, 0.04f, 0.04f);
     glUniform3f(m_uniforms.SpecularMaterial, 0.5, 0.5, 0.5);
     glUniform1f(m_uniforms.Shininess, 50);
     // Set the active sampler to stage 0.  Not really necessary since the uniform
     // defaults to zero anyway, but good practice.
     glActiveTexture(GL_TEXTURE0);
     glUniform1i(m_uniforms.Sampler, 0);
     // Load the texture.
     glGenTextures(1,&m_gridTexture);
     glBindTexture(GL_TEXTURE_2D, m_gridTexture);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     m_resourceManager = CreateResourceManager();
     m_resourceManager->LoadPngImage("Grid16.png");
     void* pixels = m_resourceManager->GetImageData();
     ivec2 size = m_resourceManager->GetImageSize();
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, 
                  size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
     m_resourceManager->UnloadImage();
     // Initialize various state.
     glEnableVertexAttribArray(m_attributes.Position);
     glEnableVertexAttribArray(m_attributes.Normal);
     glEnableVertexAttribArray(m_attributes.TextureCoord);
     glEnable(GL_DEPTH_TEST);
     
     // Set up transforms.
     m_translation = mat4::Translate(0, 0, -7);
 }
Beispiel #27
0
void MediaSurface::Update()
{
	if ( !AndroidSurfaceTexture )
	{
		LOG( "!AndroidSurfaceTexture" );
		return;
	}
	if ( TexId <= 0 )
	{
		//LOG( "TexId <= 0" );
		return;
	}
	AndroidSurfaceTexture->Update();
	if ( AndroidSurfaceTexture->nanoTimeStamp == LastSurfaceTexNanoTimeStamp )
	{
		return;
	}
	LastSurfaceTexNanoTimeStamp = AndroidSurfaceTexture->nanoTimeStamp;

	// don't mess up Unity state
	GLStateSave	stateSave;

	// If we haven't allocated our GL objects yet, do it now.
	// This isn't done at Init, because GL may not be current then.
	if ( UnitSquare.vertexArrayObject == 0 )
	{
		LOG( "Allocating GL objects" );

		UnitSquare = BuildTesselatedQuad( 1, 1 );

		CopyMovieProgram = BuildProgram(
			"uniform highp mat4 Mvpm;\n"
			"attribute vec4 Position;\n"
			"attribute vec2 TexCoord;\n"
			"varying  highp vec2 oTexCoord;\n"
			"void main()\n"
			"{\n"
			"   gl_Position = Position;\n"
			"   oTexCoord = TexCoord;\n"
			"}\n"
		,
			"#extension GL_OES_EGL_image_external : require\n"
			"uniform samplerExternalOES Texture0;\n"
			"varying highp vec2 oTexCoord;\n"
			"void main()\n"
			"{\n"
			"	gl_FragColor = texture2D( Texture0, oTexCoord );\n"
			"}\n"
		);
	}

	// If the SurfaceTexture has changed dimensions, we need to
	// reallocate the texture and FBO.
	glActiveTexture( GL_TEXTURE0 );
	glBindTexture( GL_TEXTURE_EXTERNAL_OES, AndroidSurfaceTexture->textureId );
	// FIXME: no way to get texture dimensions even in ES 3.0???
	int	width = 960;
	int height = 540;
	if ( width != TexIdWidth || height != TexIdHeight )
	{
		LOG( "New surface size: %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 );

	const GLenum fboAttachments[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 );
}
void RenderingEngine::Initialize(const vector<ISurface*>& surfaces)
{
    vector<ISurface*>::const_iterator surface;
    for (surface = surfaces.begin(); surface != surfaces.end(); ++surface) {
        
        // Create the VBO for the vertices.
        vector<float> vertices;
        (*surface)->GenerateVertices(vertices, VertexFlagsNormals);
        GLuint vertexBuffer;
        glGenBuffers(1, &vertexBuffer);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        glBufferData(GL_ARRAY_BUFFER,
                     vertices.size() * sizeof(vertices[0]),
                     &vertices[0],
                     GL_STATIC_DRAW);
        
        // Create a new VBO for the indices if needed.
        int indexCount = (*surface)->GetTriangleIndexCount();
        GLuint indexBuffer;
        if (!m_drawables.empty() && indexCount == m_drawables[0].IndexCount) {
            indexBuffer = m_drawables[0].IndexBuffer;
        } else {
            vector<GLushort> indices(indexCount);
            (*surface)->GenerateTriangleIndices(indices);
            glGenBuffers(1, &indexBuffer);
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
            glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                         indexCount * sizeof(GLushort),
                         &indices[0],
                         GL_STATIC_DRAW);
        }
        
        Drawable drawable = { vertexBuffer, indexBuffer, indexCount};
        m_drawables.push_back(drawable);
    }
    
    // Create the GLSL program.
    GLuint program = BuildProgram(SimpleVertexShader, SimpleFragmentShader);
    glUseProgram(program);
    
    // Extract the handles to attributes and uniforms.
    m_attributes.Position = glGetAttribLocation(program, "Position");
    m_attributes.Normal = glGetAttribLocation(program, "Normal");
    m_attributes.Diffuse = glGetAttribLocation(program, "DiffuseMaterial");
    m_uniforms.Ambient = glGetUniformLocation(program, "AmbientMaterial");
    m_uniforms.Specular = glGetUniformLocation(program, "SpecularMaterial");
    m_uniforms.Shininess = glGetUniformLocation(program, "Shininess"); 
    m_uniforms.Projection = glGetUniformLocation(program, "Projection");
    m_uniforms.Modelview = glGetUniformLocation(program, "Modelview");
    m_uniforms.NormalMatrix = glGetUniformLocation(program, "NormalMatrix");
    m_uniforms.LightPosition = glGetUniformLocation(program, "LightPosition");
    
    // Set up some default material parameters.
    glUniform3f(m_uniforms.Ambient, 0.1, 0.1, 0.1);
    glUniform3f(m_uniforms.Specular, 0.5, 0.5, 0.5);
    glUniform1f(m_uniforms.Shininess, 50);

    // Initialize various state.
    glEnableVertexAttribArray(m_attributes.Position);
    glEnableVertexAttribArray(m_attributes.Normal);
    glEnable(GL_DEPTH_TEST);
    
    // Set up transforms.
    m_translation = mat4::Translate(0, 0, -7);
}
// Called by TimeWarp before adding the KHR sync object.
void	ImageServer::EnterWarpSwap( int eyeTexture )
{
	ImageServerRequest	request = Request.GetState();
	if ( request.Sequence <= SequenceCaptured )
	{
		return;
	}
	SequenceCaptured = request.Sequence;

	// create GL objects if necessary
	if ( !ResampleProg.program )
	{
		ResampleProg = BuildProgram(
			"uniform highp mat4 Mvpm;\n"
			"attribute vec4 Position;\n"
			"attribute vec2 TexCoord;\n"
			"varying  highp vec2 oTexCoord;\n"
			"void main()\n"
			"{\n"
			"   gl_Position = Position;\n"
			"   oTexCoord = vec2( TexCoord.x, 1.0 - TexCoord.y );\n"	// need to flip Y
			"}\n"
		,
			"uniform sampler2D Texture0;\n"
			"varying highp vec2 oTexCoord;\n"
			"void main()\n"
			"{\n"
			"	gl_FragColor = texture2D( Texture0, oTexCoord );\n"
			"}\n"
		);
	}

	if ( !UnitSquare.vertexArrayObject )
	{
		UnitSquare = BuildTesselatedQuad( 1, 1 );
	}

	// If resolution has changed, delete and reallocate the buffers
	// These might still be in use, do we trust the driver or try to
	// deal with it ourselves?
	if ( request.Resolution != CurrentResolution )
	{
		CurrentResolution = request.Resolution;
		FreeBuffers();
	}

	// Allocate any resources we need
	if ( !ResampleRenderBuffer )
	{
		LOG( "Alloc %i res renderbuffer", CurrentResolution );
		glGenRenderbuffers( 1, &ResampleRenderBuffer );
		glBindRenderbuffer( GL_RENDERBUFFER, ResampleRenderBuffer );
		glRenderbufferStorage( GL_RENDERBUFFER, GL_RGB565, CurrentResolution, CurrentResolution );
	}

	if ( !FrameBufferObject )
	{
		LOG( "Alloc FrameBufferObject" );
		glGenFramebuffers( 1, &FrameBufferObject );
		glBindFramebuffer( GL_FRAMEBUFFER, FrameBufferObject );
		glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				GL_RENDERBUFFER, ResampleRenderBuffer );
		const GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
		if (status != GL_FRAMEBUFFER_COMPLETE )
		{
			LOG( "FBO is not complete: 0x%x", status );
		}
	}

	if ( !PixelBufferObject )
	{
		LOG( "Alloc PixelBufferObject" );
		glGenBuffers( 1, &PixelBufferObject );
		glBindBuffer( GL_PIXEL_PACK_BUFFER, PixelBufferObject );
		glBufferData( GL_PIXEL_PACK_BUFFER, CurrentResolution*CurrentResolution*2, NULL,
                GL_DYNAMIC_READ );
		glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
	}

	// Render the FBO
	glBindFramebuffer( GL_FRAMEBUFFER, FrameBufferObject );
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_SCISSOR_TEST );
	GL_InvalidateFramebuffer( INV_FBO, true, false );
	glViewport( 0, 0, CurrentResolution, CurrentResolution );
	glActiveTexture( GL_TEXTURE0 );
	glBindTexture( GL_TEXTURE_2D, eyeTexture );
	glUseProgram( ResampleProg.program );
	UnitSquare.Draw();
	glUseProgram( 0 );

	// unmap the previous PBO mapping
	if ( PboMappedAddress )
	{
		glBindBuffer( GL_PIXEL_PACK_BUFFER, PixelBufferObject );
		glUnmapBuffer_( GL_PIXEL_PACK_BUFFER );
		glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
		PboMappedAddress = NULL;
	}

	// Issue an async read into our PBO
#if 1

	glBindBuffer( GL_PIXEL_PACK_BUFFER, PixelBufferObject );
	glReadPixels( 0, 0, CurrentResolution, CurrentResolution, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0 );
	// back to normal memory read operations
	glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );

#else
	GL_CheckErrors( "before read" );

	static short	pixels[256*256];
	glReadPixels( 0, 0, CurrentResolution, CurrentResolution, GL_RGB,
			GL_UNSIGNED_SHORT_5_6_5, (GLvoid *)pixels );
	ImageServerResponse	response;
	response.Data = (void *)pixels;
	response.Resolution = CurrentResolution;
	response.Sequence = request.Sequence;
	Response.SetState( response );
#endif
	glBindFramebuffer( GL_FRAMEBUFFER, 0 );

	GL_CheckErrors( "after read" );

	CountdownToSend = 2;
}
	{
	}

	void OpenGLESRenderManager::initialise(OpenGLESImageLoader* _loader)
	{
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		mVertexFormat = VertexColourType::ColourABGR; // WDY ??? ColourABGR

		mUpdate = false;
		mImageLoader = _loader;

		//mPboIsSupported = glewIsExtensionSupported("GL_EXT_pixel_buffer_object") != 0;

		mProgram = BuildProgram(vShader, fShader);

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;
	}

	void OpenGLESRenderManager::shutdown()
	{
		MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
		MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());

		destroyAllResources();

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
		mIsInitialise = false;
	}