MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / UploadToGPU

Method UploadToGPU

engine/PoseidonGL33/TextureGL33_Loading.cpp:39–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 if (interpolate && IsCompressedInterpolationFormat(format))
38 return PacARGB1555;
39 return format;
40}
41
42void TextureGL33::InitDesc(TextureDescGL33& desc, int levelMin, bool enableDXT)
43{
44 memset(&desc, 0, sizeof(desc));
45
46 PacFormat format = UploadFormatForTextureGL33(_mipmaps[levelMin].DstFormat(), _interpolate);
47 InitGLPixelFormat(desc, format, enableDXT);
48
49 desc.w = _mipmaps[levelMin]._w;
50 desc.h = _mipmaps[levelMin]._h;
51 desc.nMipmaps = _nMipmaps - levelMin;
52}
53
54int TextureGL33::TotalSize(int levelMin) const
55{
56 int totalSize = 0;
57 for (int i = levelMin; i < _nMipmaps; i++)
58 {
59 const PacLevelMem& mip = _mipmaps[i];
60 totalSize += MipmapSizeGL33(UploadFormatForTextureGL33(_mipmaps[levelMin].DstFormat(), _interpolate), mip._w,
61 mip._h);
62 }
63 return totalSize;
64}
65
66int TextureGL33::UploadToGPU(SurfaceInfoGL33& surface, int levelMin)
67{
68 if (!_src)
69 {
70 RptF("No texture source for %s", Name());
71 return -1;
72 }
73
74 unsigned int tex = surface.GetTexture();
75 if (!tex)
76 return -1;
77
78 // Upload via the dedicated upload unit so cached unit-0/1 bindings
79 // tracked by ApplyPassState/_lastHandle remain accurate (otherwise a
80 // demand-load between two draws of the same texture leaves GL bound to
81 // the just-uploaded handle while the cache claims the previous binding,
82 // and the next ApplyPassState skips the rebind — visible as the
83 // M113-track-wheel "blink").
84 GL33Bind::Tex2D(EngineGL33::kUploadUnit - GL_TEXTURE0, tex);
85 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
86 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
87
88 // Capture the format once at level-min and reuse for every mip.
89 // Per-mip DstFormat() can occasionally diverge from the level-min
90 // (mixed-format PAAs are rare but legal), and CreateSurface in
91 // TextureGL33_Init.cpp allocates *every* mip level with the
92 // level-min format — uploading a sub-image with a different
93 // compressed internalFormat trips GL_INVALID_OPERATION (0x0502).
94 // Treat level-min as authoritative; the data buffer for each mip
95 // is the right size for that format (size math below uses it).
96 const PacFormat sharedFmt = UploadFormatForTextureGL33(_mipmaps[levelMin].DstFormat(), _interpolate);

Callers

nothing calls this directly

Calls 8

Tex2DFunction · 0.85
ComputeLayoutFunction · 0.85
WarningMessageFunction · 0.85
InitGLPixelFormatFunction · 0.85
ActiveUnitFunction · 0.85
DstFormatMethod · 0.80
GetTextureMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected