X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=flavors%2Fgl%2Fsource%2Fbufferstate.cpp;h=467fb932b0c4573951b3bcc7d2893b54b046c4c7;hb=a34325fadec5b2be003bf9af1f081bfc4c83e8b6;hp=356e82b5ac3de9469b748338d852956f010bb808;hpb=f53057ce9b5eb3c7256a4aca95b4944733e14503;p=gldbg.git diff --git a/flavors/gl/source/bufferstate.cpp b/flavors/gl/source/bufferstate.cpp index 356e82b..467fb93 100644 --- a/flavors/gl/source/bufferstate.cpp +++ b/flavors/gl/source/bufferstate.cpp @@ -1,17 +1,10 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - -#include +#include "arraysize.h" #include "arraystate.h" #include "bufferstate.h" #include "enums.h" +#include "strformat.h" using namespace std; -using namespace Msp; BufferContent::BufferContent(): consistent(true), @@ -51,6 +44,27 @@ void BufferContent::update(const ArrayState &array) arrays.insert(place, array); } +void BufferContent::update_elements(GLenum type) +{ + if(arrays.empty()) + { + Array array; + array.kind = GL_ELEMENT_ARRAY_BUFFER; + array.type = type; + arrays.push_back(array); + stride = typesize(type); + } + else if(arrays.size()>1 || arrays.front().kind!=GL_ELEMENT_ARRAY_BUFFER) + consistent = false; + else + { + if(arrays.front().type!=type) + consistent = false; + arrays.front().type = type; + stride = typesize(type); + } +} + string BufferContent::describe() const { if(arrays.empty()) @@ -68,6 +82,8 @@ string BufferContent::describe() const kind = 'C'; else if(i->kind==GL_TEXTURE_COORD_ARRAY && i->index==0) kind = 'T'; + else if(i->kind==GL_ELEMENT_ARRAY_BUFFER) + kind = 'E'; char type[3] = { '?', 0, 0 }; if(i->type==GL_FLOAT) @@ -89,13 +105,21 @@ string BufferContent::describe() const if(!result.empty()) result += '_'; - result += format("%c%d%s", kind, i->size, type); + result += strformat("%c%d%s", kind, i->size, type); } return result; } +BufferContent::Array::Array(): + kind(GL_NONE), + index(0), + size(1), + type(GL_NONE), + offset(0) +{ } + BufferContent::Array::Array(const ArrayState &a): kind(a.kind), index(a.index), @@ -106,11 +130,18 @@ BufferContent::Array::Array(const ArrayState &a): BufferState::BufferState(): + id(0), + target(0), usage(GL_STATIC_DRAW), size(0), data(0) { } +BufferState::~BufferState() +{ + delete[] data; +} + void BufferState::set_data(unsigned sz, const void *ptr, GLenum use) { usage = use; @@ -134,8 +165,18 @@ void BufferState::set_sub_data(unsigned off, unsigned sz, const void *ptr) string BufferState::describe() const { if(content.stride) - return format("%s, %d vertices (%d bytes), %s", - content.describe(), size/content.stride, size, describe_enum(usage, "")); + { + const char *what = (content.arrays.front().kind==GL_ELEMENT_ARRAY_BUFFER ? "indices" : "vertices"); + return content.describe()+strformat(", %d %s (%d bytes), %s", + size/content.stride, what, size, describe_enum(usage, "")); + } else - return format("%d bytes, %s", size, describe_enum(usage, "")); + return strformat("%d bytes, %s", size, describe_enum(usage, "")); } + + +BufferBindingState::BufferBindingState(): + buffer(0), + offset(0), + size(0) +{ }