void FramebufferObject::detachTexture(GLenum attachment) {
    size_t index = decodeAttachment(attachment);
    if (attachments_[index] != 0) {
        switch (attachments_[index]->getType()) {
            case GL_TEXTURE_1D:
                glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_1D, 0, 0);
                break;
            case GL_TEXTURE_2D_ARRAY:
                glFramebufferTextureLayerEXT(GL_FRAMEBUFFER_EXT, attachment, 0, 0, 0);
                break;
            case GL_TEXTURE_3D:
                glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_3D, 0, 0, 0);
                break;
            default: // GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE
                glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, 0, 0);
                break;
        }
        attachments_[index] = 0;
        LGL_ERROR;

        if (index < CGT_FRAMEBUFFEROBJECT_MAX_SUPPORTED_COLOR_ATTACHMENTS)
            --numColorAttachments_;
    }
    else {
        LWARNING("Trying to detach unknown texture!");
    }
}
void FramebufferObject::attachTexture(Texture* texture, GLenum attachment, int mipLevel, int zSlice)
{
    switch(texture->getType()) {
        case GL_TEXTURE_1D:
            glFramebufferTexture1DEXT( GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_1D, texture->getId(), mipLevel );
            break;
        case GL_TEXTURE_3D:
            glFramebufferTexture3DEXT( GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_3D, texture->getId(), mipLevel, zSlice );
            break;
        case GL_TEXTURE_2D_ARRAY:
            glFramebufferTextureLayerEXT( GL_FRAMEBUFFER_EXT, attachment, texture->getId(), mipLevel, zSlice );
            break;
        default: //GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE
            glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, texture->getType(), texture->getId(), mipLevel );
            break;
    }
    LGL_ERROR;

    size_t index = decodeAttachment(attachment);
    attachments_[index] = texture;
    if (index < CGT_FRAMEBUFFEROBJECT_MAX_SUPPORTED_COLOR_ATTACHMENTS)
        ++numColorAttachments_;

#ifdef CAMPVIS_DEBUG
    this->isComplete();
#endif
}
Esempio n. 3
0
/*
=================
R_AttachFBOTexture3D
=================
*/
void R_AttachFBOTexture3D( int texId, int index, int zOffset )
{
	if ( index < 0 || index >= glConfig2.maxColorAttachments )
	{
		ri.Printf( PRINT_WARNING, "R_AttachFBOTexture3D: invalid attachment index %i\n", index );
		return;
	}

	glFramebufferTexture3DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + index, GL_TEXTURE_3D_EXT, texId, 0, zOffset );
}
Esempio n. 4
0
/**
 *  Deallocation of a buffer.
 */
void SoXipFbo::attachDepth()
{
    // Attach new depth buffer
    if (mFboOut.depthStorage == GL_TEXTURE_2D)
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, mFboOut.depthHandle, 0);
	else if (mFboOut.depthStorage == GL_TEXTURE_3D)
		glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_3D, mFboOut.depthHandle, 0, 0);
    else if (mFboOut.depthStorage == GL_RENDERBUFFER_EXT)
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mFboOut.depthHandle);
}
Esempio n. 5
0
/**
 * Attaches a GL texture to the framebuffer
 */
void FBO::AttachTexture(const GLuint texId, const GLenum texTarget, const GLenum attachment, const int mipLevel, const int zSlice )
{
	if (texTarget == GL_TEXTURE_1D) {
		glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_1D, texId, mipLevel);
	} else if (texTarget == GL_TEXTURE_3D) {
		glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_3D, texId, mipLevel, zSlice);
	} else {
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, texTarget, texId, mipLevel);
	}
}
Esempio n. 6
0
static int
create_3d_fbo(void)
{
	GLuint tex, fb;
	GLenum status;
	int depth;
	pot_depth = piglit_is_extension_supported("GL_ARB_texture_non_power_of_two") ?
		NUM_DEPTHS: POT_DEPTHS;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_3D, tex);

	/* allocate empty 3D texture */
	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
		     BUF_WIDTH, BUF_HEIGHT, pot_depth,
		     0,
		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	assert(glGetError() == 0);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	/* draw something into each slice of the 3D texture */
	for (depth = 0; depth < NUM_DEPTHS; depth++) {
		glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,
					  GL_COLOR_ATTACHMENT0_EXT,
					  GL_TEXTURE_3D,
					  tex,
					  0,
					  depth);

		assert(glGetError() == 0);

		status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			fprintf(stderr, "FBO incomplete\n");
			goto done;
		}

		glViewport(0, 0, BUF_WIDTH, BUF_HEIGHT);
		piglit_ortho_projection(BUF_WIDTH, BUF_HEIGHT, GL_FALSE);

		/* solid color quad */
		glColor4fv(depth_color[depth]);
		piglit_draw_rect(-2, -2, BUF_WIDTH + 2, BUF_HEIGHT + 2);
	}


done:
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	return tex;
}
Esempio n. 7
0
 void FramebufferObject::attachTexture(Texture* texture, GLenum attachment, int mipLevel, int zSlice)
 {
   switch (texture->getType()) {
   case GL_TEXTURE_1D:
     glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_1D, texture->getId(), mipLevel);
     break;
   case GL_TEXTURE_3D:
     glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_3D, texture->getId(), mipLevel, zSlice);
     break;
   case GL_TEXTURE_2D_ARRAY_EXT:
     glFramebufferTextureLayerEXT(GL_FRAMEBUFFER_EXT, attachment, texture->getId(), mipLevel, zSlice);
     break;
   default: //GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE
     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, texture->getType(), texture->getId(), mipLevel);
     break;
   }
   attachedTextures_[attachment] = texture;
 }
Esempio n. 8
0
// attach the texture to a FBO
void
CFrameBufferObject::attachTexture( GLenum texTarget, GLuint texId, 
                                   GLenum attachment, int mipLevel, int zSlice )
{
    bindRenderPath();
    switch (texTarget) {
        case GL_TEXTURE_1D:
            glFramebufferTexture1DEXT( GL_FRAMEBUFFER_EXT, attachment,
                                       GL_TEXTURE_1D, texId, mipLevel );
            break;
        case GL_TEXTURE_3D:
            glFramebufferTexture3DEXT( GL_FRAMEBUFFER_EXT, attachment,
                                       GL_TEXTURE_3D, texId, mipLevel, zSlice );
           break;
        default:
            // Default is GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB, or cube faces
            glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment,
                                       texTarget, texId, mipLevel );
            break;
    }
    unbindRenderPath();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTFramebufferObject_glFramebufferTexture3DEXT(JNIEnv *__env, jclass clazz, jint target, jint attachment, jint textarget, jint texture, jint level, jint zoffset) {
    glFramebufferTexture3DEXTPROC glFramebufferTexture3DEXT = (glFramebufferTexture3DEXTPROC)tlsGetFunction(1711);
    UNUSED_PARAM(clazz)
    glFramebufferTexture3DEXT(target, attachment, textarget, texture, level, zoffset);
}
				void frame_buffer_texture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) {
					glFramebufferTexture3DEXT(target, attachment, textarget, texture, level, zoffset);
					CHECK_GL_ERROR();
				}
Esempio n. 11
0
void LightVolumeGL::process() {
    bool lightColorChanged = false;

    if (lightSource_.isChanged()) {
        lightColorChanged = lightSourceChanged();
    }

    bool reattach = false;

    if (internalVolumesInvalid_ || lightColorChanged || inport_.isChanged()) {
        reattach = volumeChanged(lightColorChanged);
    }

    VolumeGL* outVolumeGL = volume_->getEditableRepresentation<VolumeGL>();
    TextureUnit volUnit;
    const VolumeGL* inVolumeGL = inport_.getData()->getRepresentation<VolumeGL>();
    inVolumeGL->bindTexture(volUnit.getEnum());
    TextureUnit transFuncUnit;
    const Layer* tfLayer = transferFunction_.get().getData();
    const LayerGL* transferFunctionGL = tfLayer->getRepresentation<LayerGL>();
    transferFunctionGL->bindTexture(transFuncUnit.getEnum());
    TextureUnit lightVolUnit[2];
    propParams_[0].vol->bindTexture(lightVolUnit[0].getEnum());
    propParams_[1].vol->bindTexture(lightVolUnit[1].getEnum());
    propagationShader_.activate();
    propagationShader_.setUniform("volume_", volUnit.getUnitNumber());
    utilgl::setShaderUniforms(propagationShader_, *inport_.getData(), "volumeParameters_");
    propagationShader_.setUniform("transferFunc_", transFuncUnit.getUnitNumber());
    propagationShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    propagationShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);

    BufferObjectArray* rectArray = utilgl::enableImagePlaneRect();

    //Perform propagation passes
    for (int i=0; i<2; ++i) {
        propParams_[i].fbo->activate();
        glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

        if (reattach)
            propParams_[i].fbo->attachColorTexture(propParams_[i].vol->getTexture().get(), 0);

        propagationShader_.setUniform("lightVolume_", lightVolUnit[i].getUnitNumber());
        propagationShader_.setUniform("permutationMatrix_", propParams_[i].axisPermutation);

        if (lightSource_.getData()->getLightSourceType() == LightSourceType::LIGHT_POINT) {
            propagationShader_.setUniform("lightPos_", lightPos_);
            propagationShader_.setUniform("permutedLightMatrix_", propParams_[i].axisPermutationLight);
        }
        else {
            propagationShader_.setUniform("permutedLightDirection_", propParams_[i].permutedLightDirection);
        }

        for (unsigned int z=0; z<volumeDimOut_.z; ++z) {
            glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_3D, propParams_[i].vol->getTexture()->getID(), 0, z);
            propagationShader_.setUniform("sliceNum_", static_cast<GLint>(z));
            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
            glFlush();
        }

        propParams_[i].fbo->deactivate();
    }

    utilgl::disableImagePlaneRect(rectArray);

    propagationShader_.deactivate();
    mergeShader_.activate();
    mergeShader_.setUniform("lightVolume_", lightVolUnit[0].getUnitNumber());
    mergeShader_.setUniform("lightVolumeSec_", lightVolUnit[1].getUnitNumber());
    mergeShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    mergeShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);
    mergeShader_.setUniform("permMatInv_", propParams_[0].axisPermutationINV);
    mergeShader_.setUniform("permMatInvSec_", propParams_[1].axisPermutationINV);
    mergeShader_.setUniform("blendingFactor_", blendingFactor_);
    //Perform merge pass
    mergeFBO_->activate();
    glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

    if (reattach)
        mergeFBO_->attachColorTexture(outVolumeGL->getTexture().get(), 0);

    utilgl::multiDrawImagePlaneRect(static_cast<int>(volumeDimOut_.z));
    mergeShader_.deactivate();
    mergeFBO_->deactivate();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTFramebufferObject_nglFramebufferTexture3DEXT(JNIEnv *env, jclass clazz, jint target, jint attachment, jint textarget, jint texture, jint level, jint zoffset, jlong function_pointer) {
	glFramebufferTexture3DEXTPROC glFramebufferTexture3DEXT = (glFramebufferTexture3DEXTPROC)((intptr_t)function_pointer);
	glFramebufferTexture3DEXT(target, attachment, textarget, texture, level, zoffset);
}