texture: fix get_clear_data() return type, make it work with sRGB
This commit is contained in:
parent
e4e24eee56
commit
e9a50c8898
|
|
@ -12323,20 +12323,20 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
|
|||
if (_supports_clear_texture) {
|
||||
// We can do that with the convenient glClearTexImage
|
||||
// function.
|
||||
string clear_data = tex->get_clear_data();
|
||||
vector_uchar clear_data = tex->get_clear_data();
|
||||
|
||||
_glClearTexImage(gtc->_index, n - mipmap_bias, external_format,
|
||||
component_type, (void *)clear_data.data());
|
||||
component_type, (void *)&clear_data[0]);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (_supports_clear_buffer) {
|
||||
// For buffer textures we need to clear the underlying
|
||||
// storage.
|
||||
string clear_data = tex->get_clear_data();
|
||||
vector_uchar clear_data = tex->get_clear_data();
|
||||
|
||||
_glClearBufferData(GL_TEXTURE_BUFFER, internal_format, external_format,
|
||||
component_type, (const void *)clear_data.data());
|
||||
component_type, (const void *)&clear_data[0]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -279,12 +279,12 @@ clear_clear_color() {
|
|||
* Returns the raw image data for a single pixel if it were set to the clear
|
||||
* color.
|
||||
*/
|
||||
INLINE string Texture::
|
||||
INLINE vector_uchar Texture::
|
||||
get_clear_data() const {
|
||||
CDReader cdata(_cycler);
|
||||
unsigned char data[16];
|
||||
size_t size = do_get_clear_data(cdata, data);
|
||||
return string((char *)data, size);
|
||||
vector_uchar data(16);
|
||||
data.resize(do_get_clear_data(cdata, &data[0]));
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5584,10 +5584,28 @@ do_get_clear_data(const CData *cdata, unsigned char *into) const {
|
|||
nassertr(cdata->_has_clear_color, 0);
|
||||
nassertr(cdata->_num_components <= 4, 0);
|
||||
|
||||
// TODO: encode the color into the sRGB color space if used
|
||||
switch (cdata->_component_type) {
|
||||
case T_unsigned_byte:
|
||||
{
|
||||
if (is_srgb(cdata->_format)) {
|
||||
xel color;
|
||||
xelval alpha;
|
||||
encode_sRGB_uchar(cdata->_clear_color, color, alpha);
|
||||
switch (cdata->_num_components) {
|
||||
case 2:
|
||||
into[1] = (unsigned char)color.g;
|
||||
case 1:
|
||||
into[0] = (unsigned char)color.r;
|
||||
break;
|
||||
case 4:
|
||||
into[3] = (unsigned char)alpha;
|
||||
case 3: // BGR <-> RGB
|
||||
into[0] = (unsigned char)color.b;
|
||||
into[1] = (unsigned char)color.g;
|
||||
into[2] = (unsigned char)color.r;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
LColor scaled = cdata->_clear_color.fmin(LColor(1)).fmax(LColor::zero());
|
||||
scaled *= 255;
|
||||
switch (cdata->_num_components) {
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ PUBLISHED:
|
|||
INLINE LColor get_clear_color() const;
|
||||
INLINE void set_clear_color(const LColor &color);
|
||||
INLINE void clear_clear_color();
|
||||
INLINE string get_clear_data() const;
|
||||
INLINE vector_uchar get_clear_data() const;
|
||||
MAKE_PROPERTY2(clear_color, has_clear_color, get_clear_color,
|
||||
set_clear_color, clear_clear_color);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue