void IRRQuadRenderer::createBuffers(const Group& group)
	{
		currentBuffer = dynamic_cast<IRRBuffer*>(group.createBuffer(getBufferName(),
																	IRRBufferCreator(device,
																		NB_VERTICES_PER_QUAD,
																		NB_INDICES_PER_QUAD),
																	getVBOFlag(),
																	false));
		size_t nbTotalParticles = group.getParticles().getNbReserved();

		irr::scene::IIndexBuffer& indexBuffer = currentBuffer->getIndexBuffer();
		if (indexBuffer.getType() == irr::video::EIT_32BIT)
		{
			irr::u32* indices = reinterpret_cast<irr::u32*>(indexBuffer.pointer());
			for (size_t t = 0; t < nbTotalParticles; ++t)
			{
				indices[NB_INDICES_PER_QUAD*t+0] = NB_VERTICES_PER_QUAD*t+0;
                indices[NB_INDICES_PER_QUAD*t+1] = NB_VERTICES_PER_QUAD*t+1;
                indices[NB_INDICES_PER_QUAD*t+2] = NB_VERTICES_PER_QUAD*t+2;
                indices[NB_INDICES_PER_QUAD*t+3] = NB_VERTICES_PER_QUAD*t+0;
                indices[NB_INDICES_PER_QUAD*t+4] = NB_VERTICES_PER_QUAD*t+2;
                indices[NB_INDICES_PER_QUAD*t+5] = NB_VERTICES_PER_QUAD*t+3;
			}
		}
		else if (indexBuffer.getType() == irr::video::EIT_16BIT)
		{
			irr::u16* indices = reinterpret_cast<irr::u16*>(indexBuffer.pointer());
			for (size_t t = 0; t < nbTotalParticles; ++t)
			{
				indices[NB_INDICES_PER_QUAD*t+0] = NB_VERTICES_PER_QUAD*t+0;
                indices[NB_INDICES_PER_QUAD*t+1] = NB_VERTICES_PER_QUAD*t+1;
                indices[NB_INDICES_PER_QUAD*t+2] = NB_VERTICES_PER_QUAD*t+2;
                indices[NB_INDICES_PER_QUAD*t+3] = NB_VERTICES_PER_QUAD*t+0;
                indices[NB_INDICES_PER_QUAD*t+4] = NB_VERTICES_PER_QUAD*t+2;
				indices[NB_INDICES_PER_QUAD*t+5] = NB_VERTICES_PER_QUAD*t+3;
			}	
		}

		irr::video::S3DVertex* vertices = currentBuffer->getVertexBuffer().pointer();
		for (size_t t = 0; t < nbTotalParticles; t++)
		{
			vertices[NB_VERTICES_PER_QUAD*t+0].TCoords = irr::core::vector2df(0.0f,0.0f);
			vertices[NB_VERTICES_PER_QUAD*t+1].TCoords = irr::core::vector2df(1.0f,0.0f);
			vertices[NB_VERTICES_PER_QUAD*t+2].TCoords = irr::core::vector2df(1.0f,1.0f);
			vertices[NB_VERTICES_PER_QUAD*t+3].TCoords = irr::core::vector2df(0.0f,1.0f);
		}

		if (IRRBuffer::isVBOHintActivated())
		{
			for (size_t t = 0; t < nbTotalParticles * NB_VERTICES_PER_QUAD; t++)
			{
				vertices[t].Pos = irr::core::vector3df(0.0f,0.0f,0.0f);
				vertices[t].Color = irr::video::SColor(0x00000000);
			}
		}
		else
			currentBuffer->setVBOInitialized(true);

		currentBuffer->getMeshBuffer().setDirty(irr::scene::EBT_VERTEX_AND_INDEX);	 
	}
Ejemplo n.º 2
0
void JSONVertexArray::write(json_stream& str, WriteVisitor& visitor)
{
    bool _useExternalBinaryArray = visitor._useExternalBinaryArray;
    bool _mergeAllBinaryFiles = visitor._mergeAllBinaryFiles;
    std::string basename = visitor._baseName;

    addUniqueID();

    std::stringstream url;
    if (visitor._useExternalBinaryArray) {
        std::string bufferName = getBufferName();
        if(bufferName.empty())
            bufferName = visitor.getBinaryFilename();

        if (visitor._mergeAllBinaryFiles)
            url << bufferName;
        else
            url << basename << "_" << getUniqueID() << ".bin";
    }

    std::string type;

    osg::ref_ptr<const osg::Array> array = _arrayData;

    switch (array->getType()) {
    case osg::Array::QuatArrayType:
    {
        osg::ref_ptr<osg::Vec4Array> converted = new osg::Vec4Array;
        converted->reserve(array->getNumElements());
        const osg::QuatArray* a = dynamic_cast<const osg::QuatArray*>(array.get());
        for (unsigned int i = 0; i < array->getNumElements(); ++i) {
            converted->push_back(osg::Vec4(static_cast<float>((*a)[i][0]),
                                           static_cast<float>((*a)[i][1]),
                                           static_cast<float>((*a)[i][2]),
                                           static_cast<float>((*a)[i][3])));
        }
        array = converted;
        type = "Float32Array";
    }
    case osg::Array::FloatArrayType:
    case osg::Array::Vec2ArrayType:
    case osg::Array::Vec3ArrayType:
    case osg::Array::Vec4ArrayType:
        type = "Float32Array";
        break;
    case osg::Array::Vec4ubArrayType:
    {
        osg::ref_ptr<osg::Vec4Array> converted = new osg::Vec4Array;
        converted->reserve(array->getNumElements());

        const osg::Vec4ubArray* a = dynamic_cast<const osg::Vec4ubArray*>(array.get());
        for (unsigned int i = 0; i < a->getNumElements(); ++i) {
            converted->push_back(osg::Vec4( (*a)[i][0]/255.0,
                                            (*a)[i][1]/255.0,
                                            (*a)[i][2]/255.0,
                                            (*a)[i][3]/255.0));
        }
        array = converted;
        type = "Float32Array";
    }
    break;
    case osg::Array::UByteArrayType:
    case osg::Array::Vec2ubArrayType:
    case osg::Array::Vec3ubArrayType:
        type = "Uint8Array";
        break;
    case osg::Array::UShortArrayType:
    case osg::Array::Vec2usArrayType:
    case osg::Array::Vec3usArrayType:
    case osg::Array::Vec4usArrayType:
        type = "Uint16Array";
        break;
    case osg::Array::UIntArrayType:
    case osg::Array::Vec2uiArrayType:
    case osg::Array::Vec3uiArrayType:
    case osg::Array::Vec4uiArrayType:
        type = "Uint32Array";
        break;
    case osg::Array::ByteArrayType:
    case osg::Array::Vec2bArrayType:
    case osg::Array::Vec3bArrayType:
    case osg::Array::Vec4bArrayType:
        type = "Int8Array";
        break;
    case osg::Array::ShortArrayType:
    case osg::Array::Vec2sArrayType:
    case osg::Array::Vec3sArrayType:
    case osg::Array::Vec4sArrayType:
        type = "Int16Array";
        break;
    case osg::Array::IntArrayType:
    case osg::Array::Vec2iArrayType:
    case osg::Array::Vec3iArrayType:
    case osg::Array::Vec4iArrayType:
        type = "Int32Array";
        break;
    default:
        osg::notify(osg::WARN) << "Array of type " << array->getType() << " not supported" << std::endl;
        break;
    }

    str << "{ " << std::endl;
    JSONObjectBase::level++;
    str << JSONObjectBase::indent() << "\"" << type << "\"" << ": { " << std::endl;
    JSONObjectBase::level++;
    if (_useExternalBinaryArray) {
        str << JSONObjectBase::indent() << "\"File\": \"" << osgDB::getSimpleFileName(url.str()) << "\","<< std::endl;
    } else {
        if (array->getNumElements() == 0) {
            str << JSONObjectBase::indent() << "\"Elements\": [ ],";

        } else {

            switch (array->getType()) {
            case osg::Array::FloatArrayType:
            case osg::Array::Vec2ArrayType:
            case osg::Array::Vec3ArrayType:
            case osg::Array::Vec4ArrayType:
            {
                const float* a = static_cast<const float*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArrayReal<float>(str, size, a);
            }
            break;
            case osg::Array::DoubleArrayType:
            case osg::Array::Vec2dArrayType:
            case osg::Array::Vec3dArrayType:
            case osg::Array::Vec4dArrayType:
            case osg::Array::QuatArrayType:
            {
                const double* a = static_cast<const double*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArrayReal<double>(str, size, a);
            }
            break;
            case osg::Array::ByteArrayType:
            case osg::Array::Vec2bArrayType:
            case osg::Array::Vec3bArrayType:
            case osg::Array::Vec4bArrayType:
            {
                const char* a = static_cast<const char*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArray<char, short>(str, size, a); // using short to write readable numbers and not `char`s
            }
            break;
            case osg::Array::UByteArrayType:
            case osg::Array::Vec2ubArrayType:
            case osg::Array::Vec3ubArrayType:
            case osg::Array::Vec4ubArrayType:
            {
                const unsigned char* a = static_cast<const unsigned char*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArray<unsigned char, unsigned short>(str, size, a); // using short to write readable numbers and not `char`s
            }
            break;
            case osg::Array::ShortArrayType:
            case osg::Array::Vec2sArrayType:
            case osg::Array::Vec3sArrayType:
            case osg::Array::Vec4sArrayType:
            {
                const short* a = static_cast<const short*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArray<short>(str, size, a);
            }
            break;
            case osg::Array::UShortArrayType:
            case osg::Array::Vec2usArrayType:
            case osg::Array::Vec3usArrayType:
            case osg::Array::Vec4usArrayType:
            {
                const unsigned short* a = static_cast<const unsigned short*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArray<unsigned short>(str, size, a);
            }
            break;
            case osg::Array::IntArrayType:
            case osg::Array::Vec2iArrayType:
            case osg::Array::Vec3iArrayType:
            case osg::Array::Vec4iArrayType:
            {
                const int* a = static_cast<const int*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArray<int>(str, size, a);
            }
            break;
            case osg::Array::UIntArrayType:
            case osg::Array::Vec2uiArrayType:
            case osg::Array::Vec3uiArrayType:
            case osg::Array::Vec4uiArrayType:
            {
                const unsigned int* a = static_cast<const unsigned int*>(array->getDataPointer());
                unsigned int size = array->getNumElements() * array->getDataSize();
                writeInlineArray<unsigned int>(str, size, a);
            }
            break;

            case osg::Array::MatrixdArrayType:
            default:
                break;
            }
        }
    }

    str << JSONObjectBase::indent() << "\"Size\": " << array->getNumElements();
    if (_useExternalBinaryArray) {
        str << "," << std::endl;
    } else {
        str << std::endl;
    }

    if (_useExternalBinaryArray) {
        unsigned int size;
        if (_mergeAllBinaryFiles) {
            std::pair<unsigned int, unsigned int> result;
            std::string encoding;
            result = writeMergeData(array.get(), visitor, url.str(), encoding);
            unsigned int offset = result.first;
            size = result.second;
            if(!encoding.empty()) {
                str << JSONObjectBase::indent() << "\"Offset\": " << offset << "," << std::endl;
                str << JSONObjectBase::indent() << "\"Encoding\": \"" << encoding << "\"" << std::endl;
            }
            else {
                str << JSONObjectBase::indent() << "\"Offset\": " << offset << std::endl;
            }
        } else {
            size = writeData(array.get(), url.str());
            str << JSONObjectBase::indent() << "\"Offset\": " << 0 << std::endl;
        }
        std::stringstream b;
        osg::notify(osg::NOTICE) << "TypedArray " << type << " " << url.str() << " ";
        if (size/1024.0 < 1.0) {
            osg::notify(osg::NOTICE) << size << " bytes" << std::endl;
        } else if (size/(1024.0*1024.0) < 1.0) {
            osg::notify(osg::NOTICE) << size/1024.0 << " kb" << std::endl;
        } else {
            osg::notify(osg::NOTICE) << size/(1024.0*1024.0) << " mb" << std::endl;
        }

    }

    JSONObjectBase::level--;
    str << JSONObjectBase::indent() << "}" << std::endl;
    JSONObjectBase::level--;

    str << JSONObjectBase::indent() << "}";
}
Ejemplo n.º 3
0
/*
 * listRegistry
 * List the contents of the registry.
 */
int
listRegistry (int f, int n)
{
    meBuffer *bp;                         /* Buffer pointer */
    meWindow *wp;                         /* Window associated with buffer */
    meRegNode *rnp, *cnp, *nnp ;          /* Draw the nodes */
    meUByte vstrbuf [meBUF_SIZE_MAX];     /* Vertical string buffer */
    meUByte *bn, buf[meBUF_SIZE_MAX*2];   /* Working line buffer */
    int level = 0;                        /* Depth in the registry */
    int len;                              /* Length of the string */

    rnp = &root;
    if((n & 0x02) != 0)
    {
        if(meGetString((meUByte *)"Registry Path",0, 0, buf, meBUF_SIZE_MAX) == meABORT)
            return meABORT;

        /* Find the node */
        if((rnp = regFind(rnp,buf)) == NULL)
            return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",buf);
    }
    
    if((n & 0x01) == 0)
    {
        /* prompt for and get the new buffer name */
        if((len = getBufferName((meUByte *) "Buffer", 0, 0, buf)) <= 0)
            return len ;
        bn = buf ;
    }
    else
        bn = BregistryN ;
    
    /* Find the buffer and vapour the old one */
    if((wp = meWindowPopup(bn,BFND_CREAT|BFND_CLEAR|WPOP_USESTR,NULL)) == NULL)
        return meFALSE;
    bp = wp->buffer ;                   /* Point to the buffer */

    /* Recurse the children of the node and write to file */
    do
    {
        /* get the current node's first drawn child */
        cnp = rnp->child ;
        while((cnp != NULL) && (cnp->mode & meREGMODE_INVISIBLE))
            cnp = cnp->next ;

        /* get the current node's next drawn sibling */
        nnp = rnp->next ;
        while((nnp != NULL) && (nnp->mode & meREGMODE_INVISIBLE))
            nnp = nnp->next ;

        /* Add continuation bars if we are at a child level */
        if((len = level) != 0)
            meStrncpy (buf, vstrbuf, len);
        
        /* Add connection bars for siblings */
        if(level && (nnp != NULL))
            buf [len++] = boxChars[BCNES] ;
        else
            buf [len++] = boxChars[BCNE];
        
        /* Add continuation barss for children */
        if (rnp->mode & meREGMODE_INTERNAL)
            buf[len++] = '!';
        else if (cnp == NULL)
            buf[len++] = boxChars[BCEW];
        else if (rnp->mode & meREGMODE_HIDDEN)
            buf[len++] = '+';
        else
            buf[len++] = '-';
        buf[len++] = ' ';
        
        /* Add the name of the node */
        buf[len++] = '"';
        len = expandexp(-1,rnp->name,(meBUF_SIZE_MAX*2)-7,len,buf,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO) ;
        buf[len++] = '"';
        
        /* Add the value */
        if ((rnp->value != NULL) && !(rnp->mode & meREGMODE_INTERNAL))
        {
            buf[len++] = ' ';
            buf[len++] = '=';
            buf[len++] = ' ';
            buf[len++] = '"';
            len = expandexp(-1,rnp->value,(meBUF_SIZE_MAX*2)-2,len,buf,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO) ;
            buf[len++] = '"';
        }
        /* Add the string to the print buffer */
        buf[len] = '\0';
        addLineToEob(bp,buf);
        /* Descend child */
        if((cnp != NULL) && !(rnp->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL)))
        {
            vstrbuf[level] = (level && (nnp != NULL)) ? boxChars[BCNS] : ' ' ;
            level++;
            rnp = cnp ;
            continue ;
        }
        
        /* Ascend the tree */
        while((nnp == NULL) && (--level >= 0) && ((rnp = rnp->parent) != NULL))
        {
            /* Move to next drawn sibling */
            nnp = rnp->next ;
            while((nnp != NULL) && (nnp->mode & meREGMODE_INVISIBLE))
                nnp = nnp->next ;
        }
        rnp = nnp ;
    } while((level > 0) && (rnp != NULL)) ;

    /* Set up the buffer for display */
    bp->dotLine = meLineGetNext(bp->baseLine);
    bp->dotOffset = 0 ;
    bp->dotLineNo = 0 ;
    meModeSet(bp->mode,MDVIEW) ;
    meModeClear(bp->mode,MDAUTOSV) ;
    meModeClear(bp->mode,MDUNDO) ;
    resetBufferWindows(bp) ;
    return meTRUE;
}