00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "Core/precomp.h"
00016 #ifdef USE_OPENGL
00017
00018 #include "blit_gl_generic.h"
00019 #include "Core/Display/Generic/pixeldata.h"
00020
00021
00022 void check4error()
00023 {
00024 GLenum error;
00025 while ((error = glGetError()) != GL_NO_ERROR)
00026 std::cout << gluErrorString(error) << std::endl;
00027 }
00028
00029 CL_Blit_GLTexture::CL_Blit_GLTexture(
00030 CL_GL_DisplayCard_Generic *card,
00031 CL_SurfaceProvider *provider)
00032 {
00033 card->begin_2d();
00034
00035 this->card = card;
00036 this->provider = provider;
00037
00038 provider->lock();
00039
00040 width = provider->get_width();
00041 height = provider->get_height();
00042 no_sprs = provider->get_num_frames();
00043
00044 int texture_size = 1;
00045 while (texture_size < width || texture_size < height*no_sprs) texture_size *= 2;
00046
00047 texture_width = texture_size;
00048 texture_height = texture_size;
00049
00050 cl_assert(width <= texture_width);
00051 cl_assert(height <= texture_height);
00052
00053 unsigned int *texture_data = new unsigned int[texture_width*texture_height];
00054 memset(texture_data, 0, texture_width*texture_height*sizeof(int));
00055
00056 glGenTextures(1,&texture);
00057 glBindTexture(GL_TEXTURE_2D, texture);
00058
00059
00060
00061 glTexImage2D(
00062 GL_TEXTURE_2D,
00063 0,
00064 GL_RGBA,
00065 texture_width,
00066 texture_height,
00067 0,
00068 GL_RGBA,
00069 GL_UNSIGNED_BYTE,
00070 texture_data);
00071
00072 delete[] texture_data;
00073
00074 card->end_2d();
00075 }
00076
00077 CL_Blit_GLTexture::~CL_Blit_GLTexture()
00078 {
00079 provider->unlock;
00080 glDeleteTextures(1,&texture);
00081 }
00082
00083 void CL_Blit_GLTexture::blt_noclip(
00084 CL_Target *target,
00085 int x,
00086 int y,
00087 int spr_no)
00088 {
00089 card->begin_2d();
00090
00091
00092 glBindTexture(GL_TEXTURE_2D, texture);
00093 glTexSubImage2D(
00094 GL_TEXTURE_2D,
00095 0,
00096 0,
00097 0,
00098 m_width,
00099 m_height,
00100 GL_RGBA,
00101 GL_UNSIGNED_BYTE,
00102 provider->get_data());
00103
00104 float h1 = ((float) height * spr_no) / texture_height;
00105 float h2 = ((float) height * (spr_no+1)) / texture_height;
00106 float w = (float) width / texture_width;
00107 glBegin(GL_TRIANGLE_STRIP);
00108 glTexCoord2f(0.0, h1); glVertex2i(x, y);
00109 glTexCoord2f( w, h1); glVertex2i(x + width, y);
00110 glTexCoord2f(0.0, h2); glVertex2i(x, y + height);
00111 glTexCoord2f( w, h2); glVertex2i(x + width, y + height);
00112 glEnd();
00113
00114 card->end_2d();
00115 }
00116
00117 void CL_Blit_GLTexture::blt_clip(
00118 CL_Target *target,
00119 int x,
00120 int y,
00121 int spr_no,
00122 const CL_ClipRect &clip)
00123 {
00124
00125 blt_noclip(target,x,y,spr_no);
00126 }
00127
00128 void CL_Blit_GLTexture::blt_scale_noclip(
00129 CL_Target *target,
00130 int x,
00131 int y,
00132 int dest_width,
00133 int dest_height,
00134 int spr_no)
00135 {
00136 card->begin_2d();
00137
00138 glBindTexture(GL_TEXTURE_2D, texture);
00139 float h1 = ((float) height * spr_no) / texture_height;
00140 float h2 = ((float) height * (spr_no+1)) / texture_height;
00141 float w = (float) width / texture_width;
00142 glBegin(GL_TRIANGLE_STRIP);
00143 glTexCoord2f(0.0, h1); glVertex2i(x, y);
00144 glTexCoord2f( w, h1); glVertex2i(x + dest_width, y);
00145 glTexCoord2f(0.0, h2); glVertex2i(x, y + dest_height);
00146 glTexCoord2f( w, h2); glVertex2i(x + dest_width, y + dest_height);
00147 glEnd();
00148
00149 card->end_2d();
00150 }
00151
00152 void CL_Blit_GLTexture::blt_scale_clip(
00153 CL_Target *target,
00154 int x,
00155 int y,
00156 int dest_width,
00157 int dest_height,
00158 int spr_no,
00159 const CL_ClipRect &clip)
00160 {
00161
00162 blt_scale_noclip(target, x, y, dest_width, dest_height, spr_no);
00163 }
00164
00165 #endif