@@ -289,4 +289,168 @@ struct rgb_texture
289289 }
290290};
291291
292+
293+ struct custom_texture_base
294+ {
295+ using uninitialized_bytes = boost::container::vector<unsigned char >;
296+ unsigned char * bytes;
297+ int width;
298+ int height;
299+ bool changed;
300+
301+ enum texture_format : uint8_t
302+ {
303+ RGBA8,
304+ BGRA8,
305+ R8,
306+ RG8,
307+ R16,
308+ RG16,
309+ RED_OR_ALPHA8,
310+
311+ RGBA16F,
312+ RGBA32F,
313+ R16F,
314+ R32F,
315+
316+ R8UI,
317+ R32UI,
318+ RG32UI,
319+ RGBA32UI,
320+ };
321+
322+ static constexpr int component_size (texture_format format) noexcept
323+ {
324+ switch (format)
325+ {
326+ case RGBA8:
327+ case BGRA8:
328+ return 1 ;
329+ case R8:
330+ return 1 ;
331+ case RG8:
332+ return 1 ;
333+ case R16:
334+ return 2 ;
335+ case RG16:
336+ return 2 ;
337+ case RED_OR_ALPHA8:
338+ return 1 ;
339+ case RGBA16F:
340+ return 2 ;
341+ case RGBA32F:
342+ return 4 ;
343+ case R16F:
344+ return 2 ;
345+ case R32F:
346+ return 4 ;
347+ case R8UI:
348+ return 1 ;
349+ case R32UI:
350+ return 4 ;
351+ case RG32UI:
352+ return 4 ;
353+ case RGBA32UI:
354+ return 4 ;
355+ default :
356+ return 1 ;
357+ }
358+ }
359+ static constexpr int components (texture_format format) noexcept
360+ {
361+ switch (format)
362+ {
363+ case RGBA8:
364+ case BGRA8:
365+ return 4 ;
366+ case R8:
367+ return 1 ;
368+ case RG8:
369+ return 2 ;
370+ case R16:
371+ return 1 ;
372+ case RG16:
373+ return 2 ;
374+ case RED_OR_ALPHA8:
375+ return 1 ;
376+ case RGBA16F:
377+ return 4 ;
378+ case RGBA32F:
379+ return 4 ;
380+ case R16F:
381+ return 1 ;
382+ case R32F:
383+ return 1 ;
384+ case R8UI:
385+ return 1 ;
386+ case R32UI:
387+ return 1 ;
388+ case RG32UI:
389+ return 2 ;
390+ case RGBA32UI:
391+ return 4 ;
392+ default :
393+ return 1 ;
394+ }
395+ }
396+
397+ void update (unsigned char * data, int w, int h) noexcept
398+ {
399+ bytes = data;
400+ width = w;
401+ height = h;
402+ changed = true ;
403+ }
404+ };
405+
406+ // Use when you want your plugin to request a texture format
407+ // from the host
408+ struct custom_texture : custom_texture_base
409+ {
410+ using custom_texture_base::component_size;
411+ using custom_texture_base::components;
412+ using custom_texture_base::update;
413+
414+ texture_format request_format = RGBA8;
415+
416+ auto bytesize () const noexcept { return bytes_per_pixel () * width * height; }
417+ auto component_size () const noexcept { return bytes_per_pixel () * width * height; }
418+ int bytes_per_pixel () const noexcept
419+ {
420+ return component_size (request_format) * components (request_format);
421+ }
422+
423+ /* FIXME the allocation should not be managed by the plug-in */
424+ auto allocate (int width, int height)
425+ {
426+ using namespace boost ::container;
427+ return uninitialized_bytes (bytesize (), default_init);
428+ }
429+ };
430+
431+ // Use when you want your plugin to receive whatever format
432+ // the host chooses
433+ struct custom_variable_texture : custom_texture_base
434+ {
435+ using custom_texture_base::component_size;
436+ using custom_texture_base::components;
437+ using custom_texture_base::update;
438+
439+ texture_format format = RGBA8;
440+
441+ auto bytesize () const noexcept { return bytes_per_pixel () * width * height; }
442+ auto component_size () const noexcept { return bytes_per_pixel () * width * height; }
443+ int bytes_per_pixel () const noexcept
444+ {
445+ return component_size (format) * components (format);
446+ }
447+
448+ /* FIXME the allocation should not be managed by the plug-in */
449+ auto allocate (int width, int height)
450+ {
451+ using namespace boost ::container;
452+ return uninitialized_bytes (bytesize (), default_init);
453+ }
454+ };
455+
292456}
0 commit comments