Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla RPC Texture

From Leeroopedia
Revision as of 12:14, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CARLA_simulator_Carla_RPC_Texture.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Rendering, RPC Serialization
Last Updated 2026-02-15 05:00 GMT

Overview

Texture is a template class for RPC-serializable 2D texture data, with type aliases for color (RGBA) and float-color textures used in CARLA's material and rendering system.

Description

Defined in the carla::rpc namespace (~70 lines), the Texture<T> template class stores a 2D grid of pixel values of type T. It manages width, height, and a flat std::vector<T> buffer. Access is provided via At(x, y) for per-pixel read/write, GetDataPtr() for raw pointer access, and SetDimensions(w, h) for resizing. The class is MsgPack-serializable with width, height, and texture data.

Two type aliases are defined:

  • TextureColor: Texture<sensor::data::Color> for 8-bit RGBA pixel data
  • TextureFloatColor: Texture<FloatColor> for floating-point color data

Usage

Use this type when applying or retrieving textures via the CARLA RPC interface, such as changing material textures on actors or retrieving rendered images.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/rpc/Texture.h

Signature

namespace carla {
namespace rpc {

  template<typename T>
  class Texture {
  public:
    Texture() = default;
    Texture(uint32_t width, uint32_t height);

    uint32_t GetWidth() const;
    uint32_t GetHeight() const;
    void SetDimensions(uint32_t width, uint32_t height);
    T& At(uint32_t x, uint32_t y);
    const T& At(uint32_t x, uint32_t y) const;
    const T* GetDataPtr() const;

    MSGPACK_DEFINE_ARRAY(_width, _height, _texture_data);
  private:
    uint32_t _width = 0;
    uint32_t _height = 0;
    std::vector<T> _texture_data;
  };

  using TextureColor = Texture<sensor::data::Color>;
  using TextureFloatColor = Texture<FloatColor>;

} // namespace rpc
} // namespace carla

Import

#include "carla/rpc/Texture.h"

I/O Contract

Method Return Type Description
GetWidth() uint32_t Returns texture width in pixels
GetHeight() uint32_t Returns texture height in pixels
SetDimensions(w, h) void Resizes the texture buffer
At(x, y) T& Accesses pixel at (x, y)
GetDataPtr() const T* Returns raw pointer to texture data

Usage Examples

#include "carla/rpc/Texture.h"

// Create a 256x256 color texture
carla::rpc::TextureColor texture(256, 256);

// Set pixel to red
texture.At(0, 0) = carla::sensor::data::Color{255, 0, 0, 255};

// Access raw data pointer
const auto* data = texture.GetDataPtr();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment