- Timestamp:
- 01/12/17 19:15:29 (8 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/engine/material_manager.cc
r517 r535 19 19 uint8 data[2 * 2 * 4]; 20 20 nv::raw_fill_n( data, 2 * 2 * 4, 0 ); 21 m_default = m_context->create_texture( ivec2(2,2), nv:: image_format( nv::RGBA ), nv::sampler(), data );21 m_default = m_context->create_texture( ivec2(2,2), nv::RGBA8, nv::sampler(), data ); 22 22 } 23 23 -
trunk/src/engine/shadow.cc
r508 r535 12 12 { 13 13 m_map_size = map_size; 14 m_maps = context->create_texture( TEXTURE_2D_ARRAY, ivec3( map_size, map_size, count ), image_format( DEPTH24, UINT ), sampler( sampler::LINEAR, sampler::CLAMP_TO_EDGE ), nullptr );14 m_maps = context->create_texture( TEXTURE_2D_ARRAY, ivec3( map_size, map_size, count ), DEPTH24, sampler( sampler::LINEAR, sampler::CLAMP_TO_EDGE ), nullptr ); 15 15 m_passes.resize( count ); 16 16 for ( uint32 i = 0; i < count; ++i ) … … 32 32 void nv::shadow_data::initialize( context* context, uint32 count, uint32 map_size, const render_pass& pass_base, const render_pass& color_base ) 33 33 { 34 m_color_maps = context->create_texture( TEXTURE_2D_ARRAY, ivec3( map_size, map_size, count ), image_format( RGBA16F, FLOAT ), sampler( sampler::LINEAR, sampler::CLAMP_TO_EDGE ), nullptr );34 m_color_maps = context->create_texture( TEXTURE_2D_ARRAY, ivec3( map_size, map_size, count ), RGBA16F, sampler( sampler::LINEAR, sampler::CLAMP_TO_EDGE ), nullptr ); 35 35 36 36 initialize( context, count, map_size, pass_base ); -
trunk/src/gl/gl_context.cc
r534 r535 126 126 } 127 127 128 nv::image_data* nv::gl_context::dump_image( image_format f, image_data* reuse ) 129 { 130 NV_ASSERT_ALWAYS( f.type == nv::UBYTE, "Bad format passed to dump" ); 131 NV_ASSERT_ALWAYS( f.format == nv::RGB || f.format == nv::RGBA, "Bad format passed to dump" ); 128 nv::image_data* nv::gl_context::dump_image( pixel_format format, image_data* reuse ) 129 { 130 NV_ASSERT_ALWAYS( format == nv::RGB8 || format == nv::RGBA8, "Bad format passed to dump" ); 132 131 glPixelStorei( GL_PACK_ALIGNMENT, 1 ); 133 132 image_data* result = reuse; 134 if ( !result ) result = new image_data( f, ivec2( m_viewport.z, m_viewport.w ) ); 135 glReadPixels( 0, 0, m_viewport.z, m_viewport.w, f.format == nv::RGB ? GL_RGB : GL_RGBA, datatype_to_gl_enum( f.type ), const_cast< uint8* >( result->get_data() ) ); 133 datatype type = get_pixel_format_info( format ).type; 134 if ( !result ) result = new image_data( format, ivec2( m_viewport.z, m_viewport.w ) ); 135 glReadPixels( 0, 0, m_viewport.z, m_viewport.w, format == nv::RGB8 ? GL_RGB : GL_RGBA, datatype_to_gl_enum( type ), const_cast< uint8* >( result->get_data() ) ); 136 136 return result; 137 137 } … … 307 307 NV_ASSERT_ALWAYS( binfo->type == TEXTURE_BUFFER && tinfo->type == TEXTURE_1D_BUFFER, "bad texture or buffer type!" ); 308 308 bind( t, TEXTURE_0 ); 309 glTexBuffer( GL_TEXTURE_BUFFER, image_format_to_internal_enum( tinfo->format .format), binfo->glid );309 glTexBuffer( GL_TEXTURE_BUFFER, image_format_to_internal_enum( tinfo->format ), binfo->glid ); 310 310 } 311 311 } … … 451 451 if ( info ) 452 452 { 453 image_format format = info->format; 453 pixel_format format = info->format; 454 datatype type = get_pixel_format_info( format ).type; 454 455 ivec3 size = info->size; 455 456 unsigned gl_type = texture_type_to_enum( info->type ); … … 457 458 bind( t, texture_slot::TEXTURE_0 ); 458 459 if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY ) 459 // glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format .format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data );460 glTexSubImage3D( gl_type, 0, 0, 0, 0, size.x, size.y, size.z, nv::image_format_to_enum( format .format ), nv::datatype_to_gl_enum( format.type ), data );460 // glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format ), nv::datatype_to_gl_enum( type ), data ); 461 glTexSubImage3D( gl_type, 0, 0, 0, 0, size.x, size.y, size.z, nv::image_format_to_enum( format ), nv::datatype_to_gl_enum( type ), data ); 461 462 else 462 // glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format .format) ), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data );463 glTexSubImage2D( gl_type, 0, 0, 0, size.x, size.y, nv::image_format_to_enum( format .format ), nv::datatype_to_gl_enum( format.type ), data );463 // glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format) ), size.x, size.y, 0, nv::image_format_to_enum(format), nv::datatype_to_gl_enum(type), data ); 464 glTexSubImage2D( gl_type, 0, 0, 0, size.x, size.y, nv::image_format_to_enum( format ), nv::datatype_to_gl_enum( type ), data ); 464 465 } 465 466 } … … 898 899 } 899 900 900 nv::texture nv::gl_context::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )901 { 902 texture result = create_texture( type, aformat .format);901 nv::texture nv::gl_context::create_texture( texture_type type, ivec2 size, pixel_format aformat, sampler asampler, const void* data /*= nullptr */ ) 902 { 903 texture result = create_texture( type, aformat ); 903 904 gl_texture_info* info = static_cast<gl_device*>( m_device )->get_full_texture_info( result ); 904 905 bind( result, texture_slot::TEXTURE_0 ); 905 906 unsigned glid = info->glid; 906 907 unsigned gl_type = texture_type_to_enum( type ); 907 GLenum gl_internal = GLenum( image_format_to_internal_enum( aformat .format) );908 unsigned gl_enum = image_format_to_enum( aformat .format);909 910 bool is_depth = aformat .format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;908 GLenum gl_internal = GLenum( image_format_to_internal_enum( aformat ) ); 909 unsigned gl_enum = image_format_to_enum( aformat ); 910 911 bool is_depth = aformat == DEPTH16 || aformat == DEPTH24 || aformat == DEPTH32; 911 912 912 913 // Detect if mipmapping was requested … … 953 954 954 955 if ( gl_type != GL_TEXTURE_2D_MULTISAMPLE ) 955 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum( aformat.type ), data );956 glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum( get_pixel_format_info( aformat ).type ), data ); 956 957 else 957 958 glTexImage2DMultisample( gl_type, 4, gl_internal, size.x, size.y, 1 ); … … 974 975 } 975 976 976 nv::texture nv::gl_context::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )977 { 978 texture result = create_texture( type, aformat .format);977 nv::texture nv::gl_context::create_texture( texture_type type, ivec3 size, pixel_format aformat, sampler asampler, const void* data /*= nullptr */ ) 978 { 979 texture result = create_texture( type, aformat ); 979 980 gl_texture_info* info = static_cast<gl_device*>( m_device )->get_full_texture_info( result ); 980 981 bind( result, texture_slot::TEXTURE_0 ); … … 983 984 unsigned gl_type = texture_type_to_enum( type ); 984 985 985 bool is_depth = aformat .format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;986 bool is_depth = aformat == DEPTH16 || aformat == DEPTH24 || aformat == DEPTH32; 986 987 987 988 if ( asampler.filter_max != sampler::NEAREST ) … … 1007 1008 1008 1009 //glTexStorage3D( GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, layerCount ); 1009 glTexImage3D( gl_type, 0, GLint( nv::image_format_to_internal_enum( aformat .format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( aformat.format ), nv::datatype_to_gl_enum( aformat.type ), data );1010 glTexImage3D( gl_type, 0, GLint( nv::image_format_to_internal_enum( aformat ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( aformat ), nv::datatype_to_gl_enum( get_pixel_format_info( aformat ).type ), data ); 1010 1011 1011 1012 bind( texture(), texture_slot::TEXTURE_0 ); -
trunk/src/gl/gl_device.cc
r534 r535 36 36 } 37 37 // TODO: BGR vs RGB, single channel 38 pixel_format pformat = RGBA ;38 pixel_format pformat = RGBA8; 39 39 switch ( image->format->BytesPerPixel ) 40 40 { 41 case 4: pformat = RGBA ; break;42 case 3: pformat = RGB ; break;43 case 1: pformat = R ED; break;41 case 4: pformat = RGBA8; break; 42 case 3: pformat = RGB8; break; 43 case 1: pformat = R8; break; 44 44 default: NV_ASSERT( false, "BytesPerPixel != 4,3 or 1!" ); 45 45 } 46 image_format format( pformat, UBYTE ); 47 image_data* data = new image_data( format, ivec2( image->w, image->h ), static_cast<nv::uint8*>( image->pixels ) ); 46 image_data* data = new image_data( pformat, ivec2( image->w, image->h ), static_cast<nv::uint8*>( image->pixels ) ); 48 47 return data; 49 48 } … … 62 61 // TODO: BGR vs RGB, single channel 63 62 NV_ASSERT( image->format->BytesPerPixel > 2, "bytes per pixel > 2!" ); 64 image_format format( image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE);63 pixel_format format( image->format->BytesPerPixel == 3 ? RGB8 : RGBA8 ); 65 64 image_data* idata = new image_data( format, ivec2( image->w, image->h ), static_cast<nv::uint8*>( image->pixels ) ); 66 65 return idata; -
trunk/src/gl/gl_enum.cc
r506 r535 182 182 switch( format ) 183 183 { 184 case RGB : return GL_RGB; 185 case RGBA : return GL_RGBA; 184 case RGB8 : return GL_RGB; 185 case RGBA8 : return GL_RGBA; 186 case R8 : return GL_RED; 186 187 case RGB32F : return GL_RGB; 187 188 case RGBA32F : return GL_RGBA; 188 189 case RGB16F : return GL_RGB; 189 190 case RGBA16F : return GL_RGBA; 190 case BGR : return GL_BGR; 191 case BGRA : return GL_BGRA; 192 case RED : return GL_RED; 191 case BGR8 : return GL_BGR; 192 case BGRA8 : return GL_BGRA; 193 193 case R16F : return GL_RED; 194 194 case R32F : return GL_RED; … … 202 202 case R32I : return GL_RED_INTEGER; 203 203 case R32UI : return GL_RED_INTEGER; 204 case RGBA8I : return GL_RGBA ;205 case RGBA8UI : return GL_RGBA ;206 case RGBA16I : return GL_RGBA ;207 case RGBA16UI: return GL_RGBA ;208 case RGBA32I : return GL_RGBA ;209 case RGBA32UI: return GL_RGBA ;204 case RGBA8I : return GL_RGBA_INTEGER; 205 case RGBA8UI : return GL_RGBA_INTEGER; 206 case RGBA16I : return GL_RGBA_INTEGER; 207 case RGBA16UI: return GL_RGBA_INTEGER; 208 case RGBA32I : return GL_RGBA_INTEGER; 209 case RGBA32UI: return GL_RGBA_INTEGER; 210 210 NV_RETURN_COVERED_DEFAULT( 0 ); 211 211 } … … 216 216 switch( format ) 217 217 { 218 case RGB : return GL_RGB8; 219 case RGBA : return GL_RGBA8; 218 case RGB8 : return GL_RGB8; 219 case RGBA8 : return GL_RGBA8; 220 case R8 : return GL_R8; 220 221 case RGB32F : return GL_RGB32F; 221 222 case RGBA32F : return GL_RGBA32F; 222 223 case RGB16F : return GL_RGBA16F; 223 224 case RGBA16F : return GL_RGBA16F; 224 case BGR : return GL_RGB8; 225 case BGRA : return GL_RGBA8; 226 case RED : return GL_R8; 225 case BGR8 : return GL_RGB8; 226 case BGRA8 : return GL_RGBA8; 227 227 case R16F : return GL_R16F; 228 228 case R32F : return GL_R32F; 229 229 case DEPTH16 : return GL_DEPTH_COMPONENT16; 230 230 case DEPTH24 : return GL_DEPTH_COMPONENT24; 231 case DEPTH32 : return GL_DEPTH_COMPONENT32;231 case DEPTH32 : return GL_DEPTH_COMPONENT32; 232 232 case R8I : return GL_R8I; 233 233 case R8UI : return GL_R8UI; -
trunk/src/gui/gui_gfx_renderer.cc
r534 r535 166 166 167 167 nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE ); 168 sr->tex = m_window->get_context()->create_texture( m_atlas.get_size(), image_format( nv::RGBA, nv::UBYTE ), sampler, nullptr );168 sr->tex = m_window->get_context()->create_texture( m_atlas.get_size(), nv::RGBA8, sampler, nullptr ); 169 169 170 170 m_render_state.depth_test.enabled = false; -
trunk/src/image/png_loader.cc
r534 r535 1015 1015 png_loader::png_loader() {} 1016 1016 1017 bool nv::png_loader::get_info( stream& str, image_format& format, ivec2& size )1017 bool nv::png_loader::get_info( stream& str, pixel_format& format, ivec2& size ) 1018 1018 { 1019 1019 size_t pos = str.tell(); … … 1024 1024 { 1025 1025 str.seek( (long)pos, origin::SET ); 1026 format.type = UBYTE;1027 1026 switch ( comp ) 1028 1027 { 1029 1028 case 0: return false; 1030 case 1: format .format = RED; break;1031 case 3: format .format = RGB; break;1032 case 4: format .format = RGBA; break;1029 case 1: format = R8; break; 1030 case 3: format = RGB8; break; 1031 case 4: format = RGBA8; break; 1033 1032 default: return false; 1034 1033 } … … 1057 1056 // need to 'unget' all the characters in the IO buffer 1058 1057 s.seek( -ctx.remaining(), origin::CUR ); 1059 image_format format;1058 pixel_format format; 1060 1059 ivec2 size; 1061 format.type = UBYTE;1062 1060 switch ( comp ) 1063 1061 { 1064 case 1: format .format = RED; break;1065 case 3: format .format = RGB; break;1066 case 4: format .format = RGBA; break;1062 case 1: format = R8; break; 1063 case 3: format = RGB8; break; 1064 case 4: format = RGBA8; break; 1067 1065 default: return nullptr; 1068 1066 } … … 1073 1071 } 1074 1072 1075 image_data* nv::png_loader::load( stream& s, image_format format ) 1076 { 1077 NV_ASSERT( format.type == UBYTE, "!" ); 1073 image_data* nv::png_loader::load( stream& s, pixel_format format ) 1074 { 1078 1075 int rcomp = 0; 1079 switch ( format .format)1080 { 1081 case R ED: rcomp = 1; break;1082 case RGB : rcomp = 3; break;1083 case RGBA : rcomp = 4; break;1076 switch ( format ) 1077 { 1078 case R8: rcomp = 1; break; 1079 case RGB8: rcomp = 3; break; 1080 case RGBA8: rcomp = 4; break; 1084 1081 default: NV_ASSERT( false, "bad format requested!" ); return nullptr; 1085 1082 } … … 1091 1088 { 1092 1089 s.seek( -ctx.remaining(), origin::CUR ); 1093 image_format fmt;1090 pixel_format fmt; 1094 1091 ivec2 sz; 1095 fmt.type = UBYTE;1096 1092 switch ( comp ) 1097 1093 { 1098 case 1: fmt .format = RED; break;1099 case 3: fmt .format = RGB; break;1100 case 4: fmt .format = RGBA; break;1094 case 1: fmt = R8; break; 1095 case 3: fmt = RGB8; break; 1096 case 4: fmt = RGBA8; break; 1101 1097 default: NV_ASSERT( false, "UNKNOWN RESULT!" ); 1102 1098 }
Note: See TracChangeset
for help on using the changeset viewer.