73 Image(data, width, height),
82 Image(name, data, width, height),
135 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
136 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
203 GLint internalFormat = GL_RGBA8;
205 internalFormat = GL_COMPRESSED_RGBA;
212 int32_t bpp_target = target->format->BitsPerPixel;
213 int32_t bpp_source =
m_surface->format->BitsPerPixel;
215 if (bpp_target == 16 && bpp_source == 32) {
219 for (
uint32_t y = 0; y < height; ++y) {
220 for (
uint32_t x = 0; x < width; ++x) {
221 uint32_t pos = (y * pitch) + (x * 4);
243 internalFormat = GL_RGBA4;
248 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, oglbuffer);
257 memcpy(oglbuffer, data, width * height * 4 *
sizeof(
uint8_t));
259 for (
uint32_t y = 0; y < height; ++y) {
260 for (
uint32_t x = 0; x < width * 4; x += 4) {
263 uint8_t r = oglbuffer[gid + 0];
264 uint8_t g = oglbuffer[gid + 1];
265 uint8_t b = oglbuffer[gid + 2];
269 oglbuffer[gid + 3] = 0;
276 0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
282 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
289 for (
uint32_t y = 0; y < height; ++y) {
290 for (
uint32_t x = 0; x < width; ++x) {
291 uint32_t pos = (y * pitch) + (x * 4);
305 oglbuffer[(y*
m_chunk_size_w) + x] = r | (g << 8) | (b << 16) | (a<<24);
311 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(oglbuffer));
326 m_tex_coords[0] =
static_cast<GLfloat
>(region.
x) / static_cast<GLfloat>(width);
327 m_tex_coords[1] =
static_cast<GLfloat
>(region.
y) / static_cast<GLfloat>(height);
328 m_tex_coords[2] =
static_cast<GLfloat
>(region.
x + region.
w) / static_cast<GLfloat>(width);
329 m_tex_coords[3] =
static_cast<GLfloat
>(region.
y + region.
h) / static_cast<GLfloat>(height);
381 glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, img->
getWidth(), img->
getHeight(),
382 GL_RGBA, GL_UNSIGNED_BYTE, img->
getSurface()->pixels);
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
void reset(SDL_Surface *surface)
Resets the image to default values (including the x and y shift values), frees the current surface an...
virtual void addImageToArray(uint32_t id, const Rect &rec, float const *st, uint8_t alpha, uint8_t const *rgba)=0
Add the Image data to the array.
Abstract interface for all the renderbackends.
T * get() const
allows direct access to underlying pointer
virtual void invalidate()
Invalidates the Image causing it to be reset or re-loaded.
void generateGLTexture()
Generates the GL Texture for use when rendering.
virtual ResourceState getState()
T h
Height of the rectangle.
virtual void setSurface(SDL_Surface *surface)
This frees the current suface and replaces it with the surface passed in the parameter (which can be ...
unsigned nextPow2(unsigned x)
Returns the next higher power of 2 based on the passed argument.
void resetGlimage()
Resets GLImage variables.
GLImage(IResourceLoader *loader=0)
const GLfloat * getTexCoords() const
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
virtual void useSharedImage(const ImagePtr &shared, const Rect ®ion)
After this call all image data will be taken from the given image and its subregion.
static RenderBackend * instance()
uint32_t getHeight() const
bool isColorKeyEnabled() const
Gets whether the colorkey feature is in use.
GLuint m_texId
Holds texture ids that are used to access textures in GL rendering context.
T bottom() const
The Y coordinate of the bottom edge.
SDL_Surface * getSurface()
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
const SDL_Color & getColorKey() const
Gets the global colorkey setting.
void generateGLSharedTexture(const GLImage *shared, const Rect ®ion)
virtual const std::string & getName()
uint32_t getWidth() const
T right() const
The X coordinate of the right edge.
virtual void setState(const ResourceState &state)
virtual void forceLoadInternal()
Forces to load the image into internal memory of GPU.
void cleanup()
Frees allocated memory and calls resetGlImage.
SDL_Surface * getRenderTargetSurface()
Returns currently attached render surface.
Implements an Image using OpenGL.
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)
Renders itself to the current render target (main screen or attached destination image) at the rectan...
T w
Width of the rectangle.
The main class of the OpenGL-based renderer.