Example #1
0
/// Add vertex to buffers
static void addVertex(OglCanvas *c, GLfloat x, GLfloat y, 
        GLfloat r, GLfloat g, GLfloat b, GLfloat a,
        GLfloat u, GLfloat v)
{
    reserveSpace(c, 1);

    Vector rv = c->transform.back() * Vector(x, y);
    x = rv.getX();
    y = rv.getY();

    int i = c->numVertices * 2;
    c->vertexBuffer[i] = x;
    c->vertexBuffer[i + 1] = y;

    c->texBuffer[i] = u;
    c->texBuffer[i + 1] = v;

    i = c->numVertices * 4;
    c->colorBuffer[i] = r;
    c->colorBuffer[i + 1] = g;
    c->colorBuffer[i + 2] = b;
    c->colorBuffer[i + 3] = a;
 
    c->numVertices++;
}
Example #2
0
bool VertexBufferInterface::storeRawData(const void* data, unsigned int size, unsigned int *outStreamOffset)
{
    if (mWritePosition + size < mWritePosition)
    {
        return false;
    }

    if (!reserveSpace(mReservedSpace))
    {
        return false;
    }
    mReservedSpace = 0;

    if (!mVertexBuffer->storeRawData(data, size, mWritePosition))
    {
        return false;
    }

    if (outStreamOffset)
    {
        *outStreamOffset = mWritePosition;
    }

    mWritePosition += size;

    return true;
}
Example #3
0
gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
                                                       GLenum currentValueType,
                                                       GLint start,
                                                       GLsizei count,
                                                       GLsizei instances,
                                                       unsigned int *outStreamOffset,
                                                       const uint8_t *sourceData)
{
    gl::Error error(GL_NO_ERROR);

    unsigned int spaceRequired;
    error = mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired);
    if (error.isError())
    {
        return error;
    }

    // Align to 16-byte boundary
    unsigned int alignedSpaceRequired = roundUp(spaceRequired, 16u);

    // Protect against integer overflow
    if (!IsUnsignedAdditionSafe(mWritePosition, alignedSpaceRequired) ||
        alignedSpaceRequired < spaceRequired)
    {
        return gl::Error(GL_OUT_OF_MEMORY, "Internal error, new vertex buffer write position would overflow.");
    }

    error = reserveSpace(mReservedSpace);
    if (error.isError())
    {
        return error;
    }
    mReservedSpace = 0;

    error = mVertexBuffer->storeVertexAttributes(attrib, currentValueType, start, count, instances, mWritePosition, sourceData);
    if (error.isError())
    {
        return error;
    }

    if (outStreamOffset)
    {
        *outStreamOffset = mWritePosition;
    }

    mWritePosition += alignedSpaceRequired;

    return gl::Error(GL_NO_ERROR);
}
int VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances)
{
    if (!reserveSpace(mReservedSpace))
    {
        return -1;
    }
    mReservedSpace = 0;

    if (!mVertexBuffer->storeVertexAttributes(attrib, start, count, instances, mWritePosition))
    {
        return -1;
    }

    int oldWritePos = static_cast<int>(mWritePosition);
    mWritePosition += mVertexBuffer->getSpaceRequired(attrib, count, instances);

    return oldWritePos;
}
int VertexBufferInterface::storeRawData(const void* data, unsigned int size)
{
    if (!reserveSpace(mReservedSpace))
    {
        return -1;
    }
    mReservedSpace = 0;

    if (!mVertexBuffer->storeRawData(data, size, mWritePosition))
    {
        return -1;
    }

    int oldWritePos = static_cast<int>(mWritePosition);
    mWritePosition += size;

    return oldWritePos;
}
Example #6
0
gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
                                                       GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{
    gl::Error error(GL_NO_ERROR);

    unsigned int spaceRequired;
    error = mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired);
    if (error.isError())
    {
        return error;
    }

    if (mWritePosition + spaceRequired < mWritePosition)
    {
        return gl::Error(GL_OUT_OF_MEMORY, "Internal error, new vertex buffer write position would overflow.");
    }

    error = reserveSpace(mReservedSpace);
    if (error.isError())
    {
        return error;
    }
    mReservedSpace = 0;

    error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition);
    if (error.isError())
    {
        return error;
    }

    if (outStreamOffset)
    {
        *outStreamOffset = mWritePosition;
    }

    mWritePosition += spaceRequired;

    // Align to 16-byte boundary
    mWritePosition = roundUp(mWritePosition, 16u);

    return gl::Error(GL_NO_ERROR);
}
Example #7
0
bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,  GLint start, GLsizei count, GLsizei instances,
                                                  unsigned int *outStreamOffset)
{
    unsigned int spaceRequired;
    if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired))
    {
        return false;
    }

    // Align to 16-byte boundary
    unsigned int alignedSpaceRequired = roundUp(spaceRequired, 16);

    // Protect against integer overflow
    if ((mWritePosition + alignedSpaceRequired < mWritePosition) ||
        alignedSpaceRequired < spaceRequired)
    {
        return false;
    }

    if (!reserveSpace(mReservedSpace))
    {
        return false;
    }
    mReservedSpace = 0;

    if (!mVertexBuffer->storeVertexAttributes(attrib, start, count, instances, mWritePosition))
    {
        return false;
    }

    if (outStreamOffset)
    {
        *outStreamOffset = mWritePosition;
    }

    mWritePosition += alignedSpaceRequired;

    return true;
}
Example #8
0
bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
                                                  GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{
    unsigned int spaceRequired;
    if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired))
    {
        return false;
    }

    if (mWritePosition + spaceRequired < mWritePosition)
    {
        return false;
    }

    if (!reserveSpace(mReservedSpace))
    {
        return false;
    }
    mReservedSpace = 0;

    if (!mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition))
    {
        return false;
    }

    if (outStreamOffset)
    {
        *outStreamOffset = mWritePosition;
    }

    mWritePosition += spaceRequired;

    // Align to 16-byte boundary
    mWritePosition = rx::roundUp(mWritePosition, 16u);

    return true;
}
void 
GlyphMemCache::reserveGlyphs(UInt16 numGlyphs, UInt32 memSize, Boolean *purged) {
  reserveSpace(numGlyphs, memSize, purged);
}
Example #10
0
eMesh::eMesh(Type type, eU32 primitiveCount, eU32 vertexCount) :
    m_type(type)
{
    reserveSpace(primitiveCount, vertexCount);
}
Example #11
0
void eMesh::_fromTriangleEditMesh(eEditMesh &em)
{
    ePROFILER_ZONE("To renderable mesh");
	eASSERT(em.isTriangulated() == eTRUE);

    clear();
    reserveSpace(em.getFaceCount(), em.getFaceCount()*3); 
	m_bbox = em.getBoundingBox();

	for(eU32 i = 0; i < em.getVertexCount(); i++)
    {
		em.getVertex(i)->_volatile_attribute1 = (ePtr)-1;
    }

    eArray<eU32> indices;

    for (eU32 i=0; i<em.getFaceCount(); i++)
    {
        const eEditMesh::Face *face = em.getFace(i);
        eASSERT(face != eNULL);

        const eMaterial *mat = face->material;
        eASSERT(mat != eNULL);

        indices.clear();
        eEditMesh::HalfEdge *he = face->he;

        do
        {
            eEditMesh::Vertex *vtx = he->origin;
            eASSERT(vtx != eNULL);

            const eVector3 &normal = (mat->getFlatShaded() ? face->normal : vtx->normal);

            // Check if vertices have to be duplicated.
            if (!he->texCoord.equals(vtx->texCoord))
            {
                // Yes, so add new vertex.
                addVertex(vtx->position, normal, he->texCoord, vtx->color);
                indices.append(m_vertices.size()-1);
            }
            else if (mat->getFlatShaded())
            {
                addVertex(vtx->position, normal, vtx->texCoord, vtx->color);
                indices.append(m_vertices.size()-1);
            }
            // With flat shading every vertex has to be duplicated,
            // because vertices can't share normals anymore.
            else if (vtx->_volatile_attribute1 == (ePtr)-1)
            {
                // No and vertex was not added yet.
                addVertex(vtx->position, normal, vtx->texCoord, vtx->color);
                indices.append(m_vertices.size()-1);
                vtx->_volatile_attribute1 = (ePtr)(m_vertices.size()-1);
            }
            else
            {
                // Yes and vertex was already added before.
                indices.append((eU32)vtx->_volatile_attribute1);
            }
            he = he->next;
        }
        while (he != face->he);

        // Add triangle to mesh.
        addTriangle(indices[0], indices[1], indices[2], mat);
    }
}
Example #12
0
File: heap.c Project: fmccabe/cafe
retCode enoughRoom(heapPo H, labelPo lbl) {
  return reserveSpace(H, NormalCellCount(labelArity(lbl)));
}
Example #13
0
int saveUndo (git_sint32 * base, git_sint32 * sp)
{
    git_uint32 undoSize = sizeof(UndoRecord);
    git_uint32 mapSize = sizeof(MemoryPage*) * (gEndMem - gRamStart) / 256;
    git_uint32 stackSize = sizeof(git_sint32) * (sp - base);
    git_uint32 totalSize = undoSize + mapSize + stackSize;

    git_uint32 addr = gRamStart; // Address in glulx memory.
    git_uint32 slot = 0;         // Slot in our memory map.
    
    UndoRecord * undo = malloc (undoSize);
    if (undo == NULL)
        fatalError ("Couldn't allocate undo record");
        
    undo->endMem = gEndMem;
    undo->memoryMap = malloc (mapSize);
    undo->stackSize = stackSize;
    undo->stack = malloc (stackSize);
    undo->prev = NULL;
    undo->next = NULL;

    if (undo->memoryMap == NULL || undo->stack == NULL)
        fatalError ("Couldn't allocate memory for undo");

    // Save the stack.
    memcpy (undo->stack, base, undo->stackSize);

    // Are we diffing against the previous undo record,
    // or against the initial gamefile state?
    if (gUndo == NULL)
    {
        // We're diffing against the gamefile.        
        for ( ; addr < gExtStart ; addr += 256, ++slot)
        {
            if (memcmp (gInitMem + addr, gMem + addr, 256) != 0)
            {
                // We need to save this page.
                git_uint8 * page = malloc(256);
                if (page == NULL)
                    fatalError ("Couldn't allocate memory for undo");
                    
                memcpy (page, gMem + addr, 256);
                undo->memoryMap[slot] = page;
                totalSize += 256;
            }
            else
            {
                // We don't need to save this page.
                // Just make it point into ROM.
                undo->memoryMap[slot] = gInitMem + addr;
            }
        }

        // If the memory map has been extended, save the exended area
        for (addr = gExtStart ; addr < gEndMem ; addr += 256, ++slot)
        {
            git_uint8 * page = malloc(256);
            if (page == NULL)
                fatalError ("Couldn't allocate memory for undo");
                
            memcpy (page, gMem + addr, 256);
            undo->memoryMap[slot] = page;
            totalSize += 256;
        }
    }
    else
    {
        // We're diffing against the most recent undo record.
        git_uint32 endMem = (gUndo->endMem < gEndMem) ? gUndo->endMem : gEndMem;
        for ( ; addr < endMem ; addr += 256, ++slot)
        {
            if (memcmp (gUndo->memoryMap [slot], gMem + addr, 256) != 0)
            {
                // We need to save this page.
                git_uint8 * page = malloc(256);
                memcpy (page, gMem + addr, 256);
                undo->memoryMap[slot] = page;
                totalSize += 256;
            }
            else
            {
                // We don't need to save this page. Just copy
                // the pointer from the previous undo record.
                undo->memoryMap[slot] = gUndo->memoryMap[slot];
            }
        }

        // If the memory map has been extended, save the exended area
        for (addr = endMem ; addr < gEndMem ; addr += 256, ++slot)
        {
            git_uint8 * page = malloc(256);
            if (page == NULL)
                fatalError ("Couldn't allocate memory for undo");
                
            memcpy (page, gMem + addr, 256);
            undo->memoryMap[slot] = page;
            totalSize += 256;
        }
    }

    // Save the heap.
    if (heap_get_summary (&(undo->heapSize), &(undo->heap)))
        fatalError ("Couldn't get heap summary");
    totalSize += undo->heapSize * 4;

    // Link this record into the undo list.
    
    undo->prev = gUndo;
    if (gUndo)
        gUndo->next = undo;
    
    gUndo = undo;
    gUndoSize += totalSize;

    // Delete old records until we have enough free space.
    reserveSpace (0);

    // And we're done.
    return 0;
}
Example #14
0
void resetUndo ()
{
    reserveSpace (gMaxUndoSize);
    assert (gUndo == NULL);
    assert (gUndoSize == 0);
}