2 Copyright (C) 2011 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
22 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
23 #if USE(ACCELERATED_COMPOSITING)
25 #include "LayerShader.h"
27 #include "GraphicsContext3D.h"
28 #include "LayerManager.h"
31 #include <wtf/text/CString.h>
34 LayerShader::LayerShader(GraphicsContext3D* context, unsigned program)
40 LayerShader::~LayerShader()
42 m_context->deleteProgram(m_program);
45 void LayerShader::use()
47 m_context->useProgram(m_program);
50 unsigned LayerShader::loadShader(GraphicsContext3D* context, unsigned type, const char* shaderSource)
52 unsigned shader = context->createShader(type);
56 String sourceString(shaderSource);
57 context->shaderSource(shader, sourceString);
59 context->compileShader(shader);
62 context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled);
64 String infoLog = context->getShaderInfoLog(shader);
65 LOG_ERROR("%s", infoLog.utf8().data());
67 context->deleteShader(shader);
73 unsigned LayerShader::loadProgram(GraphicsContext3D* context, const char* vertexShaderSource, const char* fragmentShaderSource)
75 unsigned vertexShader = loadShader(context, GraphicsContext3D::VERTEX_SHADER, vertexShaderSource);
77 LOG_ERROR("LayerShader::%s() - Failed to create vertex shader\n", __func__);
81 unsigned fragmentShader = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER, fragmentShaderSource);
82 if (!fragmentShader) {
83 context->deleteShader(vertexShader);
84 LOG_ERROR("LayerShader::%s() - Failed to create fragment shader\n", __func__);
88 unsigned programObject = context->createProgram();
90 LOG_ERROR("LayerShader::%s() - Failed to create shader program\n", __func__);
94 context->attachShader(programObject, vertexShader);
95 context->attachShader(programObject, fragmentShader);
97 context->bindAttribLocation(programObject, LayerManager::s_positionAttribLocation, "attr_pos");
98 context->bindAttribLocation(programObject, LayerManager::s_texCoordAttribLocation, "attr_tex");
100 context->linkProgram(programObject);
102 context->getProgramiv(programObject, GraphicsContext3D::LINK_STATUS, &linked);
104 LOG_ERROR("LayerShader::%s() - Failed to link shader program\n", __func__);
105 context->deleteProgram(programObject);
109 context->deleteShader(vertexShader);
110 context->deleteShader(fragmentShader);
111 return programObject;