win32: add demo of agg compositing separate lua and emuscreen layers

This commit is contained in:
zeromus 2009-07-09 08:16:10 +00:00
parent d4b9473034
commit 7459a4a0db
3 changed files with 137 additions and 26 deletions

View File

@ -35,7 +35,13 @@
#include "agg_path_storage.h"
#include "agg_color_rgba.h"
#include "agg_pixfmt_rgb.h"
#include "agg_pixfmt_rgba.h"
#include "agg_pixfmt_rgb_packed.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_scanline_u.h"
#include "agg_renderer_scanline.h"
#include "agg_scanline_p.h"
//raster text
@ -49,6 +55,14 @@
#include "agg_renderer_outline_image.h"
#include "agg_rasterizer_outline_aa.h"
#include "agg_image_accessors.h"
#include "agg_span_interpolator_linear.h"
#include "agg_span_image_filter_rgb.h"
#include "agg_span_image_filter_rgba.h"
#include "agg_span_image_filter_gray.h"
#include "agg_span_allocator.h"
typedef std::map<std::string, const agg::int8u*> TAgg_Font_Table;
static TAgg_Font_Table font_table;
@ -108,24 +122,87 @@ void Agg_init_fonts()
font_table[fonts[i].name] = fonts[i].font;
}
#include "agg_pixfmt_rgb.h"
#include "agg_pixfmt_rgb_packed.h"
AggDraw_Desmume aggDraw;
typedef AggDrawTargetImplementation<agg::pixfmt_rgb555> T_AGG_RGB555;
T_AGG_RGB555 agg_targetScreen(GPU_tempScreen, 256, 384, 512);
typedef AggDrawTargetImplementation<agg::pixfmt_bgra32> T_AGG_RGBA;
T_AGG_RGB555 agg_targetScreen(GPU_screen, 256, 384, 512);
static u32 luaBuffer[256*192*2];
T_AGG_RGBA agg_targetLua((u8*)luaBuffer, 256, 384, 1024);
static AggDrawTarget* targets[] = {
&agg_targetScreen,
&agg_targetLua
};
void Agg_init()
{
aggDraw.target = &agg_targetScreen;
Agg_init_fonts();
aggDraw.target = targets[0];
}
void AggDraw_Desmume::setTarget(AggTarget newTarget)
{
target = targets[newTarget];
}
void AggDraw_Desmume::composite(void* dest)
{
//!! oh what a mess !!
agg::rendering_buffer rBuf;
rBuf.attach((u8*)dest, 256, 384, 1024);
typedef agg::image_accessor_clip<T_AGG_RGBA::pixfmt> img_source_type;
img_source_type img_src(agg_targetLua.pixf, T_AGG_RGBA::pixfmt::color_type(0,255,0,0));
agg::trans_affine img_mtx;
typedef agg::span_interpolator_linear<> interpolator_type;
interpolator_type interpolator(img_mtx);
typedef agg::span_image_filter_rgba_nn<img_source_type,interpolator_type> span_gen_type;
span_gen_type sg(img_src, interpolator);
agg::rasterizer_scanline_aa<> ras;
//dont know whether this is necessary
//ras.clip_box(0, 0, 256,384);
agg::scanline_u8 sl;
//I can't believe we're using a polygon for a rectangle.
//there must be a better way
agg::path_storage path;
path.move_to(0, 0);
path.line_to(255, 0);
path.line_to(255, 383);
path.line_to(0, 383);
path.close_polygon();
T_AGG_RGBA::pixfmt pixf(rBuf);
T_AGG_RGBA::RendererBase rbase(pixf);
agg::span_allocator<T_AGG_RGBA::color_type> sa;
ras.add_path(path);
agg::render_scanlines_bin(ras, sl, rbase, sa, sg);
}
static int ctr=0;
//temporary, just for testing the lib
void AGGDraw() {
aggDraw.setTarget(AggTarget_Lua);
aggDraw.target->clear();
ctr++;
aggDraw.target->set_color(0, 255, 0, 128);
aggDraw.target->solid_rectangle(100, 100, 200, 200);
int add = (int)(40*cos((double)ctr/20.0f));
aggDraw.target->solid_rectangle(100 +add , 100, 200 + add, 200);
aggDraw.target->set_gamma(99999);
aggDraw.target->set_color(255, 64, 64, 128);
@ -135,9 +212,9 @@ void AGGDraw() {
aggDraw.target->solid_ellipse(70, 80, 50, 50);
aggDraw.target->set_font("verdana18_bold");
aggDraw.target->set_color(255, 0, 255, 128);
aggDraw.target->set_color(255, 0, 255, 255);
aggDraw.target->render_text(60,60, "testing testing testing");
//
//agg_draw_line_pattern(64, 19, 14, 126, 118, 266, 19, 265, .76, 4.69, "C:\\7.bmp");
}

View File

@ -30,9 +30,9 @@
#include "agg_color_rgba.h"
#include "agg_rendering_buffer.h"
#include "agg_renderer_base.h"
#include "agg_renderer_primitives.h"
#include "agg_renderer_scanline.h"
#include "agg_renderer_base.h"
#include "agg_renderer_primitives.h"
#include "agg_renderer_scanline.h"
#include "agg_bounding_rect.h"
class AggDrawTarget
@ -41,6 +41,9 @@ public:
virtual void set_color(int r, int g, int b, int a) = 0;
virtual void set_gamma(int gamma) = 0;
virtual void set_font(const std::string& name) = 0;
virtual void set_pixel(int x, int y) = 0;
virtual void clear() = 0;
virtual void render_text(int x, int y, const std::string& str) = 0;
virtual void solid_ellipse(int x, int y, int rx, int ry) = 0;
@ -50,33 +53,35 @@ public:
static const agg::int8u* lookupFont(const std::string& name);
};
template<typename pixfmt>
template<typename PIXFMT>
class AggDrawTargetImplementation : public AggDrawTarget
{
public:
typedef PIXFMT pixfmt;
// The AGG base
typedef agg::renderer_base<pixfmt> RendererBase;
// The AGG primitives renderer
// The AGG primitives renderer
typedef agg::renderer_primitives<RendererBase> RendererPrimitives;
// The AGG solid renderer
// The AGG solid renderer
typedef agg::renderer_scanline_aa_solid<RendererBase> RendererSolid;
//the order of declaration matters in order to make these variables get setup correctly
agg::rendering_buffer rBuf;
pixfmt pixf;
RendererBase rbase;
RendererBase rbase;
RendererPrimitives rprim;
AggDrawTargetImplementation(agg::int8u* buf, int width, int height, int stride)
: rBuf(buf,width,height,stride)
, pixf(rBuf)
, rbase(pixf)
, rprim(rbase)
{
}
, pixf(rBuf)
, rbase(pixf)
, rprim(rbase)
{
}
typedef typename pixfmt::color_type color_type;
@ -96,6 +101,17 @@ public:
virtual void set_gamma(int gamma) { renderState.gamma = gamma; }
virtual void set_font(const std::string& name) { renderState.font = lookupFont(name); }
virtual void set_pixel(int x, int y)
{
pixf.copy_pixel(x, y, renderState.color);
}
virtual void clear()
{
static color_type transparentBlack(0,0,0,0);
rbase.clear(transparentBlack);
}
virtual void render_text(int x, int y, const std::string& str)
{
typedef agg::renderer_base<pixfmt> ren_base;
@ -110,15 +126,15 @@ public:
rt.render_text(x, y, str.c_str(), true); //flipy
}
virtual void solid_ellipse(int x, int y, int rx, int ry)
{
rprim.fill_color(renderState.color);
rprim.solid_ellipse(x, y, rx, ry);
virtual void solid_ellipse(int x, int y, int rx, int ry)
{
rprim.fill_color(renderState.color);
rprim.solid_ellipse(x, y, rx, ry);
}
virtual void solid_rectangle(int x1, int y1, int x2, int y2)
{
rprim.fill_color(renderState.color);
rprim.fill_color(renderState.color);
rprim.solid_rectangle(x1, y1, x2, y2);
}
@ -154,9 +170,18 @@ public:
AggDrawTarget *target;
};
enum AggTarget
{
AggTarget_Screen = 0,
AggTarget_Lua = 1
};
//specialized instance for desmume; should eventually move to another file
class AggDraw_Desmume : public AggDraw
{
public:
void setTarget(AggTarget newTarget);
void composite(void* dest);
};
extern AggDraw_Desmume aggDraw;

View File

@ -83,9 +83,11 @@
#include "7zip.h"
#include "pathsettings.h"
#include "utils/xstring.h"
#include "directx/ddraw.h"
#include "aggdraw.h"
using namespace std;
#define HAVE_REMOTE
@ -774,6 +776,9 @@ void Display()
ddsd.dwFlags=DDSD_ALL;
res = lpBackSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
extern void AGGDraw();
AGGDraw();
if (res == DD_OK)
{
char* buffer = (char*)ddsd.lpSurface;
@ -828,6 +833,8 @@ void Display()
break;
}
}
//aggDraw.composite(ddsd.lpSurface);
break;
case 16:
@ -1469,6 +1476,8 @@ std::string GetPrivateProfileStdString(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR
int _main()
{
extern void Agg_init();
Agg_init();
InitDecoder();
#ifdef WX_STUB