当前位置: 首页>>代码示例>>C++>>正文


C++ Quad::setNativeTextureID方法代码示例

本文整理汇总了C++中Quad::setNativeTextureID方法的典型用法代码示例。如果您正苦于以下问题:C++ Quad::setNativeTextureID方法的具体用法?C++ Quad::setNativeTextureID怎么用?C++ Quad::setNativeTextureID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quad的用法示例。


在下文中一共展示了Quad::setNativeTextureID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: render

void DisplayObject::render(lua_State *L) {
    // Disable reentrancy for this function (read: don't cache to texture while caching to a texture)
    if (cacheAsBitmapInProgress) return;

    // Clear and free the cached image if the conditions apply
    if ((!cacheAsBitmap || !cacheAsBitmapValid) && cachedImage != NULL) {
        Quad* quad = static_cast<Quad*>(cachedImage);

        lmAssert(quad != NULL, "Cached image is invalid");

        GFX::Texture::dispose(quad->getNativeTextureID());
        quad->setNativeTextureID(-1);

        lmDelete(NULL, quad);
        cachedImage = NULL;
        cacheAsBitmapValid = false;
    }

    // Cache the contents into an image if the conditions apply
    if (cacheAsBitmap && !cacheAsBitmapValid && cachedImage == NULL) {
        cacheAsBitmapInProgress = true;
        
        // Used for displaying the texture
        Quad* quad = lmNew(NULL) Quad();
        
        // Setup for getmember
        lualoom_pushnative<DisplayObject>(L, this);
        
        // Push function and arguments
        lualoom_getmember(L, -1, "getBounds");
        lualoom_pushnative<DisplayObject>(L, this);
        lua_pushnil(L);
        // Call getBounds
        lua_call(L, 2, 1);
        
        // Returned result
        Loom2D::Rectangle *bounds = (Loom2D::Rectangle*) lualoom_getnativepointer(L, -1);
        cacheAsBitmapOffsetX = bounds->x;
        cacheAsBitmapOffsetY = bounds->y;
        lmscalar fracWidth = bounds->width;
        lmscalar fracHeight = bounds->height;

        // pop bounds Rectangle and the DisplayObject at the top
        lua_pop(L, 1+1);

        if (cacheApplyScale)
        {
            fracWidth *= scaleX;
            fracHeight *= scaleY;
        }

        // Convert to integers for the following math
        int texWidthI = static_cast<int>(ceil(fracWidth));
        int texHeightI = static_cast<int>(ceil(fracHeight));

        // Calculate power of 2 sizes
        if (cacheUseTexturesPot)
        {
            _UT_UTHASHTABLE_POW2(texWidthI);
            _UT_UTHASHTABLE_POW2(texHeightI);
        }

        // Calculate the resulting scale (as a consequence of pow2 sizes)
        // Used for 'trans' matrix
        lmscalar calcScaleX = texWidthI / bounds->width;
        lmscalar calcScaleY = texHeightI / bounds->height;

        // Setup texture
        TextureInfo *tinfo = Texture::initEmptyTexture(texWidthI, texHeightI);
        Texture::clear(tinfo->id, 0x000000, 0);
        tinfo->smoothing = TEXTUREINFO_SMOOTHING_BILINEAR;
        tinfo->wrapU = TEXTUREINFO_WRAP_CLAMP;
        tinfo->wrapV = TEXTUREINFO_WRAP_CLAMP;
        TextureID id = tinfo->id;

        // Setup quad for rendering the texture
        quad->setNativeTextureID(id);
        
        VertexPosColorTex* qv;

        qv = &quad->quadVertices[0];  qv->x =                    0;  qv->y =                     0;  qv->z = 0; qv->abgr = 0xFFFFFFFF; qv->u = 0; qv->v = 0;
        qv = &quad->quadVertices[1];  qv->x = (float)bounds->width;  qv->y =                     0;  qv->z = 0; qv->abgr = 0xFFFFFFFF; qv->u = 1; qv->v = 0;
        qv = &quad->quadVertices[2];  qv->x =                    0;  qv->y = (float)bounds->height;  qv->z = 0; qv->abgr = 0xFFFFFFFF; qv->u = 0; qv->v = 1;
        qv = &quad->quadVertices[3];  qv->x = (float)bounds->width;  qv->y = (float)bounds->height;  qv->z = 0; qv->abgr = 0xFFFFFFFF; qv->u = 1; qv->v = 1;
        quad->setNativeVertexDataInvalid(false);

        lmAssert(Texture::getRenderTarget() == -1, "Unsupported render target state: %d", Texture::getRenderTarget());

        // Set render target to texture
        Texture::setRenderTarget(id);
        
        // Shift the contents down and to the right so that the elements extending
        // past the left and top edges don't get cut off, ignore other existing transforms
        Matrix trans;
        trans.translate(-cacheAsBitmapOffsetX, -cacheAsBitmapOffsetY);

        trans.scale(calcScaleX, calcScaleY);

        // Setup for Graphics::render
        lualoom_pushnative<DisplayObject>(L, this);
//.........这里部分代码省略.........
开发者ID:Y-way,项目名称:LoomSDK,代码行数:101,代码来源:l2dDisplayObject.cpp


注:本文中的Quad::setNativeTextureID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。