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)) {
159 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
160 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
187 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
188 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
212 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
213 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
281 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
285 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
295 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast<GLint>(
RenderBackend::instance()->getMaxAnisotropy()));
304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
313 GLint internalFormat = GL_RGBA8;
315 internalFormat = GL_COMPRESSED_RGBA;
323 int32_t bpp_target = target->format->BitsPerPixel;
324 int32_t bpp_source =
m_surface->format->BitsPerPixel;
326 if (bpp_target == 16 && bpp_source == 32) {
330 for (
uint32_t y = 0; y < height; ++y) {
331 for (
uint32_t x = 0; x < width; ++x) {
332 uint32_t pos = (y * pitch) + (x * 4);
360 internalFormat = GL_RGBA4;
365 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, oglbuffer);
374 memcpy(oglbuffer, data, width * height * 4 *
sizeof(
uint8_t));
376 for (
uint32_t y = 0; y < height; ++y) {
377 for (
uint32_t x = 0; x < width * 4; x += 4) {
380 uint8_t r = oglbuffer[gid + 0];
381 uint8_t g = oglbuffer[gid + 1];
382 uint8_t b = oglbuffer[gid + 2];
386 oglbuffer[gid + 3] = 0;
391 oglbuffer[gid + 0] = lum;
392 oglbuffer[gid + 1] = lum;
393 oglbuffer[gid + 2] = lum;
400 0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
403 }
else if (monochrome) {
405 memcpy(oglbuffer, data, width * height * 4 *
sizeof(
uint8_t));
407 for (
uint32_t y = 0; y < height; ++y) {
408 for (
uint32_t x = 0; x < width * 4; x += 4) {
411 uint8_t lum =
static_cast<uint8_t>(oglbuffer[gid + 0]*0.3 + oglbuffer[gid + 1]*0.59 + oglbuffer[gid + 2]*0.11);
412 oglbuffer[gid + 0] = lum;
413 oglbuffer[gid + 1] = lum;
414 oglbuffer[gid + 2] = lum;
420 0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
426 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
433 for (
uint32_t y = 0; y < height; ++y) {
434 for (
uint32_t x = 0; x < width; ++x) {
435 uint32_t pos = (y * pitch) + (x * 4);
456 oglbuffer[(y*
m_chunk_size_w) + x] = r | (g << 8) | (b << 16) | (a<<24);
462 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(oglbuffer));
479 m_tex_coords[0] = (
static_cast<GLfloat
>(region.
x)+0.5) /
static_cast<GLfloat
>(width);
480 m_tex_coords[1] = (
static_cast<GLfloat
>(region.
y)+0.5) /
static_cast<GLfloat
>(height);
481 m_tex_coords[2] = (
static_cast<GLfloat
>(region.
x + region.
w)-0.5) /
static_cast<GLfloat
>(width);
482 m_tex_coords[3] = (
static_cast<GLfloat
>(region.
y + region.
h)-0.5) /
static_cast<GLfloat
>(height);
484 m_tex_coords[0] =
static_cast<GLfloat
>(region.
x) / static_cast<GLfloat>(width);
485 m_tex_coords[1] =
static_cast<GLfloat
>(region.
y) / static_cast<GLfloat>(height);
486 m_tex_coords[2] =
static_cast<GLfloat
>(region.
x + region.
w) / static_cast<GLfloat>(width);
487 m_tex_coords[3] =
static_cast<GLfloat
>(region.
y + region.
h) / static_cast<GLfloat>(height);
542 glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, img->
getWidth(), img->
getHeight(),
543 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()
bool isMipmappingEnabled() const
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
bool isMonochromeEnabled() 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.
virtual void renderZ(const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
The main class of the OpenGL-based renderer.