[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13327] branches/soc-2007-joeedh/source/ blender/blenkernel: Forgot to add some new files.
Joseph Eagar
joeedh at gmail.com
Mon Jan 21 09:34:18 CET 2008
Revision: 13327
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13327
Author: joeedh
Date: 2008-01-21 09:34:18 +0100 (Mon, 21 Jan 2008)
Log Message:
-----------
Forgot to add some new files.
Added Paths:
-----------
branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h
branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
Added: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h (rev 0)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h 2008-01-21 08:34:18 UTC (rev 13327)
@@ -0,0 +1,66 @@
+/**
+ * $Id: tcs_bucketbuffer.c 10648 2008-01-14 21:37:52Z joeedh $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2007 by the Blender Foundation.
+ *
+ * Contributor(s): Joseph Eagar
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#ifndef _BKE_BUCKETBUFFER_H
+#define _BKE_BUCKETBUFFER_H
+
+#include "BKE_tile.h"
+#include "BLI_memarena.h"
+
+#define MAX_BUCKETENTRY 256
+
+typedef struct RE_BucketEntry {
+ struct RE_BucketEntry *next;
+ int obi[MAX_BUCKETENTRY];
+ int nr[MAX_BUCKETENTRY];
+ int used;
+} RE_BucketEntry;
+
+typedef struct RE_BucketTile {
+ TCS_Tile tile;
+ int sizex, sizey, x, y;
+
+ RE_BucketEntry *ventries, *lastv; /*vlaks*/
+ RE_BucketEntry *sentries, *lasts; /*strands*/
+
+ /*total number of vlak/strand entry blocks.
+ important: these must be valid!*/
+ int totv, tots;
+} RE_BucketTile;
+
+typedef struct RE_BucketBuffer {
+ TCS_TileBuffer buffer;
+
+ /*tilex/y is number of tiles in each dimensions*/
+ int sizex, sizey, tilex, tiley;
+ int tsizex, tsizey, borderx, bordery;
+ RE_BucketTile *tilerect;
+} RE_BucketBuffer;
+
+void RE_Bucket_FreePool(void);
+RE_BucketBuffer *RE_Bucket_New(int sizex, int sizey, int tsizex, int tsizey);
+
+#endif /* _BKE_BUCKETBUFFER_H */
Added: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c (rev 0)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c 2008-01-21 08:34:18 UTC (rev 13327)
@@ -0,0 +1,287 @@
+/**
+ * $Id: tcs_bucketbuffer.c 10648 2008-01-14 21:37:52Z joeedh $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2007 by the Blender Foundation.
+ *
+ * Contributor(s): Joseph Eagar
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_memarena.h"
+
+#include "BKE_utildefines.h"
+#include "BKE_bucketbuffer.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern TCS_TileBuffer TCS_BucketBuffer;
+TCS_TilePool *re_bucket_pool = NULL;
+
+#define POOLMAXMEM 75*1024*1024
+
+RE_BucketBuffer *RE_Bucket_New(int sizex, int sizey, int tsizex, int tsizey) {
+ if (re_bucket_pool == NULL) re_bucket_pool = TCS_MakePool(POOLMAXMEM, "bucketpool");
+
+ return (RE_BucketBuffer*) TCS_MakeBuffer(re_bucket_pool, &TCS_BucketBuffer, tsizex, tsizey, sizex, sizey, NULL);
+}
+
+void RE_Bucket_FreePool(void)
+{
+ if (re_bucket_pool) {
+ TCS_FreePool(re_bucket_pool);
+ re_bucket_pool = NULL;
+ }
+}
+
+#define BUCKET_MAGICNUM ('B' | ('U' << 8) | ('C' << 16) | ('T' << 24)) //"BUCT"
+
+static RE_BucketEntry *bucket_loadentries(TCS_File *file, int *tot, RE_BucketEntry **lastentry)
+{
+ RE_BucketEntry *firstentry = NULL, *entry = NULL;
+ int a;
+
+ TCS_fread(tot, sizeof(int), 1, file);
+ for (a=0; a<*tot; a++) {
+ if (entry) {
+ entry->next = MEM_mallocN(sizeof(RE_BucketEntry), "RE_BucketEntry reloaded");
+ entry = entry->next;
+ //entry->next = NULL;
+ } else {
+ entry = firstentry = MEM_mallocN(sizeof(RE_BucketEntry), "RE_BucketEntry reloaded2");
+ //entry->next = NULL;
+ }
+ TCS_fread(entry, sizeof(RE_BucketEntry), 1, file);
+ }
+
+ *lastentry = entry;
+
+ return firstentry;
+}
+
+static void bucket_loadtile(TCS_Tile *tself, TCS_File *file)
+{
+ RE_BucketTile *self = (RE_BucketTile*) tself;
+ int tot;
+ unsigned int magic;
+
+ TCS_fread(&magic, sizeof(int), 1, file);
+ if (magic != BUCKET_MAGICNUM) {
+ printf("EVIL! Corrupted bucket tile data! id: %c%c%c%c", ((char*)&magic)[0], ((char*)&magic)[1], ((char*)&magic)[2], ((char*)&magic)[3]);
+ magic = BUCKET_MAGICNUM;
+ printf(", should be: %c%c%c%c\n", ((char*)&magic)[0], ((char*)&magic)[1], ((char*)&magic)[2], ((char*)&magic)[3]);
+ return;
+ }
+
+ self->ventries = bucket_loadentries(file, &tot, &self->lastv);
+ self->totv = tot;
+ self->sentries = bucket_loadentries(file, &tot, &self->lasts);
+ self->tots = tot;
+}
+
+
+static unsigned int bucket_savetile(struct TCS_Tile *tself, TCS_File *file, unsigned long curpos)
+{
+ RE_BucketTile *self = (RE_BucketTile*) tself;
+ RE_BucketEntry *entry, *enext;
+ int num, tot;
+
+ BASSERT(tself);
+ BASSERT(file);
+
+ num = BUCKET_MAGICNUM;
+ TCS_fwrite(&num, sizeof(int), 1, file);
+
+ tot = self->totv;
+ TCS_fwrite(&tot, sizeof(int), 1, file);
+
+ for (entry=self->ventries; entry; entry=enext) {
+ enext = entry->next;
+ TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file);
+ tot++;
+
+ MEM_freeN(entry);
+ }
+
+ tot = self->tots;
+ TCS_fwrite(&tot, sizeof(int), 1, file);
+
+ for (entry=self->sentries; entry; entry=enext) {
+ enext = entry->next;
+ TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file);
+ tot++;
+
+ MEM_freeN(entry);
+ }
+
+ BASSERT(file->error_occured == 0);
+
+ self->ventries = self->sentries = self->lastv = self->lasts = NULL;
+
+ return TCS_ftell(file) - curpos;
+}
+
+unsigned int bucket_gettilelen(TCS_Tile *tself)
+{
+ RE_BucketTile *self = (RE_BucketTile*) tself;
+
+ /*int*3 is for magic number int, total vlakren int, and total strand int.*/
+ return sizeof(int)*3 + sizeof(RE_BucketEntry)*(self->totv+self->tots);
+}
+
+static TCS_TileType _bucket_tile_type = {
+ bucket_loadtile,
+ bucket_savetile,
+ bucket_gettilelen,
+};
+
+static void bucket_freebuffer(TCS_TileBuffer *self)
+{
+ RE_BucketBuffer *buf = (RE_BucketBuffer*) self;
+ RE_BucketTile *tile;
+ RE_BucketEntry *entry, *next;
+ int x, y;
+
+ for (x=0; x<buf->tilex; x++) {
+ for (y=0; y<buf->tiley; y++) {
+ tile = &buf->tilerect[y*buf->tilex+x];
+
+ /*we don't use the BLI stuff since we're dealing
+ with a singly-linked list, not a doubly-linked list*/
+ for (entry=tile->ventries; entry; entry=next) {
+ next = entry->next;
+ MEM_freeN(entry);
+ }
+ for (entry=tile->sentries; entry; entry=next) {
+ next = entry->next;
+ MEM_freeN(entry);
+ }
+ }
+ }
+ MEM_freeN(buf->tilerect);
+}
+
+int bucket_getTileSizeX(struct TCS_TileBuffer *self)
+{
+ RE_BucketBuffer *buf = (RE_BucketBuffer*) self;
+ return buf->tsizex;
+}
+
+int bucket_getTileSizeY(struct TCS_TileBuffer *self)
+{
+ RE_BucketBuffer *buf = (RE_BucketBuffer*) self;
+ return buf->tsizey;
+}
+
+int bucket_getSizeX(struct TCS_TileBuffer *self)
+{
+ RE_BucketBuffer *buf = (RE_BucketBuffer*) self;
+ return buf->sizex;
+}
+
+int bucket_getSizeY(struct TCS_TileBuffer *self)
+{
+ RE_BucketBuffer *buf = (RE_BucketBuffer*) self;
+ return buf->sizey;
+}
+
+static void *bucket_gettile(TCS_TileBuffer *tself, int x, int y, int z)
+{
+ RE_BucketBuffer *buf = (RE_BucketBuffer*) tself;
+
+ return &buf->tilerect[y*buf->tilex+x];
+}
+
+/*I'll just not fill in this function, since I don't see any particular reason to*/
+static struct TCS_TileBuffer *bucket_newbuffer(TCS_TilePool *pool, int tsizex, int tsizey, int sizex, int sizey, void *data)
+{
+ RE_BucketBuffer *buf = MEM_callocN(sizeof(RE_BucketBuffer), "RE_BucketBuf");
+ RE_BucketTile *tile;
+ int tilex = sizex/tsizex, tiley = sizey/tsizey;
+ int x, y;
+ float fac;
+
+ buf->tsizex = tsizex;
+ buf->tsizey = tsizey;
+ buf->sizex = sizex;
+ buf->sizey = sizey;
+
+ /*test if we need to add extra tiles along the x axix*/
+ fac = ((float)sizex/(float)tsizex) + 0.0000001;
+
+ if ((int)((fac - (int)fac)*(float)tsizex) > 0.000001) {
+ tilex += 1;
+ }
+
+ /*test if we need to add extra tiles along the y axix*/
+ fac = ((float)sizey/(float)tsizey) + 0.0000001;
+
+ if ((int)((fac - (int)fac)*(float)tsizey) > 0.000001) {
+ tiley += 1;
+ }
+
+ buf->tilex = tilex;
+ buf->tiley = tiley;
+
+ buf->tilerect = MEM_callocN(sizeof(RE_BucketTile)*tilex*tiley, "RE_BucketTile buf");
+
+ TCS_InitBuffer(&TCS_BucketBuffer, buf);
+
+ for (x=0; x<buf->tilex; x++) {
+ for (y=0; y<buf->tiley; y++) {
+ tile = &buf->tilerect[y*buf->tilex+x];
+ tile->tile.type = &_bucket_tile_type;
+ tile->tile.struct_overhead = sizeof(RE_BucketTile);
+ tile->tile.buffer = (TCS_TileBuffer*) buf;
+ tile->x = x;
+ tile->y = y;
+
+ /*right and top border tiles arn't always the same size as the others*/
+ if (x == tilex-1) tile->sizex = sizex - tsizex*x;
+ else tile->sizex = tsizex;
+
+ if (y == tiley-1) tile->sizey = sizey - tsizey*y;
+ else tile->sizey = tsizey;
+
+ TCS_AddToPool(pool, tile);
+ }
+ }
+
+ return (TCS_TileBuffer*) buf;
+}
+
+TCS_TileBuffer TCS_BucketBuffer = {
+ NULL, NULL,
+ bucket_newbuffer,
+ bucket_freebuffer,
+ bucket_gettile,
+ bucket_getTileSizeX,
+ bucket_getTileSizeY,
+ bucket_getSizeX,
+ bucket_getSizeY,
+ TCS_READONLY,
+ NULL
+};
More information about the Bf-blender-cvs
mailing list