Beispiel #1
0
void GLTexture::activateSide(int side) {
	if (side == -1) {
		if (m_fbType == EColorBuffer) {
			Log(EError, "GLTexture::activateTexture(-1): Not allowed for cube map color-only buffers");
		} else if (m_fbType == EColorAndDepthBuffer) {
			glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_id, 0);
			glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, m_depthId, 0);
		} else if (m_fbType == EDepthBuffer) {
			glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, m_id, 0);
		} else {
			Log(EError, "Unsupported framebuffer type!");
		}
	} else {
		if (m_fbType == EColorBuffer) {
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + side, m_id, 0);
		} else if (m_fbType == EColorAndDepthBuffer) {
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + side, m_id, 0);
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + side, m_depthId, 0);
		} else if (m_fbType == EDepthBuffer) {
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + side, m_id, 0);
		} else {
			Log(EError, "Unsupported framebuffer type!");
		}
	}
}
Beispiel #2
0
/**
 *  AttachColors.
 */
void SoXipFbo::attachColors()
{
    // Attach colors
    if (mFboOut.colorStorage == GL_TEXTURE_2D)
    {
        for (unsigned int i = 0; i < mFboOut.numColorAttachments; i++)
            glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, mFboOut.colorHandles[i], 0);
        for (unsigned int i = mFboOut.numColorAttachments; i < (unsigned int)mMaxBuffers; i++)
            glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, 0, 0);
        //SoDebugError::postInfo("SoXipFbo", "Attaching 2D color targets %d %d", mFboOut.colorHandles[0], mFboOut.colorHandles[1]);
    }
    else if (mFboOut.colorStorage == GL_TEXTURE_3D)
    {
        for (unsigned int i = 0; i < mFboOut.numColorAttachments; i++)
            glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, mFboOut.colorHandles[i], 0);
        for (unsigned int i = mFboOut.numColorAttachments; i < (unsigned int)mMaxBuffers; i++)
            glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, 0, 0);
        //SoDebugError::postInfo("SoXipFbo", "Attaching 3D color targets %d %d", mFboOut.colorHandles[0], mFboOut.colorHandles[1]);
    }
    else if (mFboOut.colorStorage == GL_RENDERBUFFER_EXT)
    {
        for (unsigned int i = 0; i < mFboOut.numColorAttachments; i++)
            glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_RENDERBUFFER_EXT, mFboOut.colorHandles[i]);
        for (unsigned int i = mFboOut.numColorAttachments; i < (unsigned int)mMaxBuffers; i++)
            glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_RENDERBUFFER_EXT, 0);
    }
}
/* void glFramebufferTextureEXT ( GLenum target, GLenum attachment, GLuint texture, GLint level ) */
static void
android_glFramebufferTextureEXT__IIII
  (JNIEnv *_env, jobject _this, jint target, jint attachment, jint texture, jint level) {
    glFramebufferTextureEXT(
        (GLenum)target,
        (GLenum)attachment,
        (GLuint)texture,
        (GLint)level
    );
}
 inline void VL_glFramebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
 {
   // even if this extension is signed ad ARB it does not appear in the GL 3.0 specs
   if (glFramebufferTextureARB)
     glFramebufferTextureARB(target,attachment,texture,level);
   else
   if (glFramebufferTextureEXT)
     glFramebufferTextureEXT(target,attachment,texture,level);
   else
     VL_UNSUPPORTED_FUNC();
 }
Beispiel #5
0
FrameBuffer::FrameBuffer(int test) :
	m_width(512), m_height(512), m_depth(-1), m_automaticMipmapsEnabled(0)
{
	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorBuffers);
	m_colorIDs = new GLuint[m_maxColorBuffers]; m_colorType = new GLenum[m_maxColorBuffers];
	m_depthID = m_stencilID = m_prevFrameBuf = m_includedBuffers = 0;
	for (int i=0; i<m_maxColorBuffers; i++)
	{
		m_colorIDs[i] = 0;
		m_colorType[i] = GL_TEXTURE_2D_ARRAY_EXT;
	}
	m_depthType = m_stencilType = GL_TEXTURE_2D_ARRAY_EXT;
	sprintf(m_FBOName, "Test CubeMap Framebuffer");
	
	m_numColorAttachments = 1;
	m_includedBuffers = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
	glGenFramebuffersEXT(1, &m_ID);
	
	glGenTextures(1, m_colorIDs);
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, m_colorIDs[0]);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0, GL_LUMINANCE, m_width, m_height, 6, 0, GL_RGBA, GL_FLOAT, NULL);
	
	glGenTextures(1, &m_depthID);
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, m_depthID);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);	
	glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0, GL_DEPTH_COMPONENT, m_width, m_height, 6, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
	
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, 0);
	
	bindBuffer();
	glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_colorIDs[0], 0);
	glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, m_depthID, 0);
	unbindBuffer();
	
}
Beispiel #6
0
void FOpenGLES31::ProcessExtensions( const FString& ExtensionsString )
{
	// Version setup first, need to check string for 3 or higher, then can use integer queries
	if (SupportsAdvancedFeatures())
	{
		glGetIntegerv(GL_MAJOR_VERSION, &MajorVersion);
		glGetIntegerv(GL_MINOR_VERSION, &MinorVersion);

		bES2Fallback = false;
		UE_LOG(LogRHI, Log, TEXT("bES2Fallback = false"));
	}
	else
	{
		MajorVersion = 2;
		MinorVersion = 0;
		bES2Fallback = true;
		UE_LOG(LogRHI, Log, TEXT("bES2Fallback = true"));
	}

	bSupportsSeparateAlphaBlend = ExtensionsString.Contains(TEXT("GL_EXT_draw_buffers_indexed"));

	static auto CVarAllowHighQualityLightMaps = IConsoleManager::Get().FindConsoleVariable(TEXT("r.HighQualityLightMaps"));

	if (!bES2Fallback)
	{
		// only supported if we are at a minimum bar
		bSupportsTessellation = ExtensionsString.Contains(TEXT("GL_EXT_tessellation_shader"));
		bSupportsTextureView = ExtensionsString.Contains(TEXT("GL_EXT_texture_view"));
		CVarAllowHighQualityLightMaps->Set(1);
	}
	else
	{
		CVarAllowHighQualityLightMaps->Set(0);
	}

	ProcessQueryGLInt();
	FOpenGLBase::ProcessExtensions(ExtensionsString);

	bSupportsMapBuffer = ExtensionsString.Contains(TEXT("GL_OES_mapbuffer"));
	bSupportsDepthTexture = ExtensionsString.Contains(TEXT("GL_OES_depth_texture"));
	bSupportsOcclusionQueries = ExtensionsString.Contains(TEXT("GL_ARB_occlusion_query2")) || ExtensionsString.Contains(TEXT("GL_EXT_occlusion_query_boolean"));
	bSupportsRGBA8 = ExtensionsString.Contains(TEXT("GL_OES_rgb8_rgba8"));
	bSupportsBGRA8888 = ExtensionsString.Contains(TEXT("GL_APPLE_texture_format_BGRA8888")) || ExtensionsString.Contains(TEXT("GL_IMG_texture_format_BGRA8888")) || ExtensionsString.Contains(TEXT("GL_EXT_texture_format_BGRA8888"));
	bSupportsVertexHalfFloat = ExtensionsString.Contains(TEXT("GL_OES_vertex_half_float"));
	bSupportsTextureFloat = ExtensionsString.Contains(TEXT("GL_OES_texture_float"));
	bSupportsTextureHalfFloat = ExtensionsString.Contains(TEXT("GL_OES_texture_half_float"));
	bSupportsSGRB = ExtensionsString.Contains(TEXT("GL_EXT_sRGB"));
	bSupportsColorBufferHalfFloat = ExtensionsString.Contains(TEXT("GL_EXT_color_buffer_half_float"));
	bSupportsNvImageFormats = ExtensionsString.Contains(TEXT("GL_NV_image_formats"));
	bSupportsShaderFramebufferFetch = ExtensionsString.Contains(TEXT("GL_EXT_shader_framebuffer_fetch")) || ExtensionsString.Contains(TEXT("GL_NV_shader_framebuffer_fetch")) || ExtensionsString.Contains(TEXT("GL_ARM_shader_framebuffer_fetch"));
	bSupportsShaderDepthStencilFetch = ExtensionsString.Contains(TEXT("GL_ARM_shader_framebuffer_fetch_depth_stencil"));
	bSupportsMultisampledRenderToTexture = ExtensionsString.Contains(TEXT("GL_EXT_multisampled_render_to_texture"));
	// @todo es3: SRGB support does not work with our texture format setup (ES2 docs indicate that internalFormat and format must match, but they don't at all with sRGB enabled)
	//             One possible solution us to use GLFormat.InternalFormat[bSRGB] instead of GLFormat.Format
	bSupportsSGRB = false;//ExtensionsString.Contains(TEXT("GL_EXT_sRGB"));
	bSupportsDXT = ExtensionsString.Contains(TEXT("GL_NV_texture_compression_s3tc")) || ExtensionsString.Contains(TEXT("GL_EXT_texture_compression_s3tc"));
	bSupportsPVRTC = ExtensionsString.Contains(TEXT("GL_IMG_texture_compression_pvrtc")) ;
	bSupportsATITC = ExtensionsString.Contains(TEXT("GL_ATI_texture_compression_atitc")) || ExtensionsString.Contains(TEXT("GL_AMD_compressed_ATC_texture"));
	bSupportsETC1 = ExtensionsString.Contains(TEXT("GL_OES_compressed_ETC1_RGB8_texture"));
	bSupportsVertexArrayObjects = ExtensionsString.Contains(TEXT("GL_OES_vertex_array_object")) ;
	bSupportsDiscardFrameBuffer = ExtensionsString.Contains(TEXT("GL_EXT_discard_framebuffer"));
	bSupportsNVFrameBufferBlit = ExtensionsString.Contains(TEXT("GL_NV_framebuffer_blit"));
	bSupportsPackedDepthStencil = ExtensionsString.Contains(TEXT("GL_OES_packed_depth_stencil"));
	bSupportsShaderTextureLod = ExtensionsString.Contains(TEXT("GL_EXT_shader_texture_lod"));
	bSupportsTextureStorageEXT = ExtensionsString.Contains(TEXT("GL_EXT_texture_storage"));
	bSupportsCopyTextureLevels = bSupportsTextureStorageEXT && ExtensionsString.Contains(TEXT("GL_APPLE_copy_texture_levels"));
	bSupportsDisjointTimeQueries = ExtensionsString.Contains(TEXT("GL_EXT_disjoint_timer_query"));// || ExtensionsString.Contains(TEXT("GL_NV_timer_query"));
	bTimerQueryCanBeDisjoint = !ExtensionsString.Contains(TEXT("GL_NV_timer_query"));
	bSupportsNvTimerQuery = ExtensionsString.Contains(TEXT("GL_NV_timer_query"));

	// Report shader precision
	int Range[2];
	glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_LOW_FLOAT, Range, &ShaderLowPrecision);
	glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, Range, &ShaderMediumPrecision);
	glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, Range, &ShaderHighPrecision);
	UE_LOG(LogRHI, Log, TEXT("Fragment shader lowp precision: %d"), ShaderLowPrecision);
	UE_LOG(LogRHI, Log, TEXT("Fragment shader mediump precision: %d"), ShaderMediumPrecision);
	UE_LOG(LogRHI, Log, TEXT("Fragment shader highp precision: %d"), ShaderHighPrecision);
	
	// Test whether the GPU can support volume-texture rendering.
	// There is no API to query this - you just have to test whether a 3D texture is framebuffer-complete.
	if (!bES2Fallback)
	{
		GLuint FrameBuffer;
		glGenFramebuffers(1, &FrameBuffer);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FrameBuffer);
		GLuint VolumeTexture;
		glGenTextures(1, &VolumeTexture);
		glBindTexture(GL_TEXTURE_3D, VolumeTexture);
		glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 256, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
		glFramebufferTextureEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, VolumeTexture, 0);

		bSupportsVolumeTextureRendering = (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);

		glDeleteTextures(1, &VolumeTexture);
		glDeleteFramebuffers(1, &FrameBuffer);
	}

	bSupportsCopyImage = ExtensionsString.Contains(TEXT("GL_EXT_copy_image"));
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTGeometryShader4_nglFramebufferTextureEXT(JNIEnv *env, jclass clazz, jint target, jint attachment, jint texture, jint level, jlong function_pointer) {
    glFramebufferTextureEXTPROC glFramebufferTextureEXT = (glFramebufferTextureEXTPROC)((intptr_t)function_pointer);
    glFramebufferTextureEXT(target, attachment, texture, level);
}
Beispiel #8
0
void Mercury::initRendering(void) {

	// OpenGL 4.3 is the minimum for compute shaders
	if (!requireMinAPIVersion(NvGLAPIVersionES3_1()))
		return;

	// Set Clear Color
	glClearColor(0.25f, 0.25f, 0.25f, 1.0f);

	CHECK_GL_ERROR();
	NvAssetLoaderAddSearchPath("es3aep-kepler/Mercury");

	const char* shaderPrefix =
		(getGLContext()->getConfiguration().apiVer.api == NvGLAPI::GL)
		? "#version 430\n" : "#version 310 es\n";

	CHECK_GL_ERROR();
	{
		int32_t len;
		// Initialize Particles Render Program
		NvScopedShaderPrefix switched(shaderPrefix);

		std::string renderPartVS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderPartVS.glsl");
		std::string renderPartGS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderPartGS.glsl");
		mParticlesRenderProg = new NvGLSLProgram;


		NvGLSLProgram::ShaderSourceItem sourcesP[2];
		sourcesP[0].type = GL_VERTEX_SHADER;
		sourcesP[0].src = renderPartVS.c_str();
		sourcesP[1].type = GL_FRAGMENT_SHADER;
		sourcesP[1].src = NvAssetLoaderRead("shaders/renderPartFS.glsl", len);
		mParticlesRenderProg->setSourceFromStrings(sourcesP, 2);
		NvAssetLoaderFree((char*)sourcesP[1].src);

		// Initialize Surface Render Program
		std::string renderSurfVS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderSurfVS.glsl");
		std::string renderSurfGS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderSurfGS.glsl");
		std::string renderSurfFS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderSurfFS.glsl");
		mSurfaceRenderProg = new NvGLSLProgram;

		NvGLSLProgram::ShaderSourceItem sourcesS[3];
		sourcesS[0].type = GL_VERTEX_SHADER;
		sourcesS[0].src = renderSurfVS.c_str();
		sourcesS[1].type = GL_GEOMETRY_SHADER_EXT;
		sourcesS[1].src = renderSurfGS.c_str();
		sourcesS[2].type = GL_FRAGMENT_SHADER;
		sourcesS[2].src = renderSurfFS.c_str();
		mSurfaceRenderProg->setSourceFromStrings(sourcesS, 3);

		std::string quadVS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderQuadVS.glsl");
		std::string quadFS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/renderQuadFS.glsl");
		mQuadProg = new NvGLSLProgram;

		NvGLSLProgram::ShaderSourceItem sourcesQ[2];
		sourcesQ[0].type = GL_VERTEX_SHADER;
		sourcesQ[0].src = quadVS.c_str();
		sourcesQ[1].type = GL_FRAGMENT_SHADER;
		sourcesQ[1].src = quadFS.c_str();
		mQuadProg->setSourceFromStrings(sourcesQ, 2);
		
		std::string blurVS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/blurVS.glsl");
		std::string blurFS = loadShaderSourceWithUniformTag("shaders/uniforms.h", "shaders/blurFS.glsl");
		mBlurProg = new NvGLSLProgram;

		NvGLSLProgram::ShaderSourceItem sourcesB[2];
		sourcesB[0].type = GL_VERTEX_SHADER;
		sourcesB[0].src = blurVS.c_str();
		sourcesB[1].type = GL_FRAGMENT_SHADER;
		sourcesB[1].src = blurFS.c_str();
		mBlurProg->setSourceFromStrings(sourcesB, 2);

	}
	CHECK_GL_ERROR();

	// Set up cubemap for skybox 
	mSkyBoxTexID = NvImageGL::UploadTextureFromDDSFile("textures/sky_cube.dds");
	glBindTexture(GL_TEXTURE_CUBE_MAP, mSkyBoxTexID);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
	CHECK_GL_ERROR();

	// Initialize skybox for screen quad
	mScreenQuadPos = new ShaderBuffer<nv::vec4f>(4);
	vec4f* pos = mScreenQuadPos->map();
	pos[0] = vec4f(-1.0f, -1.0f, -1.0f, 1.0f);
    pos[1] = vec4f( 1.0f, -1.0f, -1.0f, 1.0f);
    pos[2] = vec4f(-1.0f, 1.0f, -1.0f, 1.0f);
    pos[3] = vec4f( 1.0f, 1.0f, -1.0f, 1.0f);
	mScreenQuadPos->unmap();	


    //create ubo and initialize it with the structure data
    glGenBuffers( 1, &mUBO);
    glBindBuffer( GL_UNIFORM_BUFFER, mUBO);
    glBufferData( GL_UNIFORM_BUFFER, sizeof(ShaderParams), &mShaderParams, GL_STREAM_DRAW);
    CHECK_GL_ERROR();

    //create simple single-vertex VBO
    float vtx_data[] = { 0.0f, 0.0f, 0.0f, 1.0f};
    glGenBuffers( 1, &mVBO);
    glBindBuffer( GL_ARRAY_BUFFER, mVBO);
    glBufferData( GL_ARRAY_BUFFER, sizeof(vtx_data), vtx_data, GL_STATIC_DRAW);
    CHECK_GL_ERROR();

    // For now, scale back the particle count on mobile.
	//int32_t particleCount = isMobilePlatform() ? (mNumParticles >> 2) : mNumParticles;
	int32_t particleCount = mNumParticles;

    mParticles = new ParticleSystem(particleCount, shaderPrefix);
    CHECK_GL_ERROR();

    int cx, cy, cz;
    glGetIntegeri_v( GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, &cx );
    glGetIntegeri_v( GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, &cy );
    glGetIntegeri_v( GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, &cz );
    LOGI("Max compute work group count = %d, %d, %d\n", cx, cy, cz );

    int sx, sy, sz;
    glGetIntegeri_v( GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &sx );
    glGetIntegeri_v( GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, &sy );
    glGetIntegeri_v( GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, &sz );
    LOGI("Max compute work group size  = %d, %d, %d\n", sx, sy, sz );

    CHECK_GL_ERROR();

	//Set clockwise winding
	glFrontFace(GL_CW);

	// Texture
	const int screen_width = getAppContext()->width();
	const int screen_height = getAppContext()->height();
	
	// Frame buffer for final scene
	glGenTextures(gbuffer_size, gbuffer_tex);
	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	for (int i = 0; i < gbuffer_size; i++) {
		glActiveTexture(GL_TEXTURE0 + 3 + i);
		glBindTexture(GL_TEXTURE_2D, gbuffer_tex[i]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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_RGBA16F, screen_width, screen_height, 0, GL_RGBA, GL_FLOAT, NULL);
		glBindTexture(GL_TEXTURE_2D, 0);
		
		glFramebufferTextureEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, gbuffer_tex[i], 0);
	}

	// Depth buffer 
	glGenRenderbuffers(1, &rbo_depth);
	glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screen_width, screen_height);
	glBindRenderbuffer(GL_RENDERBUFFER, 0);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth);


	GLuint attachments[gbuffer_size];
	for (int i = 0; i < gbuffer_size; i++) {
		attachments[i] = GL_COLOR_ATTACHMENT0 + i;
	}

	glDrawBuffers(gbuffer_size, attachments);

	GLenum status;
	if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) {
		LOGE("glCheckFramebufferStatus: error %p", status);
		exit(0);
	}
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	
}
Beispiel #9
0
FrameBuffer::FrameBuffer(GLenum type, int w, int h, int d, 
						 GLuint colorBufType, int numColorBufs, int hasZbuf, 
						 bool enableAutomaticMipmaps, const char *name) :
	m_width(w), m_height(h), m_depth(d), 
	m_automaticMipmapsEnabled(enableAutomaticMipmaps?1:0)
{
	if (type == GL_TEXTURE_1D || type == GL_TEXTURE_3D)
		printf("Warning!  FrameBuffer constructor called with untested texture type!\n");
	
	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorBuffers);
	m_colorIDs = new GLuint[m_maxColorBuffers];
	m_colorType = new GLenum[m_maxColorBuffers];
	m_depthID = m_stencilID = m_prevFrameBuf = m_includedBuffers = 0;
	for (int i=0; i<m_maxColorBuffers; i++)
	{
		m_colorIDs[i] = 0;
		m_colorType[i] = type;
	}
	m_depthType = m_stencilType = type;
	
	if (!name) sprintf(m_FBOName, "Framebuffer %d", m_ID);
	else strncpy(m_FBOName, name, 79);
	
	glGenFramebuffersEXT(1, &m_ID);
	

	m_numColorAttachments = numColorBufs;
	if (numColorBufs > 0)
	{
		m_includedBuffers |= GL_COLOR_BUFFER_BIT;
		glGenTextures(numColorBufs, m_colorIDs);
		
		for (int i=0; i<numColorBufs; i++)
		{
			glBindTexture(type, m_colorIDs[i]);
			glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(type, GL_GENERATE_MIPMAP, m_automaticMipmapsEnabled > 0 ? GL_TRUE : GL_FALSE);
			if (type == GL_TEXTURE_CUBE_MAP)
			{
				glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
			}
			else if (type == GL_TEXTURE_2D_ARRAY_EXT || type == GL_TEXTURE_3D)
				glTexImage3D(type, 0, colorBufType, m_width, m_height, m_depth, 0, GL_RGBA, GL_FLOAT, NULL);
			else if (type == GL_TEXTURE_2D || type == GL_TEXTURE_1D_ARRAY_EXT)
				glTexImage2D(type, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
			else if (type == GL_TEXTURE_1D)
				glTexImage1D(type, 0, colorBufType, m_width, 0, GL_RGBA, GL_FLOAT, NULL);
			if (enableAutomaticMipmaps) glGenerateMipmapEXT(type);
			bindBuffer();
			
			glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, m_colorIDs[i], 0);
			unbindBuffer();
		}
	}
	if (hasZbuf > 0)
	{
		m_includedBuffers |= GL_DEPTH_BUFFER_BIT;
		glGenTextures(1, &m_depthID);
		
		glBindTexture(type, m_depthID);
		glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(type, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
		if (type == GL_TEXTURE_CUBE_MAP)
		{
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		}
		else if (type == GL_TEXTURE_2D_ARRAY_EXT || type == GL_TEXTURE_3D)
			glTexImage3D(type, 0, GL_DEPTH_COMPONENT, m_width, m_height, m_depth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		else if (type == GL_TEXTURE_2D || type == GL_TEXTURE_1D_ARRAY_EXT)
			glTexImage2D(type, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		else if (type == GL_TEXTURE_1D)
			glTexImage1D(type, 0, GL_DEPTH_COMPONENT, m_width, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		bindBuffer();
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_depthID, 0);
		unbindBuffer();
	}
	
	glBindTexture(type, 0);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTGeometryShader4_glFramebufferTextureEXT(JNIEnv *__env, jclass clazz, jint target, jint attachment, jint texture, jint level) {
    glFramebufferTextureEXTPROC glFramebufferTextureEXT = (glFramebufferTextureEXTPROC)tlsGetFunction(1718);
    UNUSED_PARAM(clazz)
    glFramebufferTextureEXT(target, attachment, texture, level);
}