mini3d::D3D9VertexShader::~D3D9VertexShader(void)
{
	UnloadResource();
	pGraphicsService->RemoveResource(this);

	free(pShaderBytes);
	delete[] vertexDeclaration;
}
void mini3d::OGL20RenderTargetTexture::LoadResource(void)
{

	// if it is not unloaded, do so now
	UnloadResource();

	// create a texture object
	glGenTextures(1, &pTexture);
	pOGLWrapper->GLBindTexture(GL_TEXTURE_2D, pTexture);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
	glBindTexture(GL_TEXTURE_2D, 0);

	if (depthTestEnabled == true)
	{
		// create a renderbuffer object to store depth info
		pOGLWrapper->GLGenRenderbuffers(1, &pDepthStencil);
		pOGLWrapper->GLBindRenderbuffer(GL_RENDERBUFFER, pDepthStencil);
		pOGLWrapper->GLRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
		pOGLWrapper->GLBindRenderbuffer(GL_RENDERBUFFER, 0);
	}
	
	
	// create a framebuffer object
	pOGLWrapper->GLGenFramebuffers(1, &pRenderTarget);
	pOGLWrapper->GLBindFramebuffer(GL_FRAMEBUFFER, pRenderTarget);

	// attach the texture to FBO color attachment point
	pOGLWrapper->GLFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pTexture, 0);

	// attach the renderbuffer to depth attachment point
	if (depthTestEnabled == true)
	{
		pOGLWrapper->GLFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pDepthStencil);
	}

	// switch back to window-system-provided framebuffer
	pOGLWrapper->GLBindFramebuffer(GL_FRAMEBUFFER, 0);

	bufferWidth = width;
	bufferHeight = height;
	isDirty = false;
}
void cSoundResourceManagerBase::RemoveResource(unsigned int storage_index)
{
    if(storage_index >= GetResourcesCount())
        return;

    vResource<ALuint> *res = m_Resources[storage_index];

    m_Resources[storage_index] = m_Resources.back();
    // Update storage index
    m_Resources[storage_index]->SetStorageIndex(storage_index);
    m_Resources.pop_back();

    // Remove all traces of resource ever existing
    UnloadResource(res);

    if(res)
        delete res;
}
void mini3d::OGL20VertexShader::LoadResource(void)
{
	// If the buffer exists tear it down.
	if (pShaderBuffer != 0)
	{
		UnloadResource();
	}

	pShaderBuffer = pOGLWrapper->GLCreateShader(GL_VERTEX_SHADER);
	pOGLWrapper->GLShaderSource(pShaderBuffer, 1, (const GLchar**)&pShaderBytes, (const GLint*)&sizeInBytes);
	pOGLWrapper->GLCompileShader(pShaderBuffer);

	printLog(pShaderBuffer);
	isDirty = false;

	// update the vertex Attributes
	CreateOGL20VertexAttributes();

}
Exemple #5
0
bool cSoundSourceManager::ReloadResource(unsigned int storage_index)
{
    if(storage_index >= GetResourcesCount())
        return false;

    vSoundSourceResource *rs = (vSoundSourceResource*)m_Resources[storage_index];
    if(!rs)
        return false;

    ALuint buffer = 0;
    // Reloading starts by releasing associated buffer
    UnloadResource(rs);
    // Recreate buffer and update resource state
    buffer = OpenAL::Get().CreateBuffer();
    if(alIsBuffer(buffer))
    {
        rs->SetState(EResourceState::Ok);
        rs->SetResource(buffer);
        return true;
    }

    return false;
}
void mini3d::D3D9VertexShader::LoadResource(void)
{
	IDirect3DDevice9* pDevice = pGraphicsService->GetDevice();
	if (pDevice == 0)
		return;

	// If the buffer exists tear it down.
	if (pShaderBuffer != 0)
	{
		UnloadResource();
	}

	// compile the shader source
	ID3DXBuffer* buffer;

	LPD3DXBUFFER ppErroMessage;
	D3DXCompileShader((LPCSTR)pShaderBytes, sizeInBytes, 0, 0, "main", "vs_2_0", 0, &buffer, &ppErroMessage, 0);
	
	if (ppErroMessage != 0)
	{
		OutputDebugStringA((char*)(ppErroMessage->GetBufferPointer()));
		isDirty = true;
		return;
	}

	if( FAILED( pDevice->CreateVertexShader((DWORD*)buffer->GetBufferPointer(), &pShaderBuffer)))
	{
		isDirty = true;
		return;
	}

	buffer->Release();
	isDirty = false;

	// load the vertex declaration into the pool
	pGraphicsService->PoolVertexDeclaration(vertexDeclaration, vertexDataCount);
}
void mini3d::OGL20BitmapTexture::LoadResource(void)
{
    if (pBitmap == 0 || sizeInBytes == 0)
    {
		UnloadResource();
        return;
    }

	// If the buffer exists but is not the correct size, tear it down and recreate it
	if (pTexture != 0 && (bufferWidth != width || bufferHeight != height))
	{
		UnloadResource();
	}

	GLuint fmt;

	switch (bitDepth)
	{
	case IBitmapTexture::BIT_16:
		fmt = GL_RGBA4;
		break;
	case IBitmapTexture::BIT_32:
		fmt = GL_RGBA8;
		break;
	case IBitmapTexture::BIT_64:
		fmt = GL_RGBA16;
		break;
	default:
		fmt = GL_RGBA8;
	}

	// If it does not exist, create a new one
	if (pTexture == 0)
	{
		glGenTextures(1, &pTexture);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		glBindTexture(GL_TEXTURE_2D, pTexture);
		
		try{
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 0);
		}
		catch  (GLuint error)
		{
			switch (error)
			{
			case GL_OUT_OF_MEMORY:
				isDirty = true;
				return;
				break;
			}
		}
	}

	// write bitmap data to texture
	try
	{
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pBitmap);
	}
	catch (GLuint error) // TODO: Fix this to something useful
	{
		switch (error)
		{
		case 0:
		default:
			isDirty = true;
			break;
		}
	}

	// Clear the current bound texture
	glBindTexture(GL_TEXTURE_2D, 0);

	bufferWidth = width;
	bufferHeight = height;
	isDirty = false;
}
mini3d::OGL20BitmapTexture::~OGL20BitmapTexture(void)
{
	UnloadResource();
	UnloadBitmap();
	pGraphicsService->RemoveResource(this);
}
U2D3DXEffectShader::~U2D3DXEffectShader()
{
	UnloadResource();
	RemoveShaderFromList();		
}
mini3d::OGL20RenderTargetTexture::~OGL20RenderTargetTexture(void)
{
	UnloadResource();
	pGraphicsService->RemoveResource(this);
}