Click here to Skip to main content
15,892,161 members
Articles / Mobile Apps / Android

One-Touch Casual 3D Game Based on OpenGL ES 2.0 3D Engine with Lua, Bullet, and Vorbis Support

Rate me:
Please Sign up or sign in to vote.
4.75/5 (7 votes)
8 Nov 2012CPOL5 min read 50.5K   3.3K   18  
Android-x86 native game-engine - without JNI
#include "Base.h"
#include "VertexFormat.h"

namespace gameplay
{

VertexFormat::VertexFormat(const Element* elements, unsigned int elementCount)
    : _vertexSize(0)
{
    GP_ASSERT(elements);

    // Copy elements and compute vertex size
    for (unsigned int i = 0; i < elementCount; ++i)
    {
        // Copy element
        Element element;
        memcpy(&element, &elements[i], sizeof(Element));
        _elements.push_back(element);

        _vertexSize += element.size * sizeof(float);
    }
}

VertexFormat::~VertexFormat()
{
}

const VertexFormat::Element& VertexFormat::getElement(unsigned int index) const
{
    GP_ASSERT(index < _elements.size());
    return _elements[index];
}

unsigned int VertexFormat::getElementCount() const
{
    return _elements.size();
}

unsigned int VertexFormat::getVertexSize() const
{
    return _vertexSize;
}

bool VertexFormat::operator == (const VertexFormat& f) const
{
    if (_elements.size() != f._elements.size())
        return false;

    for (unsigned int i = 0, count = _elements.size(); i < count; ++i)
    {
        if (_elements[i] != f._elements[i])
            return false;
    }

    return true;
}


bool VertexFormat::operator != (const VertexFormat& f) const
{
    return !(*this == f);
}

VertexFormat::Element::Element() :
    usage(POSITION), size(0)
{
}

VertexFormat::Element::Element(Usage usage, unsigned int size) :
    usage(usage), size(size)
{
}

bool VertexFormat::Element::operator == (const VertexFormat::Element& e) const
{
    return (size == e.size && usage == e.usage);
}

bool VertexFormat::Element::operator != (const VertexFormat::Element& e) const
{
    return !(*this == e);
}

const char* VertexFormat::toString(Usage usage)
{
    switch (usage)
    {
    case POSITION:
        return "POSITION";
    case NORMAL:
        return "NORMAL";
    case COLOR:
        return "COLOR";
    case TANGENT:
        return "TANGENT";
    case BINORMAL:
        return "BINORMAL";
    case BLENDWEIGHTS:
        return "BLENDWEIGHTS";
    case BLENDINDICES:
        return "BLENDINDICES";
    case TEXCOORD0:
        return "TEXCOORD0";
    case TEXCOORD1:
        return "TEXCOORD1";
    case TEXCOORD2:
        return "TEXCOORD2";
    case TEXCOORD3:
        return "TEXCOORD3";
    case TEXCOORD4:
        return "TEXCOORD4";
    case TEXCOORD5:
        return "TEXCOORD5";
    case TEXCOORD6:
        return "TEXCOORD6";
    case TEXCOORD7:
        return "TEXCOORD7";
    default:
        return "UNKNOWN";
    }
}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions