|
|
|
@ -145,7 +145,7 @@ namespace lunarium
|
|
|
|
if (mRT == RenderTarget::RT_IMAGE)
|
|
|
|
if (mRT == RenderTarget::RT_IMAGE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mpFBTexture->mGLTextureID);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mpFBTexture->GetGLTextureID());
|
|
|
|
|
|
|
|
|
|
|
|
// Buffer width and height (in pixels) is the same as the screen size
|
|
|
|
// Buffer width and height (in pixels) is the same as the screen size
|
|
|
|
// Need to multiply these by the number bytes per pixel
|
|
|
|
// Need to multiply these by the number bytes per pixel
|
|
|
|
@ -158,9 +158,9 @@ namespace lunarium
|
|
|
|
//glSetTexImage()
|
|
|
|
//glSetTexImage()
|
|
|
|
|
|
|
|
|
|
|
|
mpFBTexture->FreeRawData();
|
|
|
|
mpFBTexture->FreeRawData();
|
|
|
|
mpFBTexture->mWidth = mFBWidth;
|
|
|
|
mpFBTexture->SetWidth(mFBWidth);
|
|
|
|
mpFBTexture->mHeight = mFBHeight;
|
|
|
|
mpFBTexture->SetHeight(mFBHeight);
|
|
|
|
mpFBTexture->mFormat = ImageFormat::RGBA;
|
|
|
|
mpFBTexture->SetFormat(ImageFormat::RGBA);
|
|
|
|
|
|
|
|
|
|
|
|
// return a copy of the image
|
|
|
|
// return a copy of the image
|
|
|
|
return mpFBTexture;
|
|
|
|
return mpFBTexture;
|
|
|
|
@ -369,14 +369,15 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
// Takes raw image data and creates and Image class instance out of it.
|
|
|
|
// Takes raw image data and creates and Image class instance out of it.
|
|
|
|
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
|
|
|
|
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
|
|
|
|
Image* OglGraphics::CreateImage(const unsigned char* pData, int width, int height, ImageFormat format)
|
|
|
|
void OglGraphics::RegisterImage(Image& image)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int glFormat[4] = { GL_RGB, GL_RGBA, GL_BGR, GL_BGRA };
|
|
|
|
unsigned int glFormat[4] = { GL_RGB, GL_RGBA, GL_BGR, GL_BGRA };
|
|
|
|
unsigned int textureID = 0;
|
|
|
|
unsigned int textureID = 0;
|
|
|
|
glGenTextures(1, &textureID);
|
|
|
|
glGenTextures(1, &textureID);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
|
|
|
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, glFormat[format], width, height, 0, glFormat[format], GL_UNSIGNED_BYTE, pData);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, glFormat[image.GetFormat()], image.GetWidth(),
|
|
|
|
|
|
|
|
image.GetHeight(), 0, glFormat[image.GetFormat()], GL_UNSIGNED_BYTE, image.GetData());
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -387,18 +388,7 @@ namespace lunarium
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
|
|
|
|
Image* image = new Image;
|
|
|
|
image.SetGLTextureID(textureID);
|
|
|
|
image->mWidth = width;
|
|
|
|
|
|
|
|
image->mHeight = height;
|
|
|
|
|
|
|
|
image->mGLTextureID = textureID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OglGraphics::DestroyImage(Image* i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i->FreeRawData();
|
|
|
|
|
|
|
|
delete i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fonts
|
|
|
|
// Fonts
|
|
|
|
@ -537,15 +527,17 @@ namespace lunarium
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
|
|
|
|
|
|
|
|
|
|
|
|
// Texture
|
|
|
|
// Texture
|
|
|
|
glGenTextures(1, &mpFBTexture->mGLTextureID);
|
|
|
|
unsigned int id = -1;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mpFBTexture->mGLTextureID);
|
|
|
|
glGenTextures(1, &id);
|
|
|
|
|
|
|
|
mpFBTexture->SetGLTextureID(id);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mpFBTexture->GetGLTextureID());
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mFBWidth, mFBHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mFBWidth, mFBHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Attach texture
|
|
|
|
// Attach texture
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mpFBTexture->mGLTextureID, 0);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mpFBTexture->GetGLTextureID(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Render Buffer for depth/stencil testing
|
|
|
|
// Render Buffer for depth/stencil testing
|
|
|
|
glGenRenderbuffers(1, &mRBO);
|
|
|
|
glGenRenderbuffers(1, &mRBO);
|
|
|
|
|