From 080b8b2e244b295bb4e7c4e3a6ddbd084eb20b97 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 26 May 2003 18:48:34 +0000 Subject: [PATCH] add textures --- render2/Makefile.am | 18 ++++++++++++--- render2/render.h | 39 ++++++++++++++++++++++++++----- render2/surface.h | 2 ++ render2/texture.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ render2/texture.h | 36 +++++++++++++++++++++++++++++ 5 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 render2/texture.c create mode 100644 render2/texture.h diff --git a/render2/Makefile.am b/render2/Makefile.am index 88f86244..8f9c4d21 100644 --- a/render2/Makefile.am +++ b/render2/Makefile.am @@ -15,9 +15,21 @@ rendertest_LDFLAGS=-lobrender2 -L. rendertest_SOURCES=test.c lib_LTLIBRARIES=libobrender2.la -libobrender2_la_SOURCES=init.c instance.c color.c debug.c font.c surface.c - -noinst_HEADERS=render.h instance.h debug.h surface.h +libobrender2_la_SOURCES=\ + init.c \ + instance.c \ + color.c \ + debug.c \ + font.c \ + surface.c \ + texture.h + +noinst_HEADERS=\ + render.h \ + instance.h \ + debug.h \ + surface.h \ + texture.h MAINTAINERCLEANFILES=Makefile.in diff --git a/render2/render.h b/render2/render.h index 8c0611ca..90a5b56e 100644 --- a/render2/render.h +++ b/render2/render.h @@ -76,17 +76,12 @@ int RrFontMaxCharWidth(struct RrFont *font); /* surfaces */ struct RrSurface; -struct RrTexture; enum RrSurfaceType { RR_SURFACE_PLANAR, RR_SURFACE_NONPLANAR }; -enum RrTextureType { - RR_TEXTURE_FOO -}; - /*! The options available for the background of an RrSurface */ enum RrSurfaceColorType { /*! No rendering on the surface background, its contents will be @@ -133,6 +128,38 @@ struct RrSurface *RrSurfaceCopyChild(struct RrSurface *sur, void RrSurfaceFree(struct RrSurface *sur); Window RrSurfaceWindow(struct RrSurface *sur); -struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum); + +/* textures */ + +enum RrLayout { + RR_TOP_LEFT, + RR_TOP, + RR_TOP_RIGHT, + RR_LEFT, + RR_CENTER, + RR_RIGHT, + RR_BOTTOM_LEFT, + RR_BOTTOM, + RR_BOTTOM_RIGHT +}; + +#ifndef __LONG64 +typedef long RrData32; +#else +typedef int RrData32; +#endif + +void RrTextureSetRGBA(struct RrSurface *sur, + int texnum, + RrData32 *data, + int x, + int y, + int w, + int h); +void RrTextureSetText(struct RrSurface *sur, + int texnum, + struct RrFont *font, + enum RrLayout layout, + const char *text); #endif diff --git a/render2/surface.h b/render2/surface.h index 1a0ff756..9218b67c 100644 --- a/render2/surface.h +++ b/render2/surface.h @@ -42,4 +42,6 @@ struct RrSurface { int parenty; }; +struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum); + #endif diff --git a/render2/texture.c b/render2/texture.c new file mode 100644 index 00000000..d2b6da61 --- /dev/null +++ b/render2/texture.c @@ -0,0 +1,56 @@ +#include "texture.h" +#include "surface.h" + +void texture_free(struct RrTexture *tex) +{ + switch (tex->type) { + case RR_TEXTURE_NONE: + break; + case RR_TEXTURE_TEXT: + free(tex->data.text.string); + break; + case RR_TEXTUER_RGBA: + break; + } + tex->type = RR_TEXTURE_NONE; +} + +void RrTextureSetRGBA(struct RrSurface *sur, + int texnum, + RrData32 *data, + int x, + int y, + int w, + int h) +{ + struct RrTexture *tex = RrSurfaceTexture(sur, texnum); + + if (!tex) return; + texture_free(tex); + tex->type = RR_TEXTURE_RGBA; + tex->data.rgba.data = data; + tex->data.rgba.x = x; + tex->data.rgba.y = y; + tex->data.rgba.w = w; + tex->data.rgba.h = h; +} + +void RrTextureSetText(struct RrSurface *sur, + int texnum, + struct RrFont *font, + enum RrLayout layout, + const char *text) +{ + struct RrTexture *tex = RrSurfaceTexture(sur, texnum); + int l; + + if (!tex) return; + texture_free(tex); + tex->type = RR_TEXTURE_TEXT; + tex->data.text.font = font; + tex->data.text.layout = layout; + + l = strlen(text) + 1; + tex->data.text.string = malloc(l); + memcpy(tex->data.text.string, text, l); +} diff --git a/render2/texture.h b/render2/texture.h new file mode 100644 index 00000000..5415dbb5 --- /dev/null +++ b/render2/texture.h @@ -0,0 +1,36 @@ +#ifndef __render_texture_h +#define __render_texture_h + +#include "render.h" + +enum RrTextureType { + RR_TEXTURE_NONE, + RR_TEXTURE_TEXT, + RR_TEXTURE_RGBA +}; + +struct RrTextureText { + struct RrFont *font; + enum RrLayout layout; + char *string; +}; + +struct RrTextureRGBA { + RrData32 *data; + int x; + int y; + int w; + int h; +}; + +union RrTextureData { + struct RrTextureText text; + struct RrTextureRGBA rgba; +}; + +struct RrTexture { + enum RrTextureType type; + union RrTextureData data; +}; + +#endif -- 2.39.2