summaryrefslogtreecommitdiffstats
path: root/video.cpp
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-25 15:53:39 +0100
committerNao Pross <naopross@thearcway.org>2019-01-25 15:53:39 +0100
commit71b593ebd1a015a4cb9bfe0eebafc78d897ff284 (patch)
tree6a1f1b95caa2e6745f85f134dc5e8d50ba64a519 /video.cpp
parentMove renderer code in video.cpp to reflect header decl order (diff)
downloadlibwsdl2-71b593ebd1a015a4cb9bfe0eebafc78d897ff284.tar.gz
libwsdl2-71b593ebd1a015a4cb9bfe0eebafc78d897ff284.zip
Add basic texture wrapperready
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/video.cpp b/video.cpp
index 47d5756..5a5e933 100644
--- a/video.cpp
+++ b/video.cpp
@@ -12,6 +12,39 @@ extern "C" {
using namespace wsdl2;
+
+/* class texture */
+
+texture::texture(renderer& r, texture::pixformat p, texture::access a,
+ std::size_t width, std::size_t height)
+
+ : _format(p), _access(a), m_renderer(r)
+{
+ m_texture = SDL_CreateTexture(r.m_renderer,
+ static_cast<Uint32>(p), static_cast<int>(a),
+ static_cast<int>(width), static_cast<int>(height)
+ );
+}
+
+texture::~texture() {
+ if (m_texture != NULL)
+ SDL_DestroyTexture(m_texture);
+ else
+ npdebug("warning: m_texture is NULL");
+}
+
+SDL_Texture* texture::sdl() {
+#ifdef DEBUG
+ if (m_texture == NULL) {
+ throw std::runtime_error(
+ "attempted to call texture::sdl() when m_texture is NULL"
+ );
+ }
+#endif
+
+ return m_texture;
+}
+
/* class renderer */
renderer::renderer() {
@@ -19,7 +52,7 @@ renderer::renderer() {
}
SDL_Renderer * renderer::sdl() {
-#ifndef DEBUG
+#ifdef DEBUG
if (m_renderer == NULL) {
throw std::runtime_error(
"attempted to call renderer::sdl() when m_renderer is NULL"
@@ -107,7 +140,7 @@ void window::update() {
}
SDL_Window * window::sdl() {
-#ifndef DEBUG
+#ifdef DEBUG
if (m_window == NULL) {
throw std::runtime_error(
"attempted to call window::sdl() when m_window is NULL"