MCPcopy Create free account
hub / github.com/DavidColson/Polybox / UpdateUserDataImage

Function UpdateUserDataImage

source/userdata.cpp:134–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132// ***********************************************************************
133
134void UpdateUserDataImage(UserData* pUserData) {
135 // @todo: error if userdata type is not suitable for image data
136 // i.e. must be int32 etc and 2D
137
138 if (pUserData->img.id == SG_INVALID_ID ||
139 (pUserData->dirty && pUserData->dynamic == false))
140 {
141 sg_image_desc imageDesc = {
142 .width = pUserData->width,
143 .height = pUserData->height,
144 .pixel_format = SG_PIXELFORMAT_RGBA8,
145 };
146
147 // make dynamic if someone is editing this
148 // image after creation
149 pUserData->dynamic = false;
150 if (pUserData->img.id != SG_INVALID_ID) {
151 sg_destroy_image(pUserData->img);
152 imageDesc.usage = SG_USAGE_STREAM;
153 pUserData->dynamic = true;
154 }
155
156 sg_range pixelsData;
157 pixelsData.ptr = (void*)pUserData->pData;
158 pixelsData.size = pUserData->width * pUserData->height * 4 * sizeof(u8);
159 imageDesc.data.subimage[0][0] = pixelsData;
160 pUserData->img = sg_make_image(&imageDesc);
161 pUserData->dirty = false;
162 }
163
164 // @todo: only allow one edit per frame, somehow block this
165 if (pUserData->dirty && pUserData->dynamic) {
166 // already dynamic, so we can just update it
167 sg_range range;
168 range.ptr = (void*)pUserData->pData;
169 range.size = pUserData->width * pUserData->height * 4 * sizeof(u8);
170 sg_image_data data;
171 data.subimage[0][0] = range;
172 sg_update_image(pUserData->img, data);
173 }
174
175}
176
177// ***********************************************************************
178

Callers 3

LuaBindTextureFunction · 0.85
LuaDrawSpriteFunction · 0.85
LuaDrawSpriteRectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected