From 0b3bdae8e895a1f33bd1a191a052612f4a6f734c Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 15 Jan 2026 09:45:46 +0100 Subject: [PATCH] glgsg: Expose native IDs for other kinds of resources than textures Fixes #1468 --- panda/src/glstuff/glBufferContext_src.cxx | 10 ++++++++++ panda/src/glstuff/glBufferContext_src.h | 2 ++ panda/src/glstuff/glIndexBufferContext_src.cxx | 10 ++++++++++ panda/src/glstuff/glIndexBufferContext_src.h | 2 ++ panda/src/glstuff/glSamplerContext_src.cxx | 10 ++++++++++ panda/src/glstuff/glSamplerContext_src.h | 2 ++ panda/src/glstuff/glVertexBufferContext_src.cxx | 10 ++++++++++ panda/src/glstuff/glVertexBufferContext_src.h | 2 ++ panda/src/gobj/savedContext.cxx | 10 ++++++++++ panda/src/gobj/savedContext.h | 4 +++- panda/src/gobj/textureContext.cxx | 10 ---------- panda/src/gobj/textureContext.h | 3 ++- 12 files changed, 63 insertions(+), 12 deletions(-) diff --git a/panda/src/glstuff/glBufferContext_src.cxx b/panda/src/glstuff/glBufferContext_src.cxx index f2e588f945..8fc4ae62a7 100644 --- a/panda/src/glstuff/glBufferContext_src.cxx +++ b/panda/src/glstuff/glBufferContext_src.cxx @@ -47,3 +47,13 @@ evict_lru() { update_data_size_bytes(0); set_resident(false); } + +/** + * Returns an implementation-defined handle or pointer that can be used + * to interface directly with the underlying API. + * Returns 0 if the underlying implementation does not support this. + */ +uint64_t CLP(BufferContext):: +get_native_id() const { + return _index; +} diff --git a/panda/src/glstuff/glBufferContext_src.h b/panda/src/glstuff/glBufferContext_src.h index dcc31c09ab..f51cd590f5 100644 --- a/panda/src/glstuff/glBufferContext_src.h +++ b/panda/src/glstuff/glBufferContext_src.h @@ -27,6 +27,8 @@ public: virtual void evict_lru(); + virtual uint64_t get_native_id() const; + CLP(GraphicsStateGuardian) *_glgsg; // This is the GL "name" of the data object. diff --git a/panda/src/glstuff/glIndexBufferContext_src.cxx b/panda/src/glstuff/glIndexBufferContext_src.cxx index 8b3e81b7ed..6971c1a4be 100644 --- a/panda/src/glstuff/glIndexBufferContext_src.cxx +++ b/panda/src/glstuff/glIndexBufferContext_src.cxx @@ -47,3 +47,13 @@ evict_lru() { update_data_size_bytes(0); mark_unloaded(); } + +/** + * Returns an implementation-defined handle or pointer that can be used + * to interface directly with the underlying API. + * Returns 0 if the underlying implementation does not support this. + */ +uint64_t CLP(IndexBufferContext):: +get_native_id() const { + return _index; +} diff --git a/panda/src/glstuff/glIndexBufferContext_src.h b/panda/src/glstuff/glIndexBufferContext_src.h index dfe011c4d0..5c1053c954 100644 --- a/panda/src/glstuff/glIndexBufferContext_src.h +++ b/panda/src/glstuff/glIndexBufferContext_src.h @@ -27,6 +27,8 @@ public: virtual void evict_lru(); + virtual uint64_t get_native_id() const; + CLP(GraphicsStateGuardian) *_glgsg; // This is the GL "name" of the data object. diff --git a/panda/src/glstuff/glSamplerContext_src.cxx b/panda/src/glstuff/glSamplerContext_src.cxx index 5f53cf10ce..84c50fb94a 100644 --- a/panda/src/glstuff/glSamplerContext_src.cxx +++ b/panda/src/glstuff/glSamplerContext_src.cxx @@ -68,4 +68,14 @@ reset_data() { // the sampler later. glGenSamplers(1, &_index); } +/** + * Returns an implementation-defined handle or pointer that can be used + * to interface directly with the underlying API. + * Returns 0 if the underlying implementation does not support this. + */ +uint64_t CLP(SamplerContext):: +get_native_id() const { + return _index; +} + #endif // OPENGLES_1 diff --git a/panda/src/glstuff/glSamplerContext_src.h b/panda/src/glstuff/glSamplerContext_src.h index 14637a4b7d..9085cc3d1e 100644 --- a/panda/src/glstuff/glSamplerContext_src.h +++ b/panda/src/glstuff/glSamplerContext_src.h @@ -33,6 +33,8 @@ public: virtual void evict_lru(); void reset_data(); + virtual uint64_t get_native_id() const; + // This is the GL "name" of the sampler object. GLuint _index; diff --git a/panda/src/glstuff/glVertexBufferContext_src.cxx b/panda/src/glstuff/glVertexBufferContext_src.cxx index 13889e111c..178d0c2b85 100644 --- a/panda/src/glstuff/glVertexBufferContext_src.cxx +++ b/panda/src/glstuff/glVertexBufferContext_src.cxx @@ -47,3 +47,13 @@ evict_lru() { update_data_size_bytes(0); mark_unloaded(); } + +/** + * Returns an implementation-defined handle or pointer that can be used + * to interface directly with the underlying API. + * Returns 0 if the underlying implementation does not support this. + */ +uint64_t CLP(VertexBufferContext):: +get_native_id() const { + return _index; +} diff --git a/panda/src/glstuff/glVertexBufferContext_src.h b/panda/src/glstuff/glVertexBufferContext_src.h index 6833ce4eec..5d5a917c48 100644 --- a/panda/src/glstuff/glVertexBufferContext_src.h +++ b/panda/src/glstuff/glVertexBufferContext_src.h @@ -29,6 +29,8 @@ public: virtual void evict_lru(); + virtual uint64_t get_native_id() const; + CLP(GraphicsStateGuardian) *_glgsg; // This is the GL "name" of the data object. diff --git a/panda/src/gobj/savedContext.cxx b/panda/src/gobj/savedContext.cxx index 92a1af46ca..41224846bb 100644 --- a/panda/src/gobj/savedContext.cxx +++ b/panda/src/gobj/savedContext.cxx @@ -31,3 +31,13 @@ void SavedContext:: write(std::ostream &out, int indent_level) const { indent(out, indent_level) << *this << "\n"; } + +/** + * Returns an implementation-defined handle or pointer that can be used + * to interface directly with the underlying API. + * Returns 0 if the underlying implementation does not support this. + */ +uint64_t SavedContext:: +get_native_id() const { + return 0; +} diff --git a/panda/src/gobj/savedContext.h b/panda/src/gobj/savedContext.h index 6c2db6aec8..ee4cc9f170 100644 --- a/panda/src/gobj/savedContext.h +++ b/panda/src/gobj/savedContext.h @@ -31,10 +31,12 @@ public: virtual void write(std::ostream &out, int indent_level) const; PUBLISHED: + virtual uint64_t get_native_id() const; + +public: static TypeHandle get_class_type() { return _type_handle; } -public: static void init_type() { TypedObject::init_type(); register_type(_type_handle, "SavedContext", diff --git a/panda/src/gobj/textureContext.cxx b/panda/src/gobj/textureContext.cxx index 7a83a17a01..767dbbe294 100644 --- a/panda/src/gobj/textureContext.cxx +++ b/panda/src/gobj/textureContext.cxx @@ -15,16 +15,6 @@ TypeHandle TextureContext::_type_handle; -/** - * Returns an implementation-defined handle or pointer that can be used - * to interface directly with the underlying API. - * Returns 0 if the underlying implementation does not support this. - */ -uint64_t TextureContext:: -get_native_id() const { - return 0; -} - /** * Similar to get_native_id, but some implementations use a separate * identifier for the buffer object associated with buffer textures. diff --git a/panda/src/gobj/textureContext.h b/panda/src/gobj/textureContext.h index 765509ec65..006f0a607c 100644 --- a/panda/src/gobj/textureContext.h +++ b/panda/src/gobj/textureContext.h @@ -37,7 +37,8 @@ public: PUBLISHED: INLINE Texture *get_texture() const; INLINE int get_view() const; - virtual uint64_t get_native_id() const; + + //virtual uint64_t get_native_id() const; virtual uint64_t get_native_buffer_id() const; INLINE bool was_modified() const;