Subversion Repositories eduke32

Rev

Rev 5056 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5056 Rev 5075
Line 97... Line 97...
97
}
97
}
98
98
99
// <dashade>: ignored if not in Polymost+r_usetileshades
99
// <dashade>: ignored if not in Polymost+r_usetileshades
100
pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth)
100
pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth)
101
{
101
{
102
    int32_t tilestat;
-
 
103
    pthtyp *pth;
-
 
104
-
 
105
    const int32_t j = dapicnum & (GLTEXCACHEADSIZ - 1);
102
    const int32_t j = dapicnum & (GLTEXCACHEADSIZ - 1);
106
    hicreplctyp *si = usehightile ? hicfindsubst(dapicnum, dapalnum) : NULL;
103
    hicreplctyp *si = usehightile ? hicfindsubst(dapicnum, dapalnum) : NULL;
107
104
108
    if (drawingskybox && usehightile)
105
    if (drawingskybox && usehightile)
109
        if ((si = hicfindskybox(dapicnum, dapalnum)) == NULL)
106
        if ((si = hicfindskybox(dapicnum, dapalnum)) == NULL)
Line 123... Line 120...
123
     * else if palette > 0 && no replacement found
120
     * else if palette > 0 && no replacement found
124
     *    effects are applied to the palette 0 texture if it exists
121
     *    effects are applied to the palette 0 texture if it exists
125
     */
122
     */
126
123
127
    // load a replacement
124
    // load a replacement
128
    for (pth = texcache.list[j]; pth; pth = pth->next)
125
    for (pthtyp *pth = texcache.list[j]; pth; pth = pth->next)
129
    {
126
    {
130
        if (pth->picnum == dapicnum && pth->palnum == si->palnum &&
127
        if (pth->picnum == dapicnum && pth->palnum == si->palnum &&
131
            (si->palnum > 0 ? 1 : (pth->effects == hictinting[dapalnum].f)) &&
128
            (si->palnum > 0 ? 1 : (pth->effects == hictinting[dapalnum].f)) &&
132
            (pth->flags & (PTH_CLAMPED + PTH_HIGHTILE + PTH_SKYBOX)) ==
129
            (pth->flags & (PTH_CLAMPED + PTH_HIGHTILE + PTH_SKYBOX)) ==
133
            (TO_PTH_CLAMPED(dameth) + PTH_HIGHTILE + (drawingskybox > 0) * PTH_SKYBOX) &&
130
            (TO_PTH_CLAMPED(dameth) + PTH_HIGHTILE + (drawingskybox > 0) * PTH_SKYBOX) &&
Line 135... Line 132...
135
        {
132
        {
136
            if (pth->flags & PTH_INVALIDATED)
133
            if (pth->flags & PTH_INVALIDATED)
137
            {
134
            {
138
                pth->flags &= ~PTH_INVALIDATED;
135
                pth->flags &= ~PTH_INVALIDATED;
139
136
140
                tilestat = gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 0,
137
                int32_t tilestat = gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 0,
141
                                        (si->palnum > 0) ? 0 : hictinting[dapalnum].f);  // reload tile
138
                                        (si->palnum > 0) ? 0 : hictinting[dapalnum].f);  // reload tile
142
139
143
                if (!tilestat)
140
                if (!tilestat)
144
                    continue;
141
                    continue;
145
142
146
                if (tilestat == -2)  // bad filename
143
                if (tilestat == -2)  // bad filename
147
                    hicclearsubst(dapicnum, dapalnum);
144
                    hicclearsubst(dapicnum, dapalnum);
148
                return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth);
145
                return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth);
149
            }
146
            }
150
147
151
            return (pth);
148
            return pth;
152
        }
149
        }
153
    }
150
    }
154
151
155
    pth = (pthtyp *)Xcalloc(1, sizeof(pthtyp));
152
    pthtyp *pth = (pthtyp *)Xcalloc(1, sizeof(pthtyp));
156
153
157
    // possibly fetch an already loaded multitexture :_)
154
    // possibly fetch an already loaded multitexture :_)
158
    if (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS) && texcache_fetchmulti(pth, si, dapicnum, dameth))
155
    if (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS) && texcache_fetchmulti(pth, si, dapicnum, dameth))
159
        return pth;
156
        return pth;
160
157
161
    tilestat =
158
    int32_t tilestat =
162
    gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 1, (si->palnum > 0) ? 0 : hictinting[dapalnum].f);
159
    gloadtile_hi(dapicnum, dapalnum, drawingskybox, si, dameth, pth, 1, (si->palnum > 0) ? 0 : hictinting[dapalnum].f);
163
160
164
    if (!tilestat)
161
    if (!tilestat)
165
    {
162
    {
166
        pth->next = texcache.list[j];
163
        pth->next = texcache.list[j];
Line 529... Line 526...
529
{
526
{
530
    static GLint glGetTexLevelParameterivOK = GL_TRUE;
527
    static GLint glGetTexLevelParameterivOK = GL_TRUE;
531
    char cachefn[BMAX_PATH];
528
    char cachefn[BMAX_PATH];
532
    char *pic = NULL, *packbuf = NULL;
529
    char *pic = NULL, *packbuf = NULL;
533
    void *midbuf = NULL;
530
    void *midbuf = NULL;
534
    uint32_t alloclen=0, level;
531
    uint32_t alloclen=0, level=0;
535
    uint32_t padx=0, pady=0;
532
    uint32_t padx=0, pady=0;
536
    GLint gi;
533
    GLint gi;
537
    int32_t offset = 0;
534
    int32_t offset = 0;
538
535
539
    if (!texcache_enabled()) return;
536
    if (!texcache_enabled()) return;
540
537
-
 
538
#ifndef EDUKE32_GLES
541
    gi = GL_FALSE;
539
    gi = GL_FALSE;
542
    bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi);
540
    bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi);
543
    if (gi != GL_TRUE)
541
    if (gi != GL_TRUE)
544
    {
542
    {
545
        if (glGetTexLevelParameterivOK == GL_TRUE)
543
        if (glGetTexLevelParameterivOK == GL_TRUE)
Line 547... Line 545...
547
            OSD_Printf("Error: glGetTexLevelParameteriv returned GL_FALSE!\n");
545
            OSD_Printf("Error: glGetTexLevelParameteriv returned GL_FALSE!\n");
548
            glGetTexLevelParameterivOK = GL_FALSE;
546
            glGetTexLevelParameterivOK = GL_FALSE;
549
        }
547
        }
550
        return;
548
        return;
551
    }
549
    }
-
 
550
#endif
552
551
553
    Blseek(texcache.filehandle, 0, BSEEK_END);
552
    Blseek(texcache.filehandle, 0, BSEEK_END);
554
553
555
    offset = Blseek(texcache.filehandle, 0, BSEEK_CUR);
554
    offset = Blseek(texcache.filehandle, 0, BSEEK_CUR);
556
    //    OSD_Printf("Caching %s, offset 0x%x\n", cachefn, offset);
555
    //    OSD_Printf("Caching %s, offset 0x%x\n", cachefn, offset);
Line 568... Line 567...
568
567
569
    if (Bwrite(texcache.filehandle, head, sizeof(texcacheheader)) != sizeof(texcacheheader)) goto failure;
568
    if (Bwrite(texcache.filehandle, head, sizeof(texcacheheader)) != sizeof(texcacheheader)) goto failure;
570
569
571
    CLEAR_GL_ERRORS();
570
    CLEAR_GL_ERRORS();
572
571
-
 
572
#ifndef EDUKE32_GLES
573
    for (level = 0; level==0 || (padx > 1 || pady > 1); level++)
573
    for (level = 0; level==0 || (padx > 1 || pady > 1); level++)
-
 
574
#endif
574
    {
575
    {
575
        uint32_t miplen;
576
        uint32_t miplen;
576
        texcachepicture pict;
577
        texcachepicture pict;
577
578
-
 
579
#ifndef EDUKE32_GLES
578
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_ARB, &gi); WRITEX_FAIL_ON_ERROR();
580
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_ARB, &gi); WRITEX_FAIL_ON_ERROR();
579
        if (gi != GL_TRUE) goto failure;   // an uncompressed mipmap
581
        if (gi != GL_TRUE) goto failure;   // an uncompressed mipmap
580
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &gi); WRITEX_FAIL_ON_ERROR();
582
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &gi); WRITEX_FAIL_ON_ERROR();
581
583
582
#ifdef __APPLE__
584
#ifdef __APPLE__
Line 592... Line 594...
592
        pict.border = B_LITTLE32(gi);
594
        pict.border = B_LITTLE32(gi);
593
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_DEPTH, &gi); WRITEX_FAIL_ON_ERROR();
595
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_DEPTH, &gi); WRITEX_FAIL_ON_ERROR();
594
        pict.depth = B_LITTLE32(gi);
596
        pict.depth = B_LITTLE32(gi);
595
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &gi); WRITEX_FAIL_ON_ERROR();
597
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &gi); WRITEX_FAIL_ON_ERROR();
596
        miplen = gi; pict.size = B_LITTLE32(gi);
598
        miplen = gi; pict.size = B_LITTLE32(gi);
-
 
599
#else // TODO: actually code this ;)
-
 
600
//        pict.format = GL_ETC1_RGB8_OES;
-
 
601
        pict.xdim = head->xdim;
-
 
602
        pict.ydim = head->ydim;
-
 
603
        pict.border = 0;
-
 
604
        pict.depth = 16;
597
605
#endif
598
        if (alloclen < miplen)
606
        if (alloclen < miplen)
599
        {
607
        {
600
            pic = (char *)Xrealloc(pic, miplen);
608
            pic = (char *)Xrealloc(pic, miplen);
601
            alloclen = miplen;
609
            alloclen = miplen;
602
            packbuf = (char *)Xrealloc(packbuf, alloclen);
610
            packbuf = (char *)Xrealloc(packbuf, alloclen);
Line 641... Line 649...
641
        if (texcache.index)
649
        if (texcache.index)
642
        {
650
        {
643
            fseek(texcache.index, 0, BSEEK_END);
651
            fseek(texcache.index, 0, BSEEK_END);
644
            Bfprintf(texcache.index, "%s %d %d\n", t->name, t->offset, t->len);
652
            Bfprintf(texcache.index, "%s %d %d\n", t->name, t->offset, t->len);
645
        }
653
        }
-
 
654
        else
646
        else OSD_Printf("wtf?\n");
655
            OSD_Printf("wtf?\n");
647
    }
656
    }
648
657
649
    goto success;
658
    goto success;
650
659
651
failure:
660
failure:
Line 669... Line 678...
669
    bglBindTexture(GL_TEXTURE_2D,*glpic);
678
    bglBindTexture(GL_TEXTURE_2D,*glpic);
670
}
679
}
671
680
672
static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int32_t *xsiz, int32_t *ysiz)
681
static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int32_t *xsiz, int32_t *ysiz)
673
{
682
{
674
    int32_t level;
683
    int32_t level = 0;
675
    texcachepicture pict;
684
    texcachepicture pict;
676
    char *pic = NULL, *packbuf = NULL;
685
    char *pic = NULL, *packbuf = NULL;
677
    void *midbuf = NULL;
686
    void *midbuf = NULL;
678
    int32_t alloclen=0;
687
    int32_t alloclen=0;
679
688
-
 
689
#ifndef EDUKE32_GLES
680
    for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++)
690
    for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++)
-
 
691
#endif
681
    {
692
    {
682
        GLint format;
693
        GLint format;
683
694
684
        if (texcache_readdata(&pict, sizeof(texcachepicture)))
695
        if (texcache_readdata(&pict, sizeof(texcachepicture)))
685
        {
696
        {
Line 721... Line 732...
721
        {
732
        {
722
            TEXCACHE_FREEBUFS();
733
            TEXCACHE_FREEBUFS();
723
            return TEXCACHERR_COMPTEX;
734
            return TEXCACHERR_COMPTEX;
724
        }
735
        }
725
736
-
 
737
#ifndef EDUKE32_GLES
726
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &format);
738
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &format);
727
        if ((*glerr = bglGetError()) != GL_NO_ERROR)
739
        if ((*glerr = bglGetError()) != GL_NO_ERROR)
728
        {
740
        {
729
            TEXCACHE_FREEBUFS();
741
            TEXCACHE_FREEBUFS();
730
            return TEXCACHERR_GETTEXLEVEL;
742
            return TEXCACHERR_GETTEXLEVEL;
Line 734... Line 746...
734
        {
746
        {
735
            OSD_Printf("gloadtile_cached: invalid texture cache file format %d %d\n", pict.format, format);
747
            OSD_Printf("gloadtile_cached: invalid texture cache file format %d %d\n", pict.format, format);
736
            TEXCACHE_FREEBUFS();
748
            TEXCACHE_FREEBUFS();
737
            return -1;
749
            return -1;
738
        }
750
        }
-
 
751
#endif
739
    }
752
    }
740
753
741
    TEXCACHE_FREEBUFS();
754
    TEXCACHE_FREEBUFS();
742
    return 0;
755
    return 0;
743
}
756
}