Exemplo n.º 1
0
void TopazSample::initFramebuffers(int32_t width, int32_t height)
{
	if (textures.sceneColor && GLEW_ARB_bindless_texture)
	{
		glMakeTextureHandleNonResidentARB(texturesAddress64.sceneColor);
		glMakeTextureHandleNonResidentARB(texturesAddress64.sceneDepth);
	}

	if (textures.sceneColor)
	{
		glDeleteTextures(1, &textures.sceneColor);
	}
	glGenTextures(1, &textures.sceneColor);

	glBindTexture(GL_TEXTURE_RECTANGLE, textures.sceneColor);
	glTexStorage2D(GL_TEXTURE_RECTANGLE, 1, GL_RGBA16F, width, height);
	glBindTexture(GL_TEXTURE_RECTANGLE, 0);

	if (textures.sceneDepth)
	{
		glDeleteTextures(1, &textures.sceneDepth);
	}
	glGenTextures(1, &textures.sceneDepth);

	glBindTexture(GL_TEXTURE_RECTANGLE, textures.sceneDepth);
	glTexStorage2D(GL_TEXTURE_RECTANGLE, 1, GL_DEPTH_COMPONENT24, width, height);
	glBindTexture(GL_TEXTURE_RECTANGLE, 0);

	if (fbos.scene)
	{
		glDeleteFramebuffers(1, &fbos.scene);
	}
	glGenFramebuffers(1, &fbos.scene);

	glBindFramebuffer(GL_FRAMEBUFFER, fbos.scene);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, textures.sceneColor, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, textures.sceneDepth, 0);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	if (GLEW_ARB_bindless_texture)
	{
		texturesAddress64.sceneColor = glGetTextureHandleARB(textures.sceneColor);
		texturesAddress64.sceneDepth = glGetTextureHandleARB(textures.sceneDepth);
		glMakeTextureHandleResidentARB(texturesAddress64.sceneColor);
		glMakeTextureHandleResidentARB(texturesAddress64.sceneDepth);
	}

	cmdlist.state.fboIncarnation++;
}
Exemplo n.º 2
0
// --------------------------------------------------------------------------------------------------------------------
bool TexturedQuadsGLBindless::Init(const std::vector<TexturedQuadsProblem::Vertex>& _vertices,
                                   const std::vector<TexturedQuadsProblem::Index>& _indices,
                                   const std::vector<TextureDetails*>& _textures,
                                   size_t _objectCount)
{
    if (!TexturedQuadsSolution::Init(_vertices, _indices, _textures, _objectCount)) {
        return false;
    }

    // Prerequisites
    if (glGetTextureHandleARB == nullptr) {
        console::warn("Unable to initialize solution '%s', requires support for bindless textures (not present).", GetName().c_str());
        return false;
    }

    // Program
    const char* kUniformNames[] = { "ViewProjection", "DrawID", "gTex", nullptr };

    mProgram = CreateProgramT("textures_gl_bindless_vs.glsl",
                              "textures_gl_bindless_fs.glsl", 
                              kUniformNames, &mUniformLocation);

    if (mProgram == 0) {
        console::warn("Unable to initialize solution '%s', shader compilation/linking failed.", GetName().c_str());
        return false;
    }

    // Textures
    for (auto it = _textures.begin(); it != _textures.end(); ++it) {
        GLuint tex = NewTex2DFromDetails(*(*it));
        if (!tex) {
            console::warn("Unable to initialize solution '%s', texture creation failed.", GetName().c_str());
            return false;
        }

        // Needs to be freed later.
        mTextures.push_back(tex);

        GLuint64 texHandle = glGetTextureHandleARB(tex);
        if (texHandle == 0) {
            console::warn("Unable to initialize solution '%s', couldn't get texture handle.", GetName().c_str());
        }
        mTexHandles.push_back(texHandle);
    }

    // Buffers
    glGenVertexArrays(1, &mVertexArray);
    glBindVertexArray(mVertexArray);

    mVertexBuffer = NewBufferFromVector(GL_ARRAY_BUFFER, _vertices, GL_STATIC_DRAW);
    mIndexBuffer = NewBufferFromVector(GL_ELEMENT_ARRAY_BUFFER, _indices, GL_STATIC_DRAW);

    glGenBuffers(1, &mTransformBuffer);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, mTransformBuffer);

    glGenVertexArrays(1, &mVAO);
    glBindVertexArray(mVAO);

    return glGetError() == GL_NO_ERROR;
}
Exemplo n.º 3
0
static enum piglit_result
call_CopyTexSubImage_when_texture_is_referenced(void *data)
{
	GLuint tex;

	tex = piglit_rgbw_texture(GL_RGBA8, 16, 16, GL_FALSE, GL_FALSE,
				  GL_UNSIGNED_BYTE);

	glGetTextureHandleARB(tex);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;

	/* The ARB_bindless_texture spec says:
	 *
	 * "The contents of the images in a texture object may still be
	 *  updated via commands such as TexSubImage*, CopyTexSubImage*, and
	 *  CompressedTexSubImage*, and by rendering to a framebuffer object,
	 *  even if the texture object is referenced by one or more texture
	 *  handles."
	 */
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 16, 16);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;

	return PIGLIT_PASS;
}
Exemplo n.º 4
0
PIGLIT_GL_TEST_CONFIG_END

static enum piglit_result
call_TexSubImage_when_texture_is_referenced(void *data)
{
	int *img = malloc(16 * 16 * 4 * sizeof(unsigned));
	GLuint tex;

	tex = piglit_integer_texture(GL_RGBA32I, 16, 16, 0, 0);

	glGetTextureHandleARB(tex);
	if (!piglit_check_gl_error(GL_NO_ERROR)) {
		free(img);
		return PIGLIT_FAIL;
	}

	/* The ARB_bindless_texture spec says:
	 *
	 * "The contents of the images in a texture object may still be
	 *  updated via commands such as TexSubImage*, CopyTexSubImage*, and
	 *  CompressedTexSubImage*, and by rendering to a framebuffer object,
	 *  even if the texture object is referenced by one or more texture
	 *  handles."
	 */
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 16, 16, GL_RGBA_INTEGER,
			GL_INT, img);
	free(img);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;

	return PIGLIT_PASS;
}
Exemplo n.º 5
0
static enum piglit_result
call_MapBuffer_when_texture_is_referenced(void *data)
{
	static const float red[4] = {1, 0, 0, 0};
	GLuint tex, tbo;

	glGenBuffers(1, &tbo);
	glBindBuffer(GL_TEXTURE_BUFFER, tbo);
	glBufferData(GL_TEXTURE_BUFFER, sizeof(red), red, GL_STATIC_DRAW);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_BUFFER, tex);
	glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, tbo);

	glGetTextureHandleARB(tex);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;

	/* The ARB_bindless_texture spec says:
	 *
	 * "The contents of the buffer object may still be updated via buffer
	 *  update commands such as BufferSubData and MapBuffer*, or via the
	 *  texture update commands, even if the buffer is bound to a texture
	 *  while that buffer texture object is referenced by one or more
	 *  texture handles."
	 */
	glMapBuffer(GL_TEXTURE_BUFFER, GL_READ_ONLY);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;
	glUnmapBuffer(GL_TEXTURE_BUFFER);

	return PIGLIT_PASS;
}
Exemplo n.º 6
0
inline uint64_t get_texture_handle(uint32_t tex_id)
{
	ARC_GL_CLEAR_ERRORS();
	uint64_t result = glGetTextureHandleARB(tex_id);
	ARC_GL_CHECK_FOR_ERRORS();
	return result;
}
EXTERN_C_ENTER

JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_ARBBindlessTexture_glGetTextureHandleARB(JNIEnv *__env, jclass clazz, jint texture) {
    glGetTextureHandleARBPROC glGetTextureHandleARB = (glGetTextureHandleARBPROC)tlsGetFunction(1075);
    UNUSED_PARAM(clazz)
    return (jlong)glGetTextureHandleARB(texture);
}
Exemplo n.º 8
0
GLuint64EXT HdSimpleTextureResource::GetLayoutTextureHandle() 
{
    if (!TF_VERIFY(_isPtex)) {
        return 0;
    }
    
    if (!TF_VERIFY(glGetTextureHandleARB)) {
        return 0;
    }

    GLuint textureId = GetLayoutTextureId();

    return textureId ? glGetTextureHandleARB(textureId) : 0;
}
Exemplo n.º 9
0
GLuint64EXT HdSimpleTextureResource::GetTexelsTextureHandle() 
{ 
    GLuint textureId = GetTexelsTextureId();
    GLuint samplerId = GetTexelsSamplerId();

    if (!TF_VERIFY(glGetTextureHandleARB) ||
        !TF_VERIFY(glGetTextureSamplerHandleARB)) {
        return 0;
    }

    if (_isPtex) {
        return textureId ? glGetTextureHandleARB(textureId) : 0;
    } 

    return textureId ? glGetTextureSamplerHandleARB(textureId, samplerId) : 0;
}
Exemplo n.º 10
0
static enum piglit_result
call_CompressedTexSubImage_when_texture_is_referenced(void *data)
{
	void *compressed;
	GLuint tex;
	GLint size;

	tex = piglit_rgbw_texture(GL_COMPRESSED_RGBA_BPTC_UNORM, 16, 16,
				  GL_FALSE, GL_FALSE, GL_UNSIGNED_NORMALIZED);

	glGetTextureHandleARB(tex);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;

	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);

	compressed = malloc(size);
	glGetCompressedTexImage(GL_TEXTURE_2D, 0, compressed);

	/* The ARB_bindless_texture spec says:
	 *
	 * "The contents of the images in a texture object may still be
	 *  updated via commands such as TexSubImage*, CopyTexSubImage*, and
	 *  CompressedTexSubImage*, and by rendering to a framebuffer object,
	 *  even if the texture object is referenced by one or more texture
	 *  handles."
	 */
	glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 16, 16,
				  GL_COMPRESSED_RGBA_BPTC_UNORM, size,
				  compressed);
	free(compressed);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		return PIGLIT_FAIL;

	return PIGLIT_PASS;
}
Exemplo n.º 11
0
void ImageViewerPanel::initializeGL()
{
	//glewInit();

	glGetIntegerv(GL_MAJOR_VERSION, &ogl_ver_major);
	glGetIntegerv(GL_MINOR_VERSION, &ogl_ver_minor);

	shaderP = make_unique<GLSLProgram>(
		"resources/shaders/img_vs.glsl",
		"resources/shaders/img_fs.glsl");

	if (ogl_ver_major == 4 && ogl_ver_minor >= 5)
	{
		// DSA
		// Create VAO
		glCreateBuffers(1, &vbo);
		glNamedBufferData(vbo, sizeof(frame), frame, GL_STATIC_DRAW);
		
		// IBO
		GLuint indices[] = { 0,1,2,2,3,0 };
		glCreateBuffers(1, &ibo);
		glNamedBufferData(ibo, sizeof(indices), indices, GL_STATIC_DRAW);

		// VAO
		glCreateVertexArrays(1, &vao);
		glEnableVertexArrayAttrib(vao, 0);

		// Setup the formats
		glVertexArrayAttribFormat(vao, 0, 2, GL_FLOAT, GL_FALSE, 0);
		glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(float) * 2);
		glVertexArrayAttribBinding(vao, 0, 0);

		glVertexArrayElementBuffer(vao, ibo);

		// Setup textures
		int texSize = 4;
		glCreateTextures(GL_TEXTURE_2D, 1, &tex);
		glTextureParameteri(tex, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTextureParameteri(tex, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

		glTextureStorage2D(tex, 1, GL_RGB32F, imgsize[0], imgsize[1]);
		if (texLen > 0)
		{
			glTextureSubImage2D(tex, 0, 0, 0, imgsize[0], imgsize[1], GL_RGB, GL_FLOAT, textures);
		}
		texHandle = glGetTextureHandleARB(tex);
		glMakeTextureHandleResidentARB(texHandle);
		
		
	}
	else
	{
		// Non-DSA
		glGenVertexArrays(1, &vao);
		glBindVertexArray(vao);
		// Bind UV values
		glGenBuffers(1, &vbo);
		glBindBuffer(GL_ARRAY_BUFFER, vbo);
		glBufferData(GL_ARRAY_BUFFER, sizeof(frame), frame, GL_STATIC_DRAW);
		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
		glEnableVertexAttribArray(0);

		glBindVertexArray(0);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Texture2DContainer::Texture2DContainer(bool sparse, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei slices)
: mHandle(0)
, mWidth(width)
, mHeight(height)
, mLevels(levels)
, mSlices(slices)
, mXTileSize(0)
, mYTileSize(0)
{
    glGenTextures(1, &mTexId);
    glBindTexture(GL_TEXTURE_2D_ARRAY, mTexId);

    if (sparse) {
        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SPARSE_ARB, GL_TRUE);

        // TODO: This could be done once per internal format. For now, just do it every time.
        GLint indexCount = 0,
            xSize = 0,
            ySize = 0,
            zSize = 0;

        GLint bestIndex = -1,
            bestXSize = 0,
            bestYSize = 0;

        glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_NUM_VIRTUAL_PAGE_SIZES_ARB, 1, &indexCount);
        for (GLint i = 0; i < indexCount; ++i) {
            glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_VIRTUAL_PAGE_SIZE_INDEX_ARB, i);
            glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_VIRTUAL_PAGE_SIZE_X_ARB, 1, &xSize);
            glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_VIRTUAL_PAGE_SIZE_Y_ARB, 1, &ySize);
            glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_VIRTUAL_PAGE_SIZE_Z_ARB, 1, &zSize);

            // For our purposes, the "best" format is the one that winds up with Z=1 and the largest x and y sizes.
            if (zSize == 1) {
                if (xSize >= bestXSize && ySize >= bestYSize) {
                    bestIndex = i;
                    bestXSize = xSize;
                    bestYSize = ySize;
                }
            }
        }

        // This would mean the implementation has no valid sizes for us, or that this format doesn't actually support sparse
        // texture allocation. Need to implement the fallback. TODO: Implement that.
        assert(bestIndex != -1);

        mXTileSize = bestXSize;

        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_VIRTUAL_PAGE_SIZE_INDEX_ARB, bestIndex);
    }

    // We've set all the necessary parameters, now it's time to create the sparse texture.
    glTexStorage3D(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, mSlices);
    for (GLsizei i = 0; i < mSlices; ++i) {
        mFreeList.push(i);
    }

    if (sparse) {
        mHandle = glGetTextureHandleARB(mTexId);
        assert(mHandle != 0);
        glMakeTextureHandleResidentARB(mHandle);
    }
}
// --------------------------------------------------------------------------------------------------------------------
bool TexturedQuadsGLBindlessMultiDraw::Init(const std::vector<TexturedQuadsProblem::Vertex>& _vertices,
                                            const std::vector<TexturedQuadsProblem::Index>& _indices,
                                            const std::vector<TextureDetails*>& _textures,
                                            size_t _objectCount)
{
    if (!TexturedQuadsSolution::Init(_vertices, _indices, _textures, _objectCount)) {
        return false;
    }

    // Prerequisites
    if (glGetTextureHandleARB == nullptr) {
        console::warn("Unable to initialize solution '%s', requires support for bindless textures (not present).", GetName().c_str());
        return false;
    }

    // Programs
    mProgram = CreateProgram("textures_gl_bindless_multidraw_vs.glsl",
                             "textures_gl_bindless_multidraw_fs.glsl");

    if (mProgram == 0) {
        console::warn("Unable to initialize solution '%s', shader compilation/linking failed.", GetName().c_str());
        return false;
    }

    // Textures
    for (auto it = _textures.begin(); it != _textures.end(); ++it) {
        GLuint tex = NewTex2DFromDetails(*(*it));
        if (!tex) {
            console::warn("Unable to initialize solution '%s', texture creation failed.", GetName().c_str());
            return false;
        }

        // Needs to be freed later.
        mTextures.push_back(tex);

        GLuint64 texHandle = glGetTextureHandleARB(tex);
        if (texHandle == 0) {
            console::warn("Unable to initialize solution '%s', couldn't get texture handle.", GetName().c_str());
        }
        mTexHandles.push_back(texHandle);
    }

    // Buffers
    mVertexBuffer = NewBufferFromVector(GL_ARRAY_BUFFER, _vertices, GL_STATIC_DRAW);
    mIndexBuffer = NewBufferFromVector(GL_ELEMENT_ARRAY_BUFFER, _indices, GL_STATIC_DRAW);

    glGenBuffers(1, &mTransformBuffer);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, mTransformBuffer);

    auto srcIt = mTexHandles.cbegin();
    std::vector<GLuint64> texAddressContents(_objectCount);
    for (auto dstIt = texAddressContents.begin(); dstIt != texAddressContents.end(); ++dstIt) {
        if (srcIt == mTexHandles.cend()) {
            srcIt = mTexHandles.cbegin();
        }

        (*dstIt) = *srcIt;
        ++srcIt;
    }

    mTexAddressBuffer = NewBufferFromVector(GL_SHADER_STORAGE_BUFFER, texAddressContents, GL_STATIC_DRAW);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, mTexAddressBuffer);

    mCommands.resize(_objectCount);

    return GLRenderer::GetApiError() == GL_NO_ERROR;
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_ARBBindlessTexture_nglGetTextureHandleARB(JNIEnv *env, jclass clazz, jint texture, jlong function_pointer) {
	glGetTextureHandleARBPROC glGetTextureHandleARB = (glGetTextureHandleARBPROC)((intptr_t)function_pointer);
	GLuint64 __result = glGetTextureHandleARB(texture);
	return __result;
}
Exemplo n.º 15
0
void TopazSample::initScene()
{
	// initializate skybox
	{
		glBindTexture(GL_TEXTURE_CUBE_MAP, textures.skybox);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

		texturesAddress64.skybox = glGetTextureHandleARB(textures.skybox);
		glMakeTextureHandleResidentARB(texturesAddress64.skybox);
	}

	// init fullscreen quad
	{
		const float position[] = 
		{
			-1.0f, -1.0f, 0.0,
			1.0f, -1.0f, 0.0,
			-1.0f, 1.0f, 0.0, 
			1.0f, 1.0f, 0.0
		};

		initBuffer(GL_ARRAY_BUFFER, fullScreenRectangle.vboFullScreen, fullScreenRectangle.vboFullScreen64,
			12 * sizeof(float),
			position); 
	}

	// initializate scene & weightBlended ubo
	{
		initBuffer(GL_UNIFORM_BUFFER, ubos.sceneUbo, ubos.sceneUbo64,
			sizeof(SceneData),
			nullptr,
			true); // mutable buffer

		initBuffer(GL_UNIFORM_BUFFER, ubos.identityUbo, ubos.identityUbo64,
			sizeof(IdentityData),
			identityData.identity._array,
			true); // mutable buffer

		WeightBlendedData weightBlendedData;
		weightBlendedData.background = texturesAddress64.sceneColor;
		weightBlendedData.colorTex0 = oit->getAccumulationTextureId64(0);
		weightBlendedData.colorTex1 = oit->getAccumulationTextureId64(1);

		initBuffer(GL_UNIFORM_BUFFER, ubos.weightBlendedUbo, ubos.weightBlendedUbo64,
			sizeof(WeightBlendedData),
			&weightBlendedData,
			true); // mutable buffer
	}

	brushStyle->brushPattern8to32(QtStyles::Dense1Pattern);

	objectData.objectID = nv::vec4f(0.0);
	objectData.objectColor = nv::vec4f(1.0f, 1.0f, 1.0f, oit->getOpacity());
	objectData.skybox = texturesAddress64.skybox;
	objectData.pattern = brushStyle->getTextureId64();

	for (auto & model : models)
	{
		model->getModel()->compileModel(NvModelPrimType::TRIANGLES);

		/* ibo */
		initBuffer(GL_ELEMENT_ARRAY_BUFFER, model->getBufferID("ibo"), model->getBufferID64("ibo"),
			model->getModel()->getCompiledIndexCount(NvModelPrimType::TRIANGLES) * sizeof(uint32_t),
			model->getModel()->getCompiledIndices(NvModelPrimType::TRIANGLES));

		/* vbo */
		initBuffer(GL_ARRAY_BUFFER, model->getBufferID("vbo"), model->getBufferID64("vbo"),
			model->getModel()->getCompiledVertexCount() * model->getModel()->getCompiledVertexSize() * sizeof(float), 
			model->getModel()->getCompiledVertices());
		
		if (model->cornerPointsExists())
		{
			/* ibo corner */
			initBuffer(GL_ELEMENT_ARRAY_BUFFER, model->getCornerBufferID("ibo"), model->getCornerBufferID64("ibo"),
				model->getCornerIndices().size() * sizeof(uint32_t), 
				model->getCornerIndices().data());

			/* vbo corner */
			initBuffer(GL_ARRAY_BUFFER, model->getCornerBufferID("vbo"), model->getCornerBufferID64("vbo"),
				model->getCorners().size() * sizeof(nv::vec3f),
				model->getCorners().data());

			/* ubo corner */
			ObjectData curObjectData;
			curObjectData.objectID = nv::vec4f(1.0f);
			curObjectData.objectColor = nv::vec4f(1.0f, 0.0f, 0.0f, oit->getOpacity());
			curObjectData.pattern = brushStyle->getTextureId64();

			initBuffer(GL_UNIFORM_BUFFER, model->getCornerBufferID("ubo"), model->getCornerBufferID64("ubo"), 
				sizeof(ObjectData),
				&curObjectData, 
				true); // mutable buffer
		}

		/* ubo */
		initBuffer(GL_UNIFORM_BUFFER, model->getBufferID("ubo"), model->getBufferID64("ubo"),
			sizeof(ObjectData),
			&objectData,
			true); // mutable buffer

		objectData.objectID = nv::vec4f(1.0);
	}
}
Exemplo n.º 16
0
void WeightedBlendedOIT::InitAccumulationRenderTargets(int32_t width, int32_t height)
{
	this->imageWidth = width;
	this->imageHeight = height;

	glGenTextures(1, &this->sceneOpaqueId);

	/* scene non transparent */

	glBindTexture(GL_TEXTURE_RECTANGLE, this->sceneOpaqueId);
	
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA16F, this->imageWidth, this->imageHeight, 0, GL_RGBA, GL_FLOAT, nullptr);

	glGenTextures(2, this->accumulationTextureId);

	/* rgba texture */

	glBindTexture(GL_TEXTURE_RECTANGLE, this->accumulationTextureId[0]);
	
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	
	glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA16F, this->imageWidth, this->imageHeight, 0, GL_RGBA, GL_FLOAT, nullptr);

	/* alpha texture */

	glBindTexture(GL_TEXTURE_RECTANGLE, this->accumulationTextureId[1]);
	
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	
    glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_R8, this->imageWidth, this->imageHeight, 0, GL_RED, GL_FLOAT, nullptr);

	glGenFramebuffers(1, &this->accumulationFramebufferId);
	glBindFramebuffer(GL_FRAMEBUFFER, this->accumulationFramebufferId);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, this->accumulationTextureId[0], 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_RECTANGLE, this->accumulationTextureId[1], 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_RECTANGLE, this->sceneOpaqueId, 0);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	if (GLEW_ARB_bindless_texture)
	{
		this->accumulationTextureId64[0] = glGetTextureHandleARB(this->accumulationTextureId[0]);
		this->accumulationTextureId64[1] = glGetTextureHandleARB(this->accumulationTextureId[1]);
		this->sceneOpaqueId64 = glGetTextureHandleARB(this->sceneOpaqueId);
		glMakeTextureHandleResidentARB(this->accumulationTextureId64[0]);
		glMakeTextureHandleResidentARB(this->accumulationTextureId64[1]);
		glMakeTextureHandleResidentARB(this->sceneOpaqueId64);
	}
	
	CHECK_GL_ERROR();
}