MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / opengl_TranslateBitmapToOpenGL

Function opengl_TranslateBitmapToOpenGL

renderer/HardwareOpenGL.cpp:880–1069  ·  view source on GitHub ↗

Takes our 16bit format and converts it into the memory scheme that OpenGL wants

Source from the content-addressed store, hash-verified

878
879// Takes our 16bit format and converts it into the memory scheme that OpenGL wants
880void opengl_TranslateBitmapToOpenGL(int texnum, int bm_handle, int map_type, int replace, int tn) {
881 uint16_t *bm_ptr;
882
883 int w, h;
884 int size;
885
886 if (UseMultitexture && Last_texel_unit_set != tn) {
887#if (defined(_USE_OGL_ACTIVE_TEXTURES))
888 oglActiveTextureARB(GL_TEXTURE0_ARB + tn);
889 Last_texel_unit_set = tn;
890#endif
891 }
892
893 if (map_type == MAP_TYPE_LIGHTMAP) {
894 if (GameLightmaps[bm_handle].flags & LF_BRAND_NEW)
895 replace = 0;
896
897 bm_ptr = lm_data(bm_handle);
898 GameLightmaps[bm_handle].flags &= ~(LF_CHANGED | LF_BRAND_NEW);
899
900 w = lm_w(bm_handle);
901 h = lm_h(bm_handle);
902 size = GameLightmaps[bm_handle].square_res;
903 } else {
904 if (GameBitmaps[bm_handle].flags & BF_BRAND_NEW)
905 replace = 0;
906
907 bm_ptr = bm_data(bm_handle, 0);
908 GameBitmaps[bm_handle].flags &= ~(BF_CHANGED | BF_BRAND_NEW);
909 w = bm_w(bm_handle, 0);
910 h = bm_h(bm_handle, 0);
911 size = w;
912 }
913
914 if (OpenGL_last_bound[tn] != texnum) {
915 dglBindTexture(GL_TEXTURE_2D, texnum);
916 OpenGL_sets_this_frame[0]++;
917 OpenGL_last_bound[tn] = texnum;
918 }
919
920 int i;
921
922 if (OpenGL_packed_pixels) {
923 if (map_type == MAP_TYPE_LIGHTMAP) {
924 uint16_t *left_data = (uint16_t *)opengl_packed_Upload_data;
925 int bm_left = 0;
926
927 for (int i = 0; i < h; i++, left_data += size, bm_left += w) {
928 uint16_t *dest_data = left_data;
929 for (int t = 0; t < w; t++) {
930 *dest_data++ = opengl_packed_Translate_table[bm_ptr[bm_left + t]];
931 }
932 }
933
934 if (replace) {
935 dglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
936 opengl_packed_Upload_data);
937 } else {

Callers 1

opengl_MakeBitmapCurrentFunction · 0.70

Calls 8

lm_dataFunction · 0.85
lm_wFunction · 0.85
lm_hFunction · 0.85
bm_dataFunction · 0.85
bm_wFunction · 0.85
bm_hFunction · 0.85
bm_mippedFunction · 0.85
bm_formatFunction · 0.85

Tested by

no test coverage detected