Skip to content

Commit

Permalink
Moved some declarations from drawing_requests.hpp to drawing_context.…
Browse files Browse the repository at this point in the history
…hpp to reduce include dependencies
  • Loading branch information
Grumbel committed Aug 12, 2014
1 parent 4bd64f6 commit b2afe9f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 80 deletions.
8 changes: 4 additions & 4 deletions src/video/drawing_context.cpp
Expand Up @@ -326,8 +326,9 @@ DrawingContext::do_drawing()
target_stack.clear();

//Use Lightmap if ambient color is not white.
bool use_lightmap = ( ambient_color.red != 1.0f || ambient_color.green != 1.0f ||
ambient_color.blue != 1.0f );
bool use_lightmap = ( ambient_color.red != 1.0f ||
ambient_color.green != 1.0f ||
ambient_color.blue != 1.0f );

// PART1: create lightmap
if(use_lightmap) {
Expand All @@ -341,10 +342,9 @@ DrawingContext::do_drawing()
request->layer = LAYER_HUD - 1;
drawing_requests.push_back(request);
}
handle_drawing_requests(drawing_requests);

clear_drawing_requests(lightmap_requests);

handle_drawing_requests(drawing_requests);
clear_drawing_requests(drawing_requests);

obstack_free(&obst, NULL);
Expand Down
54 changes: 45 additions & 9 deletions src/video/drawing_context.hpp
Expand Up @@ -26,24 +26,60 @@
#include "math/rectf.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/drawing_request.hpp"
#include "video/font.hpp"
#include "video/font_ptr.hpp"
#include "video/texture.hpp"

class DrawingRequest;
class Lightmap;
class Renderer;
class Surface;
class Texture;
class Renderer;
class Lightmap;

inline int next_po2(int val)
// some constants for predefined layer values
enum {
// Image/gradient backgrounds (should cover entire screen)
LAYER_BACKGROUND0 = -300,
// Particle backgrounds
LAYER_BACKGROUND1 = -200,
// Tilemap backgrounds
LAYER_BACKGROUNDTILES = -100,
// Solid tilemaps
LAYER_TILES = 0,
// Ordinary objects
LAYER_OBJECTS = 50,
// Objects that pass through walls
LAYER_FLOATINGOBJECTS = 150,
//
LAYER_FOREGROUNDTILES = 200,
//
LAYER_FOREGROUND0 = 300,
//
LAYER_FOREGROUND1 = 400,
// Hitpoints, time, coins, etc.
LAYER_HUD = 500,
// Menus, mouse, console etc.
LAYER_GUI = 600
};

class Blend
{
int result = 1;
while(result < val)
result *= 2;
public:
GLenum sfactor;
GLenum dfactor;

Blend()
: sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
{}

return result;
}
Blend(GLenum s, GLenum d)
: sfactor(s), dfactor(d)
{}
};

enum Target {
NORMAL, LIGHTMAP
};

/**
* This class provides functions for drawing things on screen. It also
Expand Down
46 changes: 1 addition & 45 deletions src/video/drawing_request.hpp
Expand Up @@ -25,56 +25,12 @@

#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/drawing_context.hpp"
#include "video/font.hpp"
#include "video/glutil.hpp"

class Surface;

// some constants for predefined layer values
enum {
// Image/gradient backgrounds (should cover entire screen)
LAYER_BACKGROUND0 = -300,
// Particle backgrounds
LAYER_BACKGROUND1 = -200,
// Tilemap backgrounds
LAYER_BACKGROUNDTILES = -100,
// Solid tilemaps
LAYER_TILES = 0,
// Ordinary objects
LAYER_OBJECTS = 50,
// Objects that pass through walls
LAYER_FLOATINGOBJECTS = 150,
//
LAYER_FOREGROUNDTILES = 200,
//
LAYER_FOREGROUND0 = 300,
//
LAYER_FOREGROUND1 = 400,
// Hitpoints, time, coins, etc.
LAYER_HUD = 500,
// Menus, mouse, console etc.
LAYER_GUI = 600
};

class Blend
{
public:
GLenum sfactor;
GLenum dfactor;

Blend()
: sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
{}

Blend(GLenum s, GLenum d)
: sfactor(s), dfactor(d)
{}
};

enum Target {
NORMAL, LIGHTMAP
};

enum RequestType
{
SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, DRAW_LIGHTMAP, GETLIGHT
Expand Down
37 changes: 19 additions & 18 deletions src/video/font.cpp
Expand Up @@ -32,6 +32,7 @@
#include "util/log.hpp"
#include "util/utf8_iterator.hpp"
#include "video/drawing_context.hpp"
#include "video/drawing_request.hpp"
#include "video/font.hpp"
#include "video/renderer.hpp"

Expand Down Expand Up @@ -81,7 +82,7 @@ Font::Font(GlyphWidth glyph_width_,
PHYSFS_freeList(rc);
}

void
void
Font::loadFontFile(const std::string &filename)
{
lisp::Parser parser;
Expand All @@ -100,7 +101,7 @@ Font::loadFontFile(const std::string &filename)
if( !config_l->get("glyph-width",def_char_width) ) {
log_warning << "Font:"<< filename << ": misses default glyph-width" << std::endl;
}

if( !config_l->get("glyph-height",char_height) ) {
std::ostringstream msg;
msg << "Font:" << filename << ": misses glyph-height";
Expand Down Expand Up @@ -158,7 +159,7 @@ Font::loadFontFile(const std::string &filename)
}
}

void
void
Font::loadFontSurface(
const std::string &glyphimage,
const std::string &shadowimage,
Expand All @@ -176,9 +177,9 @@ Font::loadFontSurface(

int row=0, col=0;
int wrap = glyph_surface->get_width() / char_width;

SDL_Surface *surface = NULL;

if( glyph_width == VARIABLE ) {
//this does not work:
// surface = ((SDL::Texture *)glyph_surface.get_texture())->get_texture();
Expand All @@ -197,17 +198,17 @@ Font::loadFontSurface(
int x = col * (char_width + 2*border) + border;
if( ++col == wrap ) { col=0; row++; }
if( *chr == 0x0020 && glyphs[0x20].surface_idx != -1) continue;

Glyph glyph;
glyph.surface_idx = surface_idx;
if( glyph_width == FIXED )

if( glyph_width == FIXED )
{
glyph.rect = Rectf(x, y, x + char_width, y + char_height);
glyph.offset = Vector(0, 0);
glyph.advance = char_width;
}
else
else
{
if (y + char_height > surface->h)
{
Expand All @@ -221,13 +222,13 @@ Font::loadFontSurface(
int right = x + char_width - 1;
while (right > left && vline_empty(surface, right, y, y + char_height, 64))
right -= 1;
if (left <= right)

if (left <= right)
{
glyph.offset = Vector(x-left, 0);
glyph.advance = right - left + 1 + 1; // FIXME: might be useful to make spacing configurable
}
else
}
else
{ // glyph is completly transparent
glyph.offset = Vector(0, 0);
glyph.advance = char_width + 1; // FIXME: might be useful to make spacing configurable
Expand All @@ -238,7 +239,7 @@ Font::loadFontSurface(

glyphs[*chr] = glyph;
}
if( col>0 && col <= wrap ) {
if( col>0 && col <= wrap ) {
col = 0;
row++;
}
Expand Down Expand Up @@ -272,7 +273,7 @@ Font::get_text_width(const std::string& text) const
{
if( glyphs.at(*it).surface_idx != -1 )
curr_width += glyphs[*it].advance;
else
else
curr_width += glyphs[0x20].advance;
}
}
Expand Down Expand Up @@ -344,7 +345,7 @@ Font::wrap_to_width(const std::string& s_, float width, std::string* overflow)
return s.substr(0, i);
}
}

// FIXME: hard-wrap at width, taking care of multibyte characters
if (overflow) *overflow = "";
return s;
Expand Down Expand Up @@ -393,7 +394,7 @@ Font::draw_text(Renderer *renderer, const std::string& text, const Vector& pos,
DrawingEffect drawing_effect, Color color, float alpha) const
{
if(shadowsize > 0)
draw_chars(renderer, false, text,
draw_chars(renderer, false, text,
pos + Vector(shadowsize, shadowsize), drawing_effect, Color(1,1,1), alpha);

draw_chars(renderer, true, text, pos, drawing_effect, color, alpha);
Expand Down Expand Up @@ -422,7 +423,7 @@ Font::draw_chars(Renderer *renderer, bool notshadow, const std::string& text,
Glyph glyph;
if( glyphs.at(*it).surface_idx != -1 )
glyph = glyphs[*it];
else
else
glyph = glyphs[0x20];

DrawingRequest request;
Expand Down
17 changes: 13 additions & 4 deletions src/video/gl/gl_lightmap.cpp
Expand Up @@ -41,6 +41,15 @@
#include "video/surface.hpp"
#include "video/texture_manager.hpp"

inline int next_po2(int val)
{
int result = 1;
while(result < val)
result *= 2;

return result;
}

GLLightmap::GLLightmap() :
lightmap(),
lightmap_width(),
Expand All @@ -67,7 +76,7 @@ GLLightmap::~GLLightmap()
void
GLLightmap::start_draw(const Color &ambient_color)
{

glGetFloatv(GL_VIEWPORT, old_viewport); //save viewport
glViewport(old_viewport[0], old_viewport[3] - lightmap_height + old_viewport[1], lightmap_width, lightmap_height);
glMatrixMode(GL_PROJECTION);
Expand All @@ -90,7 +99,7 @@ GLLightmap::end_draw()
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, old_viewport[0], old_viewport[3] - lightmap_height + old_viewport[1], lightmap_width, lightmap_height);

glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Expand Down Expand Up @@ -193,7 +202,7 @@ GLLightmap::draw_surface_part(const DrawingRequest& request)
void
GLLightmap::draw_gradient(const DrawingRequest& request)
{
const GradientRequest* gradientrequest
const GradientRequest* gradientrequest
= (GradientRequest*) request.request_data;
const Color& top = gradientrequest->top;
const Color& bottom = gradientrequest->bottom;
Expand Down Expand Up @@ -261,7 +270,7 @@ GLLightmap::draw_filled_rect(const DrawingRequest& request)
void
GLLightmap::get_light(const DrawingRequest& request) const
{
const GetLightRequest* getlightrequest
const GetLightRequest* getlightrequest
= (GetLightRequest*) request.request_data;

float pixels[3];
Expand Down

0 comments on commit b2afe9f

Please sign in to comment.