0 votes

I have created a custom texture, in C++ [inheriting Texture] that I would like to appear in the dropdown on a shader param [say, "uniform sampler2D chickens"; where currently the dropdown lets me choose "new AnimatedTexture", "new ImageTexture", etc, I wish to see my custom class]. Unfortunately, no matter what I do, I can't figure out how to make it appear.

[Eventually, I also will need to be able to add properties to the texture itself, so I may be on completely the wrong path - I'd love to hear if I need a major shift in direction, too]

I worked through this example: https://docs.godotengine.org/en/stable/tutorials/plugins/gdnative/gdnative-cpp-example.html , and it's working for another script in my project [ https://github.com/chunky/jsbgodot/ ].

The code [below] is so far extremely trivial - as soon as it gets over the initial bump, I'll flesh it out to actually create my texture. Of note, you can see the debug spam; it is outputting that GDALTexture::register gets entered, but nothing else.

Any thoughts and guidance would be greatly appreciated

Gary

Header:

namespace godot {

class GDALTexture : public Texture {
    GODOT_CLASS(GDALTexture, Texture)

private:
    int width, height;

public:
    static void _register_methods();

    GDALTexture();
    ~GDALTexture();

    void _init();

    Ref<Image> get_data() const;
};
}

Implementation:

using namespace godot;

void GDALTexture::_register_methods() {
    register_method("get_data", &GDALTexture::get_data);
printf("in gdaltexture::register\n");
}

GDALTexture::GDALTexture() {
   width = 10;
   height = 10;
printf("in gdaltexture ctor\n");
}

GDALTexture::~GDALTexture() {
}

void GDALTexture::_init() {
printf("in gdaltexture::_init\n");
}

Ref<Image> GDALTexture::get_data() const {
printf("in gdaltexture::get_data\n");
        Image * im = Image::_new();
        ImageTexture * imTex = ImageTexture::_new();
        im->create(width, height, false, Image::FORMAT_RGBA8);
        im->lock();
        Color c;
        for(int x=0; x<width; x++){
                for(int y=0; y < height; y++){
                        im->set_pixel(x, y, c);
                }
        }
        im->unlock();
        return Ref(im);
}
Godot version 3.2.3-stable_x11.64
in Engine by (12 points)

I'm pretty sure that I need to be inheriting Image, not Texture, then using ImageTexture to do the non-image-specifc legwork.

Being said, I'm having precisely the same experience with Image as I was with TExture; in a dropdown where I'd expect to find an "Image"derived GDNative class, I don't see it. In this case, I'm creating a TextureRec, setting its texture to be an ImageTexture, then clicking on the "Image" dropdown.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.