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)) {
158 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
159 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
185 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
186 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
208 if (rect.
right() < 0 || rect.
x >
static_cast<int32_t
>(target->w) ||
209 rect.
bottom() < 0 || rect.
y >
static_cast<int32_t
>(target->h)) {
277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
281 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
295 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast<GLint>(
RenderBackend::instance()->getMaxAnisotropy()));
300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmapping ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
309 GLint internalFormat = GL_RGBA8;
311 internalFormat = GL_COMPRESSED_RGBA;
320 int32_t bpp_source =
m_surface->format->BitsPerPixel;
322 if (bpp_target == 16 && bpp_source == 32) {
326 for (
uint32_t y = 0; y < height; ++y) {
327 for (
uint32_t x = 0; x < width; ++x) {
328 uint32_t pos = (y * pitch) + (x * 4);
356 internalFormat = GL_RGBA4;
361 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, oglbuffer);
370 memcpy(oglbuffer, data, width * height * 4 *
sizeof(
uint8_t));
372 for (
uint32_t y = 0; y < height; ++y) {
373 for (
uint32_t x = 0; x < width * 4; x += 4) {
376 uint8_t r = oglbuffer[gid + 0];
377 uint8_t g = oglbuffer[gid + 1];
378 uint8_t b = oglbuffer[gid + 2];
382 oglbuffer[gid + 3] = 0;
387 oglbuffer[gid + 0] = lum;
388 oglbuffer[gid + 1] = lum;
389 oglbuffer[gid + 2] = lum;
396 0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
399 }
else if (monochrome) {
401 memcpy(oglbuffer, data, width * height * 4 *
sizeof(
uint8_t));
403 for (
uint32_t y = 0; y < height; ++y) {
404 for (
uint32_t x = 0; x < width * 4; x += 4) {
407 uint8_t lum =
static_cast<uint8_t>(oglbuffer[gid + 0]*0.3 + oglbuffer[gid + 1]*0.59 + oglbuffer[gid + 2]*0.11);
408 oglbuffer[gid + 0] = lum;
409 oglbuffer[gid + 1] = lum;
410 oglbuffer[gid + 2] = lum;
416 0, GL_RGBA, GL_UNSIGNED_BYTE, oglbuffer);
422 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
429 for (
uint32_t y = 0; y < height; ++y) {
430 for (
uint32_t x = 0; x < width; ++x) {
431 uint32_t pos = (y * pitch) + (x * 4);
452 oglbuffer[(y*
m_chunk_size_w) + x] = r | (g << 8) | (b << 16) | (a<<24);
458 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(oglbuffer));
475 m_tex_coords[0] = (
static_cast<GLfloat
>(region.
x)+0.5) /
static_cast<GLfloat
>(width);
476 m_tex_coords[1] = (
static_cast<GLfloat
>(region.
y)+0.5) /
static_cast<GLfloat
>(height);
477 m_tex_coords[2] = (
static_cast<GLfloat
>(region.
x + region.
w)-0.5) /
static_cast<GLfloat
>(width);
478 m_tex_coords[3] = (
static_cast<GLfloat
>(region.
y + region.
h)-0.5) /
static_cast<GLfloat
>(height);
480 m_tex_coords[0] =
static_cast<GLfloat
>(region.
x) / static_cast<GLfloat>(width);
481 m_tex_coords[1] =
static_cast<GLfloat
>(region.
y) / static_cast<GLfloat>(height);
482 m_tex_coords[2] =
static_cast<GLfloat
>(region.
x + region.
w) / static_cast<GLfloat>(width);
483 m_tex_coords[3] =
static_cast<GLfloat
>(region.
y + region.
h) / static_cast<GLfloat>(height);
538 glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, img->
getWidth(), img->
getHeight(),
539 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.
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()
const SDL_Color & getColorKey() const
Gets the global colorkey setting.
bool isColorKeyEnabled() const
Gets whether the colorkey feature is in use.
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.
const GLfloat * getTexCoords() const
GLImage(IResourceLoader *loader=0)
bool isMonochromeEnabled() 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()
GLuint m_texId
Holds texture ids that are used to access textures in GL rendering context.
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.
uint32_t getHeight() const
const SDL_PixelFormat & getPixelFormat() const
Gets the current screen rgba format.
void generateGLSharedTexture(const GLImage *shared, const Rect ®ion)
virtual const std::string & getName()
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.
T * get() const
allows direct access to underlying pointer
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)
bool isMipmappingEnabled() const
The main class of the OpenGL-based renderer.
T bottom() const
The Y coordinate of the bottom edge.
uint32_t getWidth() const