GlFunction(Void, "glClearColorIuiEXT", [(GLuint, "red"), (GLuint, "green"), (GLuint, "blue"), (GLuint, "alpha")]),
# GL_GREMEDY_frame_terminator
- GlFunction(Void, "glFrameTerminatorGREMEDY", [], sideeffects=False),
+ GlFunction(Void, "glFrameTerminatorGREMEDY", []),
# GL_NV_conditional_render
GlFunction(Void, "glBeginConditionalRenderNV", [(GLuint, "id"), (GLenum, "mode")]),
("glGet", I, 1, "GL_MAP1_GRID_SEGMENTS"), # 0x0DD1
("glGet", F, 4, "GL_MAP2_GRID_DOMAIN"), # 0x0DD2
("glGet", I, 2, "GL_MAP2_GRID_SEGMENTS"), # 0x0DD3
- ("glGet", B, 1, "GL_TEXTURE_1D"), # 0x0DE0
- ("glGet", B, 1, "GL_TEXTURE_2D"), # 0x0DE1
+ ("_glGet", B, 1, "GL_TEXTURE_1D"), # 0x0DE0
+ ("_glGet", B, 1, "GL_TEXTURE_2D"), # 0x0DE1
("glGet", P, 1, "GL_FEEDBACK_BUFFER_POINTER"), # 0x0DF0
("glGet", I, 1, "GL_FEEDBACK_BUFFER_SIZE"), # 0x0DF1
("glGet", E, 1, "GL_FEEDBACK_BUFFER_TYPE"), # 0x0DF2
("", X, 1, "GL_TEXTURE_TOO_LARGE_EXT"), # 0x8065
("glGetTexParameter", F, 1, "GL_TEXTURE_PRIORITY"), # 0x8066
("glGetTexParameter", B, 1, "GL_TEXTURE_RESIDENT"), # 0x8067
- ("glGet", I, 1, "GL_TEXTURE_BINDING_1D"), # 0x8068
- ("glGet", I, 1, "GL_TEXTURE_BINDING_2D"), # 0x8069
- ("glGet", I, 1, "GL_TEXTURE_BINDING_3D"), # 0x806A
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_1D"), # 0x8068
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_2D"), # 0x8069
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_3D"), # 0x806A
("glGet", I, 1, "GL_PACK_SKIP_IMAGES"), # 0x806B
("glGet", F, 1, "GL_PACK_IMAGE_HEIGHT"), # 0x806C
("glGet", I, 1, "GL_UNPACK_SKIP_IMAGES"), # 0x806D
("", X, 1, "GL_ALL_COMPLETED_NV"), # 0x84F2
("", X, 1, "GL_FENCE_STATUS_NV"), # 0x84F3
("", X, 1, "GL_FENCE_CONDITION_NV"), # 0x84F4
- ("glGet", B, 1, "GL_TEXTURE_RECTANGLE"), # 0x84F5
- ("glGet", I, 1, "GL_TEXTURE_BINDING_RECTANGLE"), # 0x84F6
+ ("_glGet", B, 1, "GL_TEXTURE_RECTANGLE"), # 0x84F5
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_RECTANGLE"), # 0x84F6
("", X, 1, "GL_PROXY_TEXTURE_RECTANGLE"), # 0x84F7
("glGet", I, 1, "GL_MAX_RECTANGLE_TEXTURE_SIZE"), # 0x84F8
("", X, 1, "GL_DEPTH_STENCIL"), # 0x84F9
("", X, 1, "GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT"), # 0x8510
("", X, 1, "GL_NORMAL_MAP"), # 0x8511
("", X, 1, "GL_REFLECTION_MAP"), # 0x8512
- ("glGet", B, 1, "GL_TEXTURE_CUBE_MAP"), # 0x8513
- ("glGet", I, 1, "GL_TEXTURE_BINDING_CUBE_MAP"), # 0x8514
+ ("_glGet", B, 1, "GL_TEXTURE_CUBE_MAP"), # 0x8513
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_CUBE_MAP"), # 0x8514
("", X, 1, "GL_TEXTURE_CUBE_MAP_POSITIVE_X"), # 0x8515
("", X, 1, "GL_TEXTURE_CUBE_MAP_NEGATIVE_X"), # 0x8516
("", X, 1, "GL_TEXTURE_CUBE_MAP_POSITIVE_Y"), # 0x8517
("", X, 1, "GL_PROXY_TEXTURE_1D_ARRAY"), # 0x8C19
("", X, 1, "GL_TEXTURE_2D_ARRAY"), # 0x8C1A
("", X, 1, "GL_PROXY_TEXTURE_2D_ARRAY"), # 0x8C1B
- ("glGet", I, 1, "GL_TEXTURE_BINDING_1D_ARRAY"), # 0x8C1C
- ("glGet", I, 1, "GL_TEXTURE_BINDING_2D_ARRAY"), # 0x8C1D
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_1D_ARRAY"), # 0x8C1C
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_2D_ARRAY"), # 0x8C1D
("", X, 1, "GL_GEOMETRY_PROGRAM_NV"), # 0x8C26
("", X, 1, "GL_MAX_PROGRAM_OUTPUT_VERTICES_NV"), # 0x8C27
("", X, 1, "GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV"), # 0x8C28
("", X, 1, "GL_DISCRETE_AMD"), # 0x9006
("", X, 1, "GL_CONTINUOUS_AMD"), # 0x9007
("", X, 1, "GL_TEXTURE_CUBE_MAP_ARRAY"), # 0x9009
- ("glGet", I, 1, "GL_TEXTURE_BINDING_CUBE_MAP_ARRAY"), # 0x900A
+ ("_glGet", I, 1, "GL_TEXTURE_BINDING_CUBE_MAP_ARRAY"), # 0x900A
("", X, 1, "GL_PROXY_TEXTURE_CUBE_MAP_ARRAY"), # 0x900B
("", X, 1, "GL_SAMPLER_CUBE_MAP_ARRAY"), # 0x900C
("", X, 1, "GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW"), # 0x900D
print ' GLint __pack_buffer = 0;'
print ' glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &__pack_buffer);'
print ' if (!__pack_buffer) {'
+ if function.name == 'glReadPixels':
+ print ' glFinish();'
+ print ' if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAME ||'
+ print ' glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {'
+ print ' glretrace::snapshot(call.no);'
+ print ' }'
print ' return;'
print ' }'
print ' if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {'
print ' glretrace::snapshot(call.no - 1);'
print ' }'
+ if function.name == 'glFrameTerminatorGREMEDY':
+ print ' glretrace::frame_complete(call.no);'
+ return
Retracer.retrace_function_body(self, function)
print ' if (!glretrace::double_buffer) {'
print ' glretrace::frame_complete(call.no);'
print ' }'
- if function.name == 'glReadPixels':
- print ' glFinish();'
- print ' if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAME ||'
- print ' glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {'
- print ' glretrace::snapshot(call.no);'
- print ' }'
if is_draw_array or is_draw_elements or is_misc_draw:
print ' if (glretrace::snapshot_frequency == glretrace::FREQUENCY_DRAW) {'
print ' glretrace::snapshot(call.no);'
json.beginMember("__data__");
char *pngBuffer;
int pngBufferSize;
- Image::writePixelsToBuffer(pixels, width, height, 4, false, &pngBuffer, &pngBufferSize);
+ Image::writePixelsToBuffer(pixels, width, height, 4, true, &pngBuffer, &pngBufferSize);
json.writeBase64(pngBuffer, pngBufferSize);
free(pngBuffer);
json.endMember(); // __data__
json.beginMember("__data__");
char *pngBuffer;
int pngBufferSize;
- Image::writePixelsToBuffer(pixels, width, height, channels, false, &pngBuffer, &pngBufferSize);
+ Image::writePixelsToBuffer(pixels, width, height, channels, true, &pngBuffer, &pngBufferSize);
//std::cerr <<" Before = "<<(width * height * channels * sizeof *pixels)
// <<", after = "<<pngBufferSize << ", ratio = " << double(width * height * channels * sizeof *pixels)/pngBufferSize;
json.writeBase64(pngBuffer, pngBufferSize);
print ' json.beginMember(name);'
print ' glActiveTexture(GL_TEXTURE0 + unit);'
print ' json.beginObject();'
- print ' GLint texture;'
+ print ' GLboolean enabled;'
+ print ' GLint binding;'
print
for target, binding in texture_targets:
print ' // %s' % target
- print ' texture = 0;'
- print ' glGetIntegerv(%s, &texture);' % binding
- print ' if (glIsEnabled(%s) || texture) {' % target
+ print ' enabled = GL_FALSE;'
+ print ' glGetBooleanv(%s, &enabled);' % target
+ print ' json.writeBoolMember("%s", enabled);' % target
+ print ' binding = 0;'
+ print ' glGetIntegerv(%s, &binding);' % binding
+ print ' json.writeNumberMember("%s", binding);' % binding
+ print ' if (enabled || binding) {'
print ' json.beginMember("%s");' % target
print ' json.beginObject();'
self.dump_atoms(glGetTexParameter, target)
{
QByteArray dataArray = QByteArray::fromBase64(base64);
m_image.loadFromData(dataArray, "png");
- m_image = m_image.mirrored();
m_thumb = m_image.scaled(64, 64, Qt::KeepAspectRatio);
}
// it's just a bunch of Delete calls for every object
// after the last SwapBuffers
if (currentFrame) {
+ if (!frames.count()) {
+ calls.squeeze();
+ currentFrame->setCalls(calls, binaryDataSize);
+ }
frames.append(currentFrame);
currentFrame = 0;
}
return m_gzFile != NULL;
}
-bool ZLibFile::rawWrite(const void *buffer, int length)
+bool ZLibFile::rawWrite(const void *buffer, size_t length)
{
return gzwrite(m_gzFile, buffer, length) != -1;
}
-bool ZLibFile::rawRead(void *buffer, int length)
+bool ZLibFile::rawRead(void *buffer, size_t length)
{
return gzread(m_gzFile, buffer, length) != -1;
}
std::string filename() const;
bool open(const std::string &filename, File::Mode mode);
- bool write(const void *buffer, int length);
- bool read(void *buffer, int length);
+ bool write(const void *buffer, size_t length);
+ bool read(void *buffer, size_t length);
void close();
void flush(void);
int getc();
virtual void setCurrentOffset(const File::Offset &offset);
protected:
virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0;
- virtual bool rawWrite(const void *buffer, int length) = 0;
- virtual bool rawRead(void *buffer, int length) = 0;
+ virtual bool rawWrite(const void *buffer, size_t length) = 0;
+ virtual bool rawRead(void *buffer, size_t length) = 0;
virtual int rawGetc() = 0;
virtual void rawClose() = 0;
virtual void rawFlush() = 0;
return m_isOpened;
}
-inline bool File::write(const void *buffer, int length)
+inline bool File::write(const void *buffer, size_t length)
{
if (!m_isOpened || m_mode != File::Write) {
return false;
return rawWrite(buffer, length);
}
-inline bool File::read(void *buffer, int length)
+inline bool File::read(void *buffer, size_t length)
{
if (!m_isOpened || m_mode != File::Read) {
return false;
virtual bool supportsOffsets() const;
protected:
virtual bool rawOpen(const std::string &filename, File::Mode mode);
- virtual bool rawWrite(const void *buffer, int length);
- virtual bool rawRead(void *buffer, int length);
+ virtual bool rawWrite(const void *buffer, size_t length);
+ virtual bool rawRead(void *buffer, size_t length);
virtual int rawGetc();
virtual void rawClose();
virtual void rawFlush();
* The file is composed of a number of chunks, they are:
* chunk {
* uint32 - specifying the length of the compressed data
- * compressed data
+ * compressed data, in little endian
* }
* File can contain any number of such chunks.
* The default size of an uncompressed chunk is specified in
SnappyFile::~SnappyFile()
{
delete [] m_compressedCache;
+ delete [] m_cache;
}
bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
return m_stream.is_open();
}
-bool SnappyFile::rawWrite(const void *buffer, int length)
+bool SnappyFile::rawWrite(const void *buffer, size_t length)
{
if (freeCacheSize() > length) {
memcpy(m_cachePtr, buffer, length);
while (sizeToWrite >= freeCacheSize()) {
int endSize = freeCacheSize();
int offset = length - sizeToWrite;
- memcpy(m_cachePtr, (char*)buffer + offset, endSize);
+ memcpy(m_cachePtr, (const char*)buffer + offset, endSize);
sizeToWrite -= endSize;
m_cachePtr += endSize;
flushCache();
}
if (sizeToWrite) {
int offset = length - sizeToWrite;
- memcpy(m_cachePtr, (char*)buffer + offset, sizeToWrite);
+ memcpy(m_cachePtr, (const char*)buffer + offset, sizeToWrite);
m_cachePtr += sizeToWrite;
}
}
return true;
}
-bool SnappyFile::rawRead(void *buffer, int length)
+bool SnappyFile::rawRead(void *buffer, size_t length)
{
if (endOfData()) {
return false;
memcpy(buffer, m_cachePtr, length);
m_cachePtr += length;
} else {
- int sizeToRead = length;
- int offset = 0;
+ size_t sizeToRead = length;
+ size_t offset = 0;
while (sizeToRead) {
- int chunkSize = std::min(freeCacheSize(), sizeToRead);
+ size_t chunkSize = std::min(freeCacheSize(), sizeToRead);
offset = length - sizeToRead;
memcpy((char*)buffer + offset, m_cachePtr, chunkSize);
m_cachePtr += chunkSize;
void SnappyFile::flushCache()
{
if (m_mode == File::Write) {
- size_t compressedLength;
+ size_t inputLength = usedCacheSize();
- ::snappy::RawCompress(m_cache, SNAPPY_CHUNK_SIZE - freeCacheSize(),
- m_compressedCache, &compressedLength);
+ if (inputLength) {
+ size_t compressedLength;
- writeCompressedLength(compressedLength);
- m_stream.write(m_compressedCache, compressedLength);
- m_cachePtr = m_cache;
+ ::snappy::RawCompress(m_cache, inputLength,
+ m_compressedCache, &compressedLength);
+
+ writeCompressedLength(compressedLength);
+ m_stream.write(m_compressedCache, compressedLength);
+ m_cachePtr = m_cache;
+ }
+ assert(m_cachePtr == m_cache);
} else if (m_mode == File::Read) {
- if (m_stream.eof())
- return;
//assert(m_cachePtr == m_cache + m_cacheSize);
m_currentOffset.chunk = m_stream.tellg();
size_t compressedLength;
compressedLength = readCompressedLength();
- m_stream.read((char*)m_compressedCache, compressedLength);
- /*
- * The reason we peek here is because the last read will
- * read all the way until the last character, but that will not
- * trigger m_stream.eof() to be set, so by calling peek
- * we assure that if we in fact have read the entire stream
- * then the m_stream.eof() is always set.
- */
- m_stream.peek();
- ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
- &m_cacheSize);
- if (m_cache)
- delete [] m_cache;
- createCache(m_cacheSize);
- ::snappy::RawUncompress(m_compressedCache, compressedLength,
- m_cache);
+
+ if (compressedLength) {
+ m_stream.read((char*)m_compressedCache, compressedLength);
+ ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
+ &m_cacheSize);
+ createCache(m_cacheSize);
+ ::snappy::RawUncompress(m_compressedCache, compressedLength,
+ m_cache);
+ } else {
+ createCache(0);
+ }
}
}
void SnappyFile::createCache(size_t size)
{
- m_cache = new char[size];
+ // TODO: only re-allocate if the current buffer is not big enough
+
+ if (m_cache) {
+ delete [] m_cache;
+ }
+
+ if (size) {
+ m_cache = new char[size];
+ } else {
+ m_cache = NULL;
+ }
+
m_cachePtr = m_cache;
m_cacheSize = size;
}
-void SnappyFile::writeCompressedLength(uint32_t value)
+void SnappyFile::writeCompressedLength(size_t length)
{
- m_stream.write((const char*)&value, sizeof value);
+ unsigned char buf[4];
+ buf[0] = length & 0xff; length >>= 8;
+ buf[1] = length & 0xff; length >>= 8;
+ buf[2] = length & 0xff; length >>= 8;
+ buf[3] = length & 0xff; length >>= 8;
+ assert(length == 0);
+ m_stream.write((const char *)buf, sizeof buf);
}
-uint32_t SnappyFile::readCompressedLength()
+size_t SnappyFile::readCompressedLength()
{
- uint32_t len;
- m_stream.read((char*)&len, sizeof len);
- return len;
+ unsigned char buf[4];
+ size_t length;
+ m_stream.read((char *)buf, sizeof buf);
+ if (m_stream.fail()) {
+ length = 0;
+ } else {
+ length = (size_t)buf[0];
+ length |= ((size_t)buf[1] << 8);
+ length |= ((size_t)buf[2] << 16);
+ length |= ((size_t)buf[3] << 24);
+ }
+ return length;
}
bool SnappyFile::supportsOffsets() const
#ifndef TRACE_SNAPPYFILE_HPP
#define TRACE_SNAPPYFILE_HPP
+#include <assert.h>
+
#include "trace_file.hpp"
#include <string>
#include <fstream>
-#include <stdint.h>
-
namespace snappy {
class File;
}
virtual void setCurrentOffset(const File::Offset &offset);
protected:
virtual bool rawOpen(const std::string &filename, File::Mode mode);
- virtual bool rawWrite(const void *buffer, int length);
- virtual bool rawRead(void *buffer, int length);
+ virtual bool rawWrite(const void *buffer, size_t length);
+ virtual bool rawRead(void *buffer, size_t length);
virtual int rawGetc();
virtual void rawClose();
virtual void rawFlush();
virtual bool rawSkip(unsigned length);
private:
- inline int freeCacheSize() const
+ inline size_t usedCacheSize() const
+ {
+ assert(m_cachePtr >= m_cache);
+ return m_cachePtr - m_cache;
+ }
+ inline size_t freeCacheSize() const
{
- if (m_cacheSize > 0)
- return m_cacheSize - (m_cachePtr - m_cache);
- else
+ assert(m_cacheSize >= usedCacheSize());
+ if (m_cacheSize > 0) {
+ return m_cacheSize - usedCacheSize();
+ } else {
return 0;
+ }
}
inline bool endOfData() const
{
}
void flushCache();
void createCache(size_t size);
- void writeCompressedLength(uint32_t num);
- uint32_t readCompressedLength();
+ void writeCompressedLength(size_t length);
+ size_t readCompressedLength();
private:
std::fstream m_stream;
char *m_cache;