示例#1
0
文件: cset.cpp 项目: JianwenSun/cc
//-----------------------------------------------------------------
static HTML_ITEM LookupElement (const CH* szName)
{
    if (0 == icmp(szName, _CH("HEAD"))) return _HEAD;
    if (0 == icmp(szName, _CH("META"))) return _META;
    if (0 == icmp(szName, _CH("BODY"))) return _BODY;
    return hi_TagUnknown;
}
示例#2
0
文件: cset.cpp 项目: JianwenSun/cc
static HRESULT ScanComment(const CH * pchStart, const CH * pchEnd, const CH ** ppch, int * pcch)
{
    if(pchStart == NULL)
        return E_INVALIDARG;

    const CH * pchScan = pchStart;
    const CH * pch = 0;
    
    if (ppch) *ppch = 0;
    if (pcch) *pcch = 0;
    
    SKIPWHITE_FAIL
    
    // leading --
    if (_CH('-') != *pchScan) return E_FAIL;
    pch = pchScan++;
    if (pchScan >= pchEnd) return E_FAIL;
    if (_CH('-') != *pchScan++) return E_FAIL;

    // look for trailing --
    for (;;)
    {
        while (pchScan < pchEnd && _CH('-') != *pchScan)
            pchScan++;
        if (++pchScan >= pchEnd) return E_FAIL;
        if (_CH('-') == *pchScan++)
            break;
    }
    
    if (ppch) *ppch = pch;
    if (pcch) *pcch = (int)(pchScan - pch);
    return S_OK;
}
示例#3
0
void MyRenderGL::OnPreRender() {
    this->MyRender::OnPreRender();

    _CH(glViewport( 0, 0, view.m_width, view.m_height ));
    _CH(glClear( GL_COLOR_BUFFER_BIT 
        | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ));
}
示例#4
0
文件: cset.cpp 项目: JianwenSun/cc
inline bool IsACSChar(CH c)
{ 
    return IsAAlNum(c) 
        || (_CH('_') == c)
        || (_CH('-') == c)
        || (_CH(':') == c)
        || (_CH('.') == c);
}
示例#5
0
文件: cset.cpp 项目: JianwenSun/cc
//-----------------------------------------------------------------
static HRESULT ScanAttribute( const CH * pchStart, const CH * pchEnd, HATT * pAtt)
{
    if(pchStart == NULL)
        return E_INVALIDARG;

    const CH * pch;
    int        cch;
    const CH * pchScan  = pchStart;
    HRESULT hr;

    if (pAtt) memset(pAtt, 0, sizeof(HATT));

    SKIPWHITE_FAIL

    switch (*pchScan)
    {
    case _CH('>'): return S_FALSE; // end of tag -- no attribute

    case _CH('/'):
        // End of empty element (e.g. "<foo ... />").  No more attributes.
        return S_FALSE;

    case _CH('-'): // comment
        if (pAtt)
            return ScanComment(pchScan, pchEnd, &pAtt->pchValue, &pAtt->cchValue);
        else
            return ScanComment(pchScan, pchEnd, 0, 0);
        break;
    }

    // scan Name
    hr = ScanName(pchScan, pchEnd, &pch, &cch);
    if (FAILED(hr)) return hr;
    if (pAtt)
    {
        pAtt->pchName = pch;
        pAtt->cchName = cch;
    }
    pchScan = pch + cch;    
    SKIPWHITE_FAIL

    if (*pchScan != _CH('=')) 
        return hr; 
    pchScan++;
    
    SKIPWHITE_FAIL

    hr = ScanValue(pchScan, pchEnd, &pch, &cch);
    if (SUCCEEDED(hr) && pAtt)
    {
        pAtt->pchValue = pch;
        pAtt->cchValue = cch;
    }
    return hr;
}
示例#6
0
void MyRenderGL::RenderSurface( const std::shared_ptr<gsurface_t> &surf ) {
    idmat4 mvpMatrix;

    mvpMatrix = m_projectionMatrix * glflipMatrix 
        * m_viewMatrix * surf.m_modelMatrix;

    surf->m_material.m_program->Bind( "mvp_matrix", mvpMatrix.Transpose() );
    surf->m_material.m_program->Bind( "model_matrix", 
            ( flipMatrix * surf.m_modelMatrix ).Transpose() );
    surf->m_material.m_program->Bind( "eye_pos", ToWorld( m_eye.ToVec3() ) );

    surf->m_material.m_program->Use();

    surf->m_material.m_texture->Bind();

    _CH(glBindVertexArray( surf->m_vao ));

    _CH(glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, surf->m_indexBuffer ));

    _CH(glDrawElements( GL_TRIANGLES, 
                surf->m_numIndices, GL_UNSIGNED_SHORT, 0 ));
}
示例#7
0
文件: cset.cpp 项目: JianwenSun/cc
static HRESULT ScanValue(const CH * pchStart, const CH * pchEnd, const CH ** ppch, int * pcch)
{
    if(pchStart == NULL)
        return E_INVALIDARG;

    const CH * pchScan = pchStart;
    const CH * pch = 0;
    
    if (ppch) *ppch = 0;
    if (pcch) *pcch = 0;
    
    SKIPWHITE_FAIL

    pch = pchScan;
    switch(*pchScan)
    {
    case _CH('"'):
        pchScan++;
        while ((pchScan < pchEnd) && *pchScan != '"')
            pchScan++;
        pchScan++;
        break;
    case _CH('\''):
        pchScan++;
        while ((pchScan < pchEnd) && *pchScan != '\'')
            pchScan++;
        pchScan++;
        break;
    default:
        while ((pchScan < pchEnd) && (*pchScan > 32) && *pchScan != '>')
            pchScan++;
    }
    if (pchScan >= pchEnd) return E_FAIL;
    
    if (ppch) *ppch = pch;
    if (pcch) *pcch = (int)(pchScan - pch);
    return S_OK;
}
示例#8
0
文件: cset.cpp 项目: JianwenSun/cc
static HRESULT ScanName( const CH * pchStart, const CH * pchEnd, const CH ** ppch, int * pcch)
{
    if(pchStart == NULL)
        return E_INVALIDARG;

    const CH * pchScan = pchStart;
    const CH * pchName = 0;

    if (ppch) *ppch = 0;
    if (pcch) *pcch = 0;
    
    SKIPWHITE_FAIL
    
    if (!IsAAlpha(*pchScan)) return E_FAIL;
    pchName = pchScan++;
    while ((pchScan < pchEnd) && (IsAAlNum(*pchScan) || (_CH('-') == *pchScan) || (_CH(':') == *pchScan)))
        pchScan++;
    if (pchScan >= pchEnd) return E_FAIL;

    if (ppch) *ppch = pchName;
    if (pcch) *pcch = (int)(pchScan - pchName);
    return S_OK;
}
示例#9
0
bool GLTexture::Init( const std::string &name, int textureUnit ) {
    byte *pic, *picCopy;
    GLuint texture;
    int width, height, format;

    format = GL_RGBA;

    if ( EndsWith( name, ".tga" ) ) {
        pic = R_LoadTGA( name, width, height, format );
    } else {
        msg_warning( "no image file with name `%s' found\n", name.c_str() );
        return false;
    }

    if ( !IsPowerOf2( width ) || !IsPowerOf2( height ) ) {
        msg_warning0( "texture must have size in power of two\n" );
        return false;
    }

    picCopy = (byte *)malloc( width * height * 4 );

    _CH(glActiveTexture( GL_TEXTURE0 + textureUnit ));
    _CH(glGenTextures( 1, &texture ));
    _CH(glBindTexture( GL_TEXTURE_2D, texture ));
    _CH(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
    _CH(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));

    int mipmap = 0;
    while ( width > 1 || height > 1 ) {
        _CH(glTexImage2D( GL_TEXTURE_2D,
            mipmap,
            format,
            width,
            height,
            0,
            format,
            GL_UNSIGNED_BYTE,
            pic));

        int oldWidth, oldHeight;

        oldWidth = width;
        oldHeight = height;

        if ( width > 1 ) {
            width >>= 1;
        }

        if ( height > 1 ) {
            height >>= 1;
        }
示例#10
0
文件: cset.cpp 项目: JianwenSun/cc
//-----------------------------------------------------------------
static void ScanItem (const CH * pchStart, const CH * pchEnd, HTOK * pk)
{
    if(pchStart == NULL || pk == NULL)
    {
        VSASSERT(false,"");
        return;
    }
    
    HRESULT hr;

    pk->id     = hi_Unknown;
    pk->pch    = (CH*)pchStart;
    pk->cch    = 0;
    pk->bEnd   = false;

    if (pchStart >= pchEnd)
    {
        pk->id = hi_Eof;
        return;
    }
    const CH * pchScan = pchStart;
    
    switch (*pchScan)
    {
//  case _CH(0):
//      pk->id = hi_Eof;
//      break;
//
//  case _CH('\n'):
//  case _CH('\r'):
//      pchScan = AdvanceLineBreak((CH*)pchScan);
//      pk->id = hi_Eol;
//      break;
    
    case _CH('<'):
        {
            const CH * pchName;
            int cch;
            
            pchScan++;          
            pk->id = hi_Error;
            switch (*pchScan)
            {
            case _CH('!'):
                pk->id = hi_Error;
                pchScan++;
                while (_CH('>') != *pchScan)
                {
                    const CH * pch;
                    int        cch;

                    SKIPWHITE_RET

                    if (IsAAlpha(*pchScan))
                        hr = ScanName(pchScan, pchEnd, &pch, &cch);
                    else
                    {
                        switch(*pchScan)
                        {
                        case CH('\''):
                        case CH('"'):
                            hr = ScanValue(pchScan, pchEnd, &pch, &cch);
                            break;

                        case CH('-'):
                            hr = ScanComment(pchScan, pchEnd, &pch, &cch);
                            break;
                        
                        default:
                            hr = S_OK;
                            pch = pchScan;
                            cch = 1;
                            break;
                        }
                    }

                    pchScan = pch + cch;
                    if (FAILED(hr) || (pchScan >= pchEnd))
                        return;
                }
                pk->id = hi_TagSpecial;
                break;

            case _CH('%'):  // ASP 'tag'
                pk->id = hi_TagSpecial;
                do {
                    do {
                        pchScan++;
                    } while ((pchScan < pchEnd) && (_CH('>') != *pchScan));
                } while ((pchScan < pchEnd) &&  (*(pchScan-1) != _CH('%')));
                break;

            case _CH('/'):
                pk->bEnd = true;
                pchScan++;
                break;

            case _CH('?'):  //
                pk->id = hi_TagSpecial;
                pchScan++;
                while ((pchScan < pchEnd) && (_CH('>') != *pchScan))
                    pchScan++;
                break;

            }
            if (pk->id != hi_TagSpecial)
            {
                pk->id = hi_Error;
                SKIPWHITE_RET
                if (!IsAAlpha(*pchScan))
                    return;
                pchName = pchScan;
                while ((pchScan < pchEnd) && IsAAlNum(*pchScan))
                    pchScan++;
                if (pchScan >= pchEnd)
                    return;
                cch = (int)(pchScan - pchName);
                if (cch <= cchMaxTag && cch > 0)
                {
                    CH * pszName = (CH*)_alloca((cch+1)*CBCH );
                    strcchcopy(pszName, cch+1, pchName);
                    pk->id = LookupElement(pszName);
                }
                else
                    return;
                if (!pk->bEnd)
                {
                    // scan attributes and comments
                    for(;;)
                    {
                        HATT    hatt;
                        HRESULT hr = ScanAttribute(pchScan, pchEnd, &hatt);
                        if (FAILED(hr))
                        {
                            pk->id = hi_Error;
                            return;
                        }
                        if (S_FALSE == hr)
                            break;
                        pchScan = hatt.pchValue ? hatt.pchValue + hatt.cchValue : hatt.pchName + hatt.cchName;
                    }
                }
            }
            // Skip over whitespace and, if this is an empty element, the closing '/' (e.g. "<foo ... />")
            while ((pchScan < pchEnd) && ((*pchScan <= 32) || (*pchScan == _CH('/'))))
                pchScan++;
            if ((pchScan >= pchEnd) || (_CH('>') != *pchScan))
                pk->id = hi_Error;
            pchScan++;
        }
        break;

//  case _CH('&'):
//      pk->id = hi_Entity;
//      if (!ScanEntity(pchScan, &pk->ch, &pchScan))
//          goto L_Text;
//      break;
    
    default:
//L_Text:
        pk->id = hi_Text;
        for (bool f = true; f && (pchScan < pchEnd); )
        {
            switch (*pchScan)
            {
//          case _CH(0):
//          case _CH('\n'):
//          case _CH('\r'):
//          case _CH('&'):
            case _CH('<'):
                f = false;
                break;
            default:
                pchScan++;
                break;
            }
        }
        break;
    }
示例#11
0
文件: cset.cpp 项目: JianwenSun/cc
//-----------------------------------------------------------------
// FindAttribute - Find a specific attribute
//
// Returns:
//   S_OK     Found Attribute
//   S_FALSE  Attribute not found
//   E_FAIL   Syntax error
//
static HRESULT FindAttribute (const CH * pchTag, const CH *pchEnd, const CH * pszAName, const CH **ppchVal, int * pcchVal)
{
    if(pchTag == NULL || pszAName == NULL || *pszAName == NULL)
    {
        VSASSERT(false,"");
        return E_INVALIDARG;
    }
    
    HRESULT    hr;
    const CH * pch;
    int        cch;
    int        cchAttIn = slen(pszAName);
    const CH * pchScan = pchTag;
    const CH * pchVal  = 0;
    
    *ppchVal = 0;
    *pcchVal = 0;

    if (*pchScan == _CH('<'))
        pchScan++;

    // don't look in ! tags or end tags
    if (*pchScan == _CH('!') || *pchScan == _CH('/') || *pchScan == _CH('?'))
        return S_FALSE;

    SKIPWHITE_FAIL

    hr = ScanName(pchScan, pchEnd, &pch, &cch);
    if (FAILED(hr))
        return E_FAIL;
    pchScan = pch + cch;
    if (pchScan >= pchEnd)
        return S_FALSE;  // no attributes

    for(;;)
    {
        HATT    hatt;
        HRESULT hr = ScanAttribute(pchScan, pchEnd, &hatt);
        if (FAILED(hr))
            return E_FAIL;
        if (S_FALSE == hr)
            break;
        pchScan = hatt.pchValue ? hatt.pchValue + hatt.cchValue : hatt.pchName + hatt.cchName;
        if (!hatt.pchName || !hatt.cchName)
            continue; // comment

        if ((cchAttIn == hatt.cchName) && (0 == icmpn(hatt.pchName, pszAName, cchAttIn)))        
        {
            /// strip quotes, if any
            CH ch = *hatt.pchValue;
            if (ch == _CH('"') || ch == _CH('\''))
            {
                VSASSERT(ch == hatt.pchValue[hatt.cchValue-1],"");
                hatt.pchValue++;
                hatt.cchValue -= 2;
            }
            // done!
            *ppchVal = hatt.pchValue;
            *pcchVal = hatt.cchValue;
            return S_OK;
        }
    }
    return S_FALSE;
}
示例#12
0
文件: cset.cpp 项目: JianwenSun/cc
inline bool IsAAlNum(CH c) { return (_CH('a') <= c && c <= _CH('z')) || (_CH('A') <= c && c <= _CH('Z')) || (_CH('0') <= c && c <= _CH('9')); }
示例#13
0
文件: cset.cpp 项目: JianwenSun/cc
inline bool IsAAlpha(CH c) { return (_CH('a') <= c && c <= _CH('z')) || (_CH('A') <= c && c <= _CH('Z')); }
示例#14
0
文件: cset.cpp 项目: JianwenSun/cc
//-----------------------------------------------------------------
inline bool IsADigit(CH c) { return (_CH('0') <= c && c <= _CH('9')); }
示例#15
0
std::shared_ptr<gsurface_t> MyRenderGL::CacheSurface( const surf_t &s ) {
    GLuint vao;
    GLuint positionBuffer, indexBuffer;

    _CH(glGenVertexArrays( 1, &vao ));
    _CH(glBindVertexArray( vao ));

    _CH(glGenBuffers( 1, &positionBuffer ));
    _CH(glBindBuffer( GL_ARRAY_BUFFER, positionBuffer ));
    _CH(glBufferData( GL_ARRAY_BUFFER, s.m_verts.size() * 8 * sizeof(float),
        (void *)s.m_verts.data(), GL_STATIC_DRAW ));

    _CH(glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
        (void *)(0 * sizeof(float ) ) ));
    _CH(glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
        (void *)(3 * sizeof(float ) ) ));
    _CH(glVertexAttribPointer( 2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
        (void *)(5 * sizeof(float ) ) ));

    _CH(glEnableVertexAttribArray( 0 ));
    _CH(glEnableVertexAttribArray( 1 ));
    _CH(glEnableVertexAttribArray( 2 ));

    _CH(glGenBuffers( 1, &indexBuffer ));
    _CH(glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ));
    _CH(glBufferData( GL_ELEMENT_ARRAY_BUFFER, 
                s.m_indices.size() * sizeof(GLushort),
        (void *)s.m_indices.data(), GL_STATIC_DRAW ));

    std::shared_ptr<gsurface_t> cached = CreateSurface();

    cached->m_vao = vao;
    cached->m_numIndices = s.m_indices.size();
    cached->m_indexBuffer = indexBuffer;

    if ( s.m_matName == "white" ) {
        cached->m_material = m_whiteMaterial;
    } else if ( s.m_matName == "sky" ) {
        cached->m_material = m_skyMaterial;
    } else {
        if ( m_materialCache.find( s.m_matName ) != m_materialCache.end() ) {
            cached->m_material = m_materialCache[ s.m_matName ];
        } else {
            std::shared_ptr<material_t> t = new material_t();
            t->m_texture = CreateTexture( s.m_matName );
            t->m_program = m_shaderProgram;
            if ( !t.IsValid() ) {
                msg_failure( "Can't cache material `%s'\n", s.m_matName.c_str() );
                return nullptr;
            }
            m_materialCache[ s.m_matName ] = t;
            cached->m_material = t;
        }
    }
    return cached;
}