[Android] Make texture loading/deleting/drawing backend non-specific by making them happen in the backend instead of somewhere else. Just a clean up commit really.

This commit is contained in:
Ryan Houdek
2013-09-02 01:40:05 -05:00
parent 0219049c03
commit 831963616f
9 changed files with 83 additions and 47 deletions

View File

@ -122,12 +122,13 @@ void SWRenderer::DrawDebugText()
SWRenderer::RenderText(debugtext_buffer, 21, 21, 0xDD000000);
SWRenderer::RenderText(debugtext_buffer, 20, 20, 0xFFFFFF00);
}
#ifdef ANDROID
// XXX: This /really/ shouldn't be here
// But for now, we don't have a generic way for all backends to draw the buttons on screen.
// Once that is implemented, we can remove this
void DrawButton(GLuint tex, float *coords)
// XXX: We should /really/ be outputting textures to the texture image instead of this way.
void SWRenderer::DrawButton(int texID, float *coords)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Texture rectangle uses pixel coordinates
#ifndef USE_GLES
GLfloat u_max = (GLfloat)width;
@ -147,7 +148,7 @@ void DrawButton(GLuint tex, float *coords)
{1, 1}
};
#endif
glBindTexture(TEX2D, tex);
glBindTexture(TEX2D, texID);
glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, coords);
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts);
@ -160,8 +161,10 @@ void DrawButton(GLuint tex, float *coords)
glDisableVertexAttribArray(attr_tex);
glBindTexture(TEX2D, 0);
glDisable(GL_BLEND);
}
#endif
void SWRenderer::DrawTexture(u8 *texture, int width, int height)
{
GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();

View File

@ -16,6 +16,7 @@ namespace SWRenderer
void RenderText(const char* pstr, int left, int top, u32 color);
void DrawDebugText();
void DrawButton(int texId, float *coords);
void DrawTexture(u8 *texture, int width, int height);
void SwapBuffer();

View File

@ -242,6 +242,32 @@ bool VideoSoftware::Video_Screenshot(const char *_szFilename)
return false;
}
int VideoSoftware::Video_LoadTexture(char *image, u32 width, u32 height)
{
GLuint Texture = 0;
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image);
return (int) Texture;
}
void VideoSoftware::Video_DeleteTexture(int texID)
{
if (texID == -1) return;
glDeleteTextures(1, (GLuint*)&texID);
}
void VideoSoftware::Video_DrawTexture(int texID, float *coords)
{
if (texID == -1) return;
SWRenderer::DrawButton(texID, coords);
}
// -------------------------------
// Enter and exit the video loop
// -------------------------------

View File

@ -35,6 +35,10 @@ class VideoSoftware : public VideoBackend
void Video_ClearMessages();
bool Video_Screenshot(const char* filename);
int Video_LoadTexture(char *imagedata, u32 width, u32 height);
void Video_DeleteTexture(int texID);
void Video_DrawTexture(int texID, float *coords);
void Video_SetRendering(bool bEnabled);
void Video_GatherPipeBursted();