Example #1
0
void BufferInterface::bind(ContextType type)throw(BufferException)
{
	if(type == OPEN_GL_CONTEXT_TYPE)
	{
		if( (mBufferInfo->usageContexts & OPEN_GL_CONTEXT_TYPE_FLAG) == 0)
		{throw(BufferException("BufferInterface::bind: GL binding requested, but this Buffer has no GL context;"));}
		PARA_COMP_MANAGER->acquireSharedBuffersForGraphics();
		GUARD(bindGL());
		return;
	}
	if(type == OPEN_CL_CONTEXT_TYPE)
	{
		if(  (mBufferInfo->usageContexts & OPEN_CL_CONTEXT_TYPE_FLAG) == 0)
				{throw(BufferException("BufferInterface::bind: CL binding requested, but this Buffer has no CL context;"));}
		LOG<<WARNING_LOG_LEVEL<<"binding a buffer to an OpenCL context makes no big sense to me at the moment ;). Try just assuring "<<
				"the Buffer is acquired for the CL context and it is set as a kernel argument properly;\n";
		PARA_COMP_MANAGER->acquireSharedBuffersForCompute();
		//GUARD(bindCL()); <-- bullshat :P
		return;
	}

	if(type == HOST_CONTEXT_TYPE)
	{
		assert("binding a buffer to the host context makes no sense to me at the moment ;)"&&0);
		return;
	}

	assert("should never end dowglBlitFramebuffern here" && 0);

}
Example #2
0
void BufferInterface::transferData(bool fromSystemToDevice)throw(BufferException)
{
	assert( "CPU buffer must exist for transfer between host and device" && mCPU_Handle);

	if(
		( hasBufferInContext(OPEN_GL_CONTEXT_TYPE) && PARA_COMP_MANAGER->graphicsAreInControl() )
		||
		! (hasBufferInContext(OPEN_CL_CONTEXT_TYPE))
	)
	{
		//commented out the guard in case of driver bugs fu**ing up when doing too mush time-shared CL-GL-stuff
		//TODO uncomment when stable work is assured
		//if(isCLGLShared())
		{
			PARA_COMP_MANAGER->acquireSharedBuffersForGraphics();
		}

		GUARD(bindGL());
		if(fromSystemToDevice)
		{
			GUARD(writeGL(mCPU_Handle));
		}
		else
		{
			GUARD(readGL(mCPU_Handle));
		}
		return;
	}

	if(
		( hasBufferInContext(OPEN_CL_CONTEXT_TYPE) && PARA_COMP_MANAGER->computeIsInControl() )
		||
		! (hasBufferInContext(OPEN_GL_CONTEXT_TYPE))
	)
	{
		//commented out the guard in case of driver bugs fu**ing up when doing too mush time-shared CL-GL-stuff
		//TODO uncomment when stable work is assured
		//if(isCLGLShared())
		{
			PARA_COMP_MANAGER->acquireSharedBuffersForCompute();
		}

		if(fromSystemToDevice)
		{
			GUARD(writeCL(mCPU_Handle));
		}
		else
		{
			GUARD(readCL(mCPU_Handle));
		}
		return;
	}

	throw(BufferException("BufferInterface::readBack(): need at least one GL or GL usage context in Buffer"));
}
Example #3
0
        void ITexture::bind(int i) {
            //glActiveTexture(GL_TEXTURE0 + i);
			//Context::getCurrent()->bind(this);
			bindGL();
        }
void GLES2RendererVertexBuffer::bind(PxU32 streamID, PxU32 firstVertex)
{
	prepareForRender();
	GLES2RendererMaterial *mat = g_hackCurrentMat;
	PxU8 *buffer = ((PxU8*)0) + firstVertex*m_stride;
	if(m_vbo)
	{
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo);
		for(PxU32 i=0; i<NUM_SEMANTICS; i++)
		{
			Semantic semantic = (Semantic)i;
			const SemanticDesc &sm = m_semanticDescs[semantic];
			if(sm.format < NUM_FORMATS)
			{
				switch(semantic)
				{
					case SEMANTIC_POSITION:
						RENDERER_ASSERT(sm.format >= FORMAT_FLOAT1 && sm.format <= FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for POSITION semantic.");
						if(sm.format >= FORMAT_FLOAT1 && sm.format <= FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].positionAttr, sm, buffer);
						}
						break;
					case SEMANTIC_COLOR:
						RENDERER_ASSERT(sm.format == FORMAT_COLOR_BGRA || sm.format == FORMAT_COLOR_RGBA || sm.format == FORMAT_COLOR_NATIVE || sm.format == FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for COLOR semantic.");
						if(sm.format == FORMAT_COLOR_BGRA || sm.format == FORMAT_COLOR_RGBA || sm.format == FORMAT_COLOR_NATIVE || sm.format == FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].colorAttr, sm, buffer);
						}
						break;
					case SEMANTIC_NORMAL:
						RENDERER_ASSERT(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for NORMAL semantic.");
						if(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].normalAttr, sm, buffer);
						}
						break;
					case SEMANTIC_TANGENT:
						RENDERER_ASSERT(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for TANGENT semantic.");
						if(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].tangentAttr, sm, buffer);
						}
						break;
					case SEMANTIC_TEXCOORD0:
					case SEMANTIC_TEXCOORD1:
					case SEMANTIC_TEXCOORD2:
					case SEMANTIC_TEXCOORD3:
					{
						const PxU32 channel = semantic - SEMANTIC_TEXCOORD0;
						glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + channel));
						glClientActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + channel));

                        bindGL(mat->m_program[mat->m_currentPass].texcoordAttr[channel], sm, buffer);

						break;
					}
					case SEMANTIC_BONEINDEX:
					{
						glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEINDEX_CHANNEL));
						glClientActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEINDEX_CHANNEL));
                        bindGL(mat->m_program[mat->m_currentPass].boneIndexAttr, sm, buffer);
                        break;
					}
					case SEMANTIC_BONEWEIGHT:
					{
						glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEWEIGHT_CHANNEL));
						glClientActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEWEIGHT_CHANNEL));
                        bindGL(mat->m_program[mat->m_currentPass].boneWeightAttr, sm, buffer);
						break;
					}
					default:
						/*
                        __android_log_print(ANDROID_LOG_DEBUG, "GLES2RendererVertexBuffer", "semantic: %d", i);
						RENDERER_ASSERT(0, "Unable to bind Vertex Buffer Semantic.");
						*/
						break;
				}
			}
		}
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
	}
}
Example #5
0
bool BufferInterface::allocMem()throw(BufferException)
{
	if( mBufferInfo->isPingPongBuffer ||
		//don't trust the bufferInfo
		dynamic_cast<PingPongBuffer*>(this)
	)
	{
		throw(BufferException("Buffer::allocMem(): this routine may never be calles for ping pong buffers, as they are only managers"
				"for other buffers but having some own associated memory!"));
	}


	//assert that this routine is called only once per object:
	if(mCPU_Handle || mGraphicsBufferHandle || mComputeBufferHandle())
	{
		throw(BufferException("Buffer::allocMem(): some buffers already allocated"));
	}

	if( mBufferInfo->usageContexts & HOST_CONTEXT_TYPE_FLAG )
	{
		mCPU_Handle = malloc(mBufferInfo->bufferSizeInByte);
	}

	if(mBufferInfo->usageContexts & OPEN_GL_CONTEXT_TYPE_FLAG)
	{
		//ok, there is a need for an openGL buffer; maybe it will be shared with openCL,
		//but that doesn't matter for the GL buffer creation :)
		if( isDefaultBuffer() && (mBufferInfo->glBufferType == NO_GL_BUFFER_TYPE)	)
		{
			throw(BufferException("no gl buffer type specified for a non-texture or non-renderbuffer Buffer, although a gl usage context was requested"));
		}
		//no special treatment for texture types, as we use native GL-#defines

		GUARD(generateGL());
		//"direct" call of "bindGL()" here isn't dangerous, as the buffer is not shared (yet),
		//as it has just been created;
		GUARD(bindGL());
		GUARD(allocGL());
	}

	//ok, the GL stuff is allocated if it was requested; Now let's check for the "compute" world;
	if(mBufferInfo->usageContexts & OPEN_CL_CONTEXT_TYPE_FLAG)
	{
		if(mBufferInfo->usageContexts & OPEN_GL_CONTEXT_TYPE_FLAG)
		{
			//both CL and GL are requested, that means interop:
			//neither bind nor alloc necessary, just generating:
			GUARD(generateCLGL());

		}
		else
		{
			//a CL-only buffer is requested:
			//in OpenCL, alloc is done at the same time of generation; so, no allocCL() routine must be called
			GUARD(generateCL());
			//GUARD(allocCL()); <--bullshaat ;)
		}
	}


#if (FLEWNIT_TRACK_MEMORY || FLEWNIT_DO_PROFILING)
	//only track memory for non-pingpongs, as pingpongs only manage, but don't "own" own data store;
	if(! mBufferInfo->isPingPongBuffer)
	{
		registerBufferAllocation(mBufferInfo->usageContexts,mBufferInfo->bufferSizeInByte);
	}
#endif

	return true;

}