refactoring of texture code into a 2D version first
This commit is contained in:
parent
2c4cc29f97
commit
753f51453f
6 changed files with 63 additions and 49 deletions
|
@ -32,6 +32,7 @@ void register_system_function(sol::state&, sol::table &ns)
|
||||||
"mouse_position",sol::readonly_property(&input::mouse_position),
|
"mouse_position",sol::readonly_property(&input::mouse_position),
|
||||||
"mouse_button",sol::readonly_property(&input::mouse_button),
|
"mouse_button",sol::readonly_property(&input::mouse_button),
|
||||||
"mouse_pressed",sol::readonly_property(&input::mouse_pressed),
|
"mouse_pressed",sol::readonly_property(&input::mouse_pressed),
|
||||||
|
"has_input",sol::readonly_property(&input::has_input),
|
||||||
"input_string",sol::readonly_property(&input::input_string)
|
"input_string",sol::readonly_property(&input::input_string)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--
|
--
|
||||||
-- demonstrator for Lua binding on pixwerx
|
-- pixwerx - bare rendering engine binding usage
|
||||||
--
|
--
|
||||||
|
|
||||||
pw.script:load_all()
|
pw.script:load_all()
|
||||||
|
@ -8,7 +8,7 @@ local w = pw.window.new()
|
||||||
w.visible = false
|
w.visible = false
|
||||||
|
|
||||||
-- set title
|
-- set title
|
||||||
w.title = "My Cool 3D Content"
|
w.title = "pixwerx - bare rendering"
|
||||||
|
|
||||||
-- set size
|
-- set size
|
||||||
w.size = pw.size.new(640,480)
|
w.size = pw.size.new(640,480)
|
||||||
|
@ -132,30 +132,33 @@ w.visible = true
|
||||||
-- main update loop
|
-- main update loop
|
||||||
while w:update() do
|
while w:update() do
|
||||||
|
|
||||||
-- somehow works
|
-- only check if get a new input
|
||||||
if pw.input.get().input_string == 'f' then
|
if pw.input.get().has_input then
|
||||||
w.fullscreen = not w.fullscreen
|
|
||||||
end
|
|
||||||
|
|
||||||
-- keycode for quit
|
-- somehow works
|
||||||
if pw.input.get().input_string == 'q' then
|
if pw.input.get().input_string == 'f' then
|
||||||
break;
|
w.fullscreen = not w.fullscreen
|
||||||
end
|
end
|
||||||
|
|
||||||
-- just to quickly modify speed
|
-- keycode for quit
|
||||||
local move_step = 0.05
|
if pw.input.get().input_string == 'q' then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
-- camera
|
-- just to quickly modify speed
|
||||||
if pw.input.get().input_string == 'w' then
|
local move_step = 0.05
|
||||||
cam_z = cam_z - move_step
|
|
||||||
elseif pw.input.get().input_string == 's' then
|
-- camera
|
||||||
cam_z = cam_z + move_step
|
if pw.input.get().input_string == 'w' then
|
||||||
print(cam_z)
|
cam_z = cam_z - move_step
|
||||||
elseif pw.input.get().input_string == 'a' then
|
elseif pw.input.get().input_string == 's' then
|
||||||
cam_x = cam_x - move_step
|
cam_z = cam_z + move_step
|
||||||
elseif pw.input.get().input_string == 'd' then
|
print(cam_z)
|
||||||
cam_x = cam_x + move_step
|
elseif pw.input.get().input_string == 'a' then
|
||||||
print(cam_x)
|
cam_x = cam_x - move_step
|
||||||
|
elseif pw.input.get().input_string == 'd' then
|
||||||
|
cam_x = cam_x + move_step
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- just to check
|
-- just to check
|
||||||
|
|
|
@ -17,6 +17,7 @@ public:
|
||||||
int mouse_button() const { return _mouse_button; }
|
int mouse_button() const { return _mouse_button; }
|
||||||
|
|
||||||
|
|
||||||
|
bool has_input() const { return !_input_string.empty();}
|
||||||
std::string input_string() const { return _input_string; }
|
std::string input_string() const { return _input_string; }
|
||||||
|
|
||||||
~input() = default;
|
~input() = default;
|
||||||
|
|
|
@ -49,9 +49,6 @@ public:
|
||||||
void set_wrap(wrap_mode w);
|
void set_wrap(wrap_mode w);
|
||||||
wrap_mode wrap() const { return _wrap; }
|
wrap_mode wrap() const { return _wrap; }
|
||||||
|
|
||||||
void generate_mipmaps();
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t native_handle() const;
|
uint32_t native_handle() const;
|
||||||
uint32_t native_sampler_handle() const;
|
uint32_t native_sampler_handle() const;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct shader::impl
|
||||||
|
|
||||||
~impl()
|
~impl()
|
||||||
{
|
{
|
||||||
clear();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_valid()
|
bool is_valid()
|
||||||
|
@ -132,16 +132,21 @@ struct shader::impl
|
||||||
glUseProgram(_shader_program);
|
glUseProgram(_shader_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void destroy()
|
||||||
{
|
{
|
||||||
// potentially the GL driver hasn't been loaded
|
// potentially the GL driver hasn't been loaded
|
||||||
if (is_valid()) {
|
if (is_valid()) {
|
||||||
glDeleteProgram(_shader_program);
|
|
||||||
|
// deleting and detaching should happen much earlier
|
||||||
|
|
||||||
for (auto s : _shader_stages)
|
for (auto s : _shader_stages)
|
||||||
{
|
{
|
||||||
glDeleteShader(s);
|
glDeleteShader(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only program needs to be deleted
|
||||||
|
|
||||||
|
glDeleteProgram(_shader_program);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,8 +174,12 @@ struct shader::impl
|
||||||
{
|
{
|
||||||
glUniform1f(location,v);
|
glUniform1f(location,v);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
void bind(int location,const texture& v)
|
||||||
|
{
|
||||||
|
glUniform1d(location,v.native_sampler_handle());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
shader::shader()
|
shader::shader()
|
||||||
|
|
|
@ -64,32 +64,35 @@ struct texture::impl {
|
||||||
unbind();
|
unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void create(const class image& i)
|
void create()
|
||||||
{
|
{
|
||||||
glGenTextures(1, &_texture_id);
|
|
||||||
|
auto i = _host._image;
|
||||||
|
|
||||||
|
glGenTextures(1, &_texture_id);
|
||||||
|
glBindTexture(gl_shape(),_texture_id);
|
||||||
|
|
||||||
|
GLuint format = GL_RGBA;
|
||||||
|
|
||||||
|
glTexImage2D(gl_shape(),0,format,i->size().width,i->size().height,0,format,GL_UNSIGNED_BYTE,i->data());
|
||||||
|
|
||||||
|
glGenerateMipmap(gl_shape());
|
||||||
|
|
||||||
|
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
// glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
|
||||||
// glTexImage1D(gl_shape(), 0, GL_R8, cosAngleResolution, 0,
|
|
||||||
// GL_RED, GL_UNSIGNED_BYTE, &textureData[0]);
|
|
||||||
// glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_BASE_LEVEL, 0);
|
|
||||||
// glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 0);
|
|
||||||
// glBindTexture(GL_TEXTURE_1D, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void destroy()
|
void destroy()
|
||||||
{
|
{
|
||||||
|
glDeleteTextures(1,&_texture_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_mipmaps()
|
|
||||||
{
|
|
||||||
glGenerateMipmap(gl_shape());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,6 +111,8 @@ texture::texture(image_ref i, texture::data_layout s)
|
||||||
texture();
|
texture();
|
||||||
set_image(i);
|
set_image(i);
|
||||||
set_shape(s);
|
set_shape(s);
|
||||||
|
|
||||||
|
_impl->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
texture::~texture()
|
texture::~texture()
|
||||||
|
@ -117,6 +122,8 @@ texture::~texture()
|
||||||
void texture::set_image(image_ref i)
|
void texture::set_image(image_ref i)
|
||||||
{
|
{
|
||||||
_image = i;
|
_image = i;
|
||||||
|
|
||||||
|
_impl->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture::set_shape(data_layout s)
|
void texture::set_shape(data_layout s)
|
||||||
|
@ -129,10 +136,6 @@ void texture::set_wrap(wrap_mode w)
|
||||||
_wrap = w;
|
_wrap = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture::generate_mipmaps()
|
|
||||||
{
|
|
||||||
_impl->generate_mipmaps();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t texture::native_handle() const
|
uint32_t texture::native_handle() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue